Skip to content
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

Fix hydration on slow connection #8680

Merged
merged 5 commits into from
Sep 29, 2023
Merged

Fix hydration on slow connection #8680

merged 5 commits into from
Sep 29, 2023

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Sep 27, 2023

Changes

Fix #8178

This implements a <!--astro:end--> comment marker added as the last child of the astro-island tag, used to detect if the children is ready for hydration.

As the comment marker could risk being stripped by HTML minifiers, I also added a fallback DOMContentLoaded listener to hydrate if it's triggered.

The downside with this approach is the increased code size for the astro-island component: 3053 chars -> 3362 chars.

Testing

Tested manually with the repro in #8178. It's a bit hard to create a test for this without making it flaky.

Docs

n/a. We currently don't document at the very specific time when we start hydrating.

@changeset-bot
Copy link

changeset-bot bot commented Sep 27, 2023

🦋 Changeset detected

Latest commit: 33a019c

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Sep 27, 2023
@bluwy bluwy marked this pull request as draft September 27, 2023 14:47
@bluwy
Copy link
Member Author

bluwy commented Sep 27, 2023

Actually I need to benchmark multiple islands too to confirm it doesn’t stall them altogether. Marking as draft.

@bluwy
Copy link
Member Author

bluwy commented Sep 28, 2023

I did some tests, it actually stalled all islands before rendering, which isn't a great experience for those on poor connections who have to wait for the entire page to load before they can interact with it. I switched to something similar to Nate's idea instead, adding a trailing child script to emit an event to signal the parent island that it's loaded. Wish there's something like DOMContentLoaded but for partial dom nodes instead.

Update: Uses Nate's idea of a comment marker completely, and a fallback DOMContentLoaded listener.

@bluwy bluwy marked this pull request as ready for review September 29, 2023 08:29
@bluwy bluwy requested a review from matthewp September 29, 2023 08:34
@bluwy
Copy link
Member Author

bluwy commented Sep 29, 2023

This is ready for review. I updated the PR description of what this PR does now.

Copy link
Contributor

@matthewp matthewp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty clever solution!

@bluwy bluwy merged commit 31c59ad into main Sep 29, 2023
4 checks passed
@bluwy bluwy deleted the slow-hydrate branch September 29, 2023 13:54
@astrobot-houston astrobot-houston mentioned this pull request Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hydration Mismatch Due to Incomplete Content Download in Slow Connection
2 participants