-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Checking readyState is interactive before listening for DOMContentLoaded #2808
Open
andrew-ebsco
wants to merge
1
commit into
bigskysoftware:dev
Choose a base branch
from
andrew-ebsco:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
ready
variable in #1688, it was precisely because we were only checking=== 'complete'
, thus we could miss the timeframe betweeninteractive
andcomplete
state, where we would bind toDOMContentLoaded
while 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 firstready
call 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
DOMContentLoaded
listeners would be bound one after the other, in the same frame.So either the
DOMContentLoaded
event hasn't been fired yet, and both the capture andready
will 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
interactive
and 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