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

Support view transitions for client:only components #8745

Closed
wants to merge 1 commit into from

Conversation

martrapp
Copy link
Member

@martrapp martrapp commented Oct 4, 2023

Changes

The original issue is #8114. Persistent client:only components lose their styling on transition.
This only happens with astro dev, not with astro build.
The reason was that the HTML files contained only statically generated styles, and the comparison between the old DOM and the new file removed the client-side generated styles.
Fix #8472 fixed this by attempting to identify these client-generated styles and retain them.
This caused several issues where old styles were not deleted during the transition, even though they should have been. (#8604, #8674)

My preferred solution would be to be able to read from each client:only astro-island (or each page) which head elements it dynamically creates. But unfortunately I have not been able to do that for dev mode. Any ideas how to achieve this?

This fix identifies head elements that are dynamically inserted by persisted client:only components.
This is done by diffing the head elements that are parsed from file with those found in the DOM right before transitioning away from the document. Of course this only helps for the next transition to this page. Therefore the page is full reloaded if the information about dynamic head elements is not available yet.

Usage: visit all pages once by navigating to them using view transitions.
After that pre-loading, few transitions work as expected on following page visits.

Testing

Manually tested with code from #8604.
Manually tested with code from #8114

Docs

n/a, bug fix

@changeset-bot
Copy link

changeset-bot bot commented Oct 4, 2023

🦋 Changeset detected

Latest commit: daad1de

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 4, 2023
@matthewp
Copy link
Contributor

matthewp commented Oct 4, 2023

I don't love the amount of code needed to fix this and the fact that we need to reload some times. Would love to find another solution. Let me think on this one for a little bit...

@martrapp
Copy link
Member Author

martrapp commented Oct 4, 2023

I share your assessment regarding the code. It would be great if we could find a simpler solution!

@martrapp martrapp mentioned this pull request Oct 6, 2023
@martrapp
Copy link
Member Author

martrapp commented Oct 6, 2023

Workaround while we strive to find a good solution:

  • Note that the problem only occurs in DEV mode, not when build/preview for production.
  • In DEV mode, you can import the missing CSS files explicitly on the page that uses the client:only component.

@martrapp
Copy link
Member Author

A long journey has come to an end: client:only components should now keep their styling when used with view transitions, see #8840

@martrapp martrapp closed this Oct 20, 2023
@martrapp martrapp deleted the mt/persisted-client-only branch October 20, 2023 09:51
@martrapp martrapp restored the mt/persisted-client-only branch October 20, 2023 09:51
@martrapp martrapp deleted the mt/persisted-client-only branch October 20, 2023 09:51
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.

2 participants