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

Behaviour when disconnected/unmounted from body #2526

Open
jy14898 opened this issue May 3, 2024 · 0 comments
Open

Behaviour when disconnected/unmounted from body #2526

jy14898 opened this issue May 3, 2024 · 0 comments

Comments

@jy14898
Copy link

jy14898 commented May 3, 2024

htmx seems to cancel a some of its behaviours if events fire while nodes are not a part of the body:

htmx/src/htmx.js

Lines 1514 to 1517 in 57595bc

if (!bodyContains(elt)) {
eltToListenOn.removeEventListener(triggerSpec.trigger, eventListener);
return;
}

htmx/src/htmx.js

Lines 1778 to 1781 in 57595bc

if (!bodyContains(elt)) {
sseEventSource.removeEventListener(sseEventName, sseListener);
return;
}

htmx/src/htmx.js

Lines 1812 to 1817 in 57595bc

if (!maybeCloseSSESource(sseSourceElt)) {
if (bodyContains(elt)) {
handler(elt);
} else {
sseEventSource.removeEventListener(sseEventName, sseListener);
}

This makes it difficult to integrate with other frameworks (eg React), where the DOM node may be unmounted and then later remounted. Users have to ensure that unmounting and remounting occurs synchronously, which can be difficult.

Calling htmx.process might not re-init if attributes are unchanged, and deInitNode is not exported by htmx. However, ideally we'd not re-process at all.

Ideally when these events trigger on unmounted nodes, the listeners don't get removed, and instead the effect not performed. This seems to be a pattern used elsewhere in htmx. Explicit deInits could be invoked if the users want to ensure the effects of htmx-powered DOM are disabled

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

1 participant