htmx icon indicating copy to clipboard operation
htmx copied to clipboard

`htmx.process` queries the whole document, not only the supplied element, causing slowdowns

Open jy14898 opened this issue 1 year ago • 4 comments

When supplying HTML from external sources, we call htmx.process on them to let htmx initialise any handlers/do necessary work. However, since support for hx-on, it queries over the whole document (not the supplied element) to find these attributes. This can be very slow in situations where many nodes are to be processed in a short period of time, in a page with many elements.

https://github.com/bigskysoftware/htmx/blob/2fe2f67555c9d3941c5041e1b3846f69996eb4a4/src/htmx.js#L1901-L1922

jy14898 avatar Nov 28 '23 13:11 jy14898

Ah, I see elt is supplied as a parameter to document.evaluate. Regardless, it still does not perform well enough

jy14898 avatar Nov 28 '23 13:11 jy14898

There does seem to be a discrepancy between the situation where you have document.evaluate available and where you don't. The fallback code above does not only look at elt and its children, but the entire document. That doesn't seem to be correct...

svenberkvens avatar Nov 28 '23 19:11 svenberkvens

Related to #2019

Telroshan avatar Nov 29 '23 08:11 Telroshan

Ah, I see elt is supplied as a parameter to document.evaluate. Regardless, it still does not perform well enough

There does seem to be a discrepancy between the situation where you have document.evaluate available and where you don't. The fallback code above does not only look at elt and its children, but the entire document. That doesn't seem to be correct...

Due to the way document.evaluate is called, the entire document is scanned, not only elt and its children, even though elt is supplied as a parameter. I think there should have been a . before the //*. See #2019 for more information.

svenberkvens avatar Nov 29 '23 08:11 svenberkvens

I think this is a duplicate of #2019, which is now closed, so I'm closing this as fixed

jy14898 avatar Jan 18 '24 13:01 jy14898