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: Persist styles of persistent client:only components during view transitions in DEV mode #8840

Merged
merged 15 commits into from
Oct 19, 2023

Conversation

martrapp
Copy link
Member

@martrapp martrapp commented Oct 15, 2023

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.

@changeset-bot
Copy link

changeset-bot bot commented Oct 15, 2023

🦋 Changeset detected

Latest 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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Oct 15, 2023
@martrapp martrapp marked this pull request as draft October 15, 2023 13:50
@martrapp martrapp marked this pull request as ready for review October 16, 2023 17:21
@martrapp martrapp marked this pull request as draft October 16, 2023 18:34
@martrapp martrapp removed the request for review from matthewp October 16, 2023 18:54
@github-actions github-actions bot added the docs pr A PR that includes documentation for review label Oct 18, 2023
@sarah11918 sarah11918 removed the docs pr A PR that includes documentation for review label Oct 19, 2023
@github-actions github-actions bot added the docs pr A PR that includes documentation for review label Oct 19, 2023
@martrapp martrapp removed the docs pr A PR that includes documentation for review label Oct 19, 2023
@github-actions github-actions bot added the docs pr A PR that includes documentation for review label Oct 19, 2023
@martrapp martrapp removed the docs pr A PR that includes documentation for review label Oct 19, 2023
@martrapp martrapp marked this pull request as ready for review October 19, 2023 15:40
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
@github-actions github-actions bot added the docs pr A PR that includes documentation for review label Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs pr A PR that includes documentation for review pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants