Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior with htmx response #564

Closed
SennaSanzo opened this issue Aug 27, 2024 · 3 comments
Closed

Behavior with htmx response #564

SennaSanzo opened this issue Aug 27, 2024 · 3 comments

Comments

@SennaSanzo
Copy link

SennaSanzo commented Aug 27, 2024

Hello everyone,

For those who use behaviors, how do you handle a situation where you have a page loaded with Hyperscript, and a part of the page is refreshed using HTMX? What I mean is that the content returned via AJAX includes a behavior script tag referencing an external "._hs" file that needs to be installed on an element also returned in the response. In my case, I’m obviously getting an error like "No such behavior defined as xxx" because Hyperscript wasn’t aware of it when the page initially loaded. Is there a function I could call on the Hyperscript object to load these new behaviors? I was thinking of processNode ?

Edit: As I cannot succeed to dynamically load behaviors as they arrive in responses, I resigned myself to load all the behaviors in the head of the page. I hope someone will bring me light soon :)

Thank you in advance.

@SennaSanzo
Copy link
Author

May I ask if this project is still being actively maintained? I really appreciate the work that's gone into it and hope the community is still involved.

@1cg
Copy link
Contributor

1cg commented Oct 4, 2024

Hi Senna, yes, I have been focused mainly on htmx, but I am going to try to get this project to 1.0 by early next year.

@1cg
Copy link
Contributor

1cg commented Dec 17, 2024

Hi Senna, I think the best solution is the one you came up with: to load all the hyperscript behaviors early. That avoids any ordering issues. content that is handled by htmx and that contains hyperscript should be automatically processed because hyperscript listens for new content from htmx here:

globalScope.document.addEventListener("htmx:load", function (/** @type {CustomEvent} */ evt) {

@1cg 1cg closed this as completed Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants