Skip to content

Lit integration hydration occurs in incorrect order for nested components #9017

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

Closed
1 task done
augustjk opened this issue Nov 7, 2023 · 0 comments · Fixed by #9018
Closed
1 task done

Lit integration hydration occurs in incorrect order for nested components #9017

augustjk opened this issue Nov 7, 2023 · 0 comments · Fixed by #9018
Labels
needs triage Issue needs to be triaged

Comments

@augustjk
Copy link
Contributor

augustjk commented Nov 7, 2023

Astro Info

Astro                    v3.4.3
Node                     v18.18.0
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/lit

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When using Lit integration and hydrating a Lit component that also renders a Lit component as part of it's template, hydration occurs in incorrect order where the child hydrates before the parent. This becomes problematic if the child component takes in properties from the parent that affect its initial render, causing mismatch between what's rendered on server and what client's first render/hydration looks like.

Lit SSR has a mechanism for ensuring proper hydration order using the defer-hydration attribute but it currently is not getting added to nested custom elements.

Fix for this is simple:

const shadowContents = instance.renderShadow({
elementRenderers: [LitElementRenderer],
customElementInstanceStack: [instance],
customElementHostStack: [],
deferHydration: false,
});

customElementHostStack should also get an array with [instance] instead of being empty which lets Lit SSR know that any other custom elements it encounters is nested and should therefore have defer-hydration.

What's the expected result?

Hydration from parent to child with no errors.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-u3e87a?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant