-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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: Persist styles of persistent client:only components during view transitions in DEV mode #8840
Conversation
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
🦋 Changeset detectedLatest commit: 671b5ad 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 |
sarah11918
reviewed
Oct 19, 2023
matthewp
reviewed
Oct 19, 2023
sarah11918
reviewed
Oct 19, 2023
Co-authored-by: Sarah Rainsberger <[email protected]>
matthewp
approved these changes
Oct 19, 2023
1 task
Merged
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)
pr: docs
A PR that includes documentation for review
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.
Changes
Yet another attempt ;-) to preserve the stylesheets of
client:only
components during view transitions in DEV mode.Production is not an issue as Vite statically bundles the style files when building for production.
Situation
Stylesheets for client:only components are generated during hydration. They are not part of the static HTML files.
Therefore the comparison of header elements during
swap()
deletes them from the header.client:only
components can not simply be re-initialized in the new DOM because the browser won't re-import modules that are already loaded. In a former approach I used random query strings in the URLs of style elements. While this worked for React-style imported CSS files, it failed for Vue's and Svelte's embedded styles.How the fix works:
Only in DEV (treeshaken in PROD) and only if there are
client:only
components in the new DOM:Hydrate the components in an environment where the module handler cache is cleared. This way, all style elements are generated. We can now identify style elements that come from hydration and not from the static HTML file. Theses are kept in the head during the transition.
Testing
Reactivated and extended the existing e2e test case.
New test for Vue and Svelte components
Documents
N/A, bug fixing.