-
-
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
[astrojs/lit] web components don't adopt SSR'd DSD from view-transitions #9953
Comments
Hi @hrmcdonald, thank you for opening this issue! It looks like we are not putting the template in the shadowRoot when we parse the new DOM from the file. |
The problem only seems to occur in development mode. |
It does appear that things are working properly in a production build. |
Still a bug so. Have to dive deeper into hydration. Any suggestions welcome. Will ask on discord, too :) |
Preliminary analysis: For view transitions, we load the DOM with |
FYI declarative shadow DOM won't be parsed with If you don't need an entire document and would like something similar to setting Currently the unsafe HTML methods are available in the recently released Firefox 122, and soon to come Safari 17.4 (currently available in Safari Technology Preview). Chrome is in the process of implementing. |
Hey @augustjk! Thank you so much for your detailed explanation and advice! I really appreciate it! Some how, we get things right when building for production. Let me learn some more about Lit 😄 |
Actually, when inspecting the production build a bit closer, I don't think things are working as expected still. It seems that in a prod build for some reason the web components are just re-initializing themselves properly when loaded via view-transition where they don't in dev. However, they still don't seem to be properly adopting their DSD template. The stackblitz example is simple enough that it looks OK on the surface, but for anything more complex this still leads to a lot of issues. |
Took a while.
|
Hello @hrmcdonald. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
I updated the repro stackblitz to use |
Hello @hrmcdonald. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
Please note that the uncaught error also occurs independently of view transitions. |
@hrmcdonald here is the stackblitz for a minimal reproducible example that works for me. Does that work for you, too? |
@hrmcdonald I'm closing this issue now as there was no further response. Please feel free to reopen it at any time if you gain new insights. |
Sorry for the delayed response here @martrapp. I don't know why the error you called out is getting thrown with decorator properties in the example, but even in your example that fixes that issue, while it looks like things are working properly, the web component is not initializing properly. Its SSR'd template shadow root is not getting properly adopted: See how the SSR'd declarative shadow dom template is still orphaned here. It looks like the web component is just initializing from scratch instead of adopting the SSR'd shadow dom template like it should. |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Our design system is built with Lit web components. Our docs site is built with Astro. We use the
@astrojs/lit
plugin to SSR all our components on pages and it works great.However, recently we have been testing out Astro's newer view-transition functionality and we noticed a major issue going on here that is blocking us from adopting this functionality right now.
While the initial page load works as expected, any SSR'd web components loaded in a view-transition do not adopt their SSR'd shadow root. I was pointed to the fact that the browser's declarative shadow DOM parsing only runs during HTML parsing. I don't know enough about view-transitions or how Astro handles them to be able to know if this is why these DSD roots are not getting adopted properly. Is this a browser bug? Should or could it be handled by Astro?
What's the expected result?
In the example I have linked below, I have created a very simple Astro site with two pages, a web component on each, and view transitions enabled.
The first page you load (can be either one) everything parses and renders as expected. But once you click the link to transition in the other page, you will notice the second page's web component link does not render correctly. It is there, but it has not adopted its SSR'd shadow DOM and thus the link on the second page is not visible.
Initial load:
Page when loaded via view-transition:
Ideally, we want web components loaded during a view transition to get parsed like normal so they adopt their DSD. Otherwise we can't really utilize view transitions with SSR'd web components.
Link to Minimal Reproducible Example
https://stackblitz.com/~/edit/withastro-astro-ytwbdv?file=src%2Fpages%2Findex.astro&title=Astro%20Starter%20Kit:%20Blog
Participation
The text was updated successfully, but these errors were encountered: