Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we simply check
readyState !== 'loading'in this case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've tried that—I know this looks a little clunky but I'd rather both checks be included.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry but this confuses me @alexpetros , are you suggesting this might result in a different behavior than
!== 'loading'?As it's a 3 values property, this should be the exact same behavior, except that this adds more hardcoded strings not to be minified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I didn't read your suggestion closely enough (I missed the
!==, that's my bad). Yes @andrew-ebsco can you make that change?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexpetros just to emphasize on this, this would take us back to august 2023, aka the first time we started dealing with these ready state / load event issues.
See #1672 which was the first one about this matter ; we precisely had a
!== 'loading'check, exactly what we would go back to with this PR.See my comment in #2264 with the history of PRs and issues related to this topic.
I'm not sure that's really what we should go for here, as we're getting back to a previous state that we already know is going to cause issues, as those very issues have been reported in the past (again, cf the issues and PRs listed in my comment, linked above)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think is true, because what we have now that we didn't august 2023 is a variable that captures whether DOMContentLoaded fired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I'm not sure this variable is useful anymore if we roll back to a
!== 'loading'check @alexpetrosWhen you added that
readyvariable in #1688, it was precisely because we were only checking=== 'complete', thus we could miss the timeframe betweeninteractiveandcompletestate, where we would bind toDOMContentLoadedwhile the document was alreadyinteractive, thus the listener would never be called.If we roll back to a
!== 'loading'check, I don't think there's any gap between the capture you linked above, and the firstreadycall of the lib.Between this
htmx/src/htmx.js
Lines 4887 to 4890 in 51807d0
And this
htmx/src/htmx.js
Lines 4938 to 4939 in 51807d0
No async work is performed, so the
DOMContentLoadedlisteners would be bound one after the other, in the same frame.So either the
DOMContentLoadedevent hasn't been fired yet, and both the capture andreadywill bind a listener to it, making the capture useless hereOr, the event has already fired when htmx loads, so ready executes right away (as the state is
interactiveand no moreloading), making the capture also useless here.As per my comment in #2264 I really think we should take some time to dive in this topic again @alexpetros with @1cg as well, to see if A) we still agree with our past selves about the init function, and B) try to setup reproducible cases to test the different loading scenarios
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Telroshan I'm documenting this as a known quirk, but if you would like to dive into this topic again I am happy to help on it.