Describe the bug
When a custom element that also uses a custom element as part of its render template is server rendered, the child might try and hydrate before its parent does. This is problematic as the child might try to hydrate before receiving props from its parent.
This causes <simple-button> to hydrate with the default empty array before it gets the property from parent, causing hydration error with shorter than expected iterable.
Providing the renderer gives Lit SSR context that this is rendering a custom element so any child custom elements should get defer-hydration attribute added to wait for parent to hydrate before hydrating themselves.
Describe the bug When a custom element that also uses a custom element as part of its render template is server rendered, the child might try and hydrate before its parent does. This is problematic as the child might try to hydrate before receiving props from its parent.
A user reported an issue with the Astro Lit integration in the Lit discord(https://discord.com/channels/1012791295170859069/1169254576449396806/1169254576449396806) and I found the same issue in
@lit-labs/ssr-react
as documented here: https://github.com/lit/lit/issues/4363To Reproduce One way to surface the problem: In the playground, I made
<simple-button>
take an array prop that defaults to empty array.I made
<my-element>
also render<simple-button>
as part of its render template, giving it an array as prop.This causes
<simple-button>
to hydrate with the default empty array before it gets the property from parent, causing hydration error with shorter than expected iterable.Solution These lines here https://github.com/prashantpalikhe/nuxt-ssr-lit/blob/a77f9f8f2f604de178f1b17cb1d4ee1f7b078756/src/runtime/utils/litElementRenderer.ts#L19-L20 should be
Providing the
renderer
gives Lit SSR context that this is rendering a custom element so any child custom elements should getdefer-hydration
attribute added to wait for parent to hydrate before hydrating themselves.