[fix] events between DOMContentLoaded and readyState.complete might be lost#1681
[fix] events between DOMContentLoaded and readyState.complete might be lost#1681xhaggi wants to merge 2 commits intobigskysoftware:devfrom
Conversation
|
If you're going to do this, what's the point of the conditional at all? Why not just function ready(fn) {
getDocument().addEventListener('DOMContentLoaded', fn);
} |
|
The |
|
Tagging for visibility @1cg The way you've done it, if the |
|
You are right, but how can this happen at all? Ready is always called during htmx initialisation. |
a1325df to
a605e1b
Compare
|
@alexpetros I added a second commit to address the concerns. The determination if ready is now separate from the BTW let me know if we want to go this way and I'll squash everything together. |
a605e1b to
9b4b35c
Compare
|
To be honest, I think what you have here is too complex, and that we need to analyze the existing code a little better, not write more code around it. We just need to be more confident in our understanding of when the DOM event fires. |
|
What do you think I've been doing for the last few hours? So let me explain the relevant part for you.
And I decided to use the event-driven approach ( |
You're correct about this. From MDN:
Ready is always called synchronously when HTMX is loaded. So we're set there. My second conclusion is that this problem:
should be solved with a closure, similar to how you accomplished it originally. I'm going to close this PR and put up my version of this. The reason I'm not asking you to update this one is because I merged the original change and I'd rather be responsible for it if it doesn't work, but I know that you have a few enhancement PRs in the works and I promise we'll get to this in release after this upcoming one. |
Relying on readyState
completein thereadyfunction might cause some of the events registered viahtmx.on()to be lost betweenDOMContentLoadedandreadyState === complete.Here is an example that simulates such a situation.
https://jsfiddle.net/k6pxg5wf/