htmx icon indicating copy to clipboard operation
htmx copied to clipboard

Behaviour when disconnected/unmounted from body

Open jy14898 opened this issue 1 year ago • 0 comments

htmx seems to cancel a some of its behaviours if events fire while nodes are not a part of the body: https://github.com/bigskysoftware/htmx/blob/57595bc0390b6ed98ada45a5d27156322e308757/src/htmx.js#L1514-L1517 https://github.com/bigskysoftware/htmx/blob/57595bc0390b6ed98ada45a5d27156322e308757/src/htmx.js#L1778-L1781 https://github.com/bigskysoftware/htmx/blob/57595bc0390b6ed98ada45a5d27156322e308757/src/htmx.js#L1812-L1817

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

jy14898 avatar May 03 '24 12:05 jy14898