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
Hydration always results in duplicate render #3651
Comments
The reason for this is that hydration is erroring due to the mismatch of template from the server render that's in the declarative shadow DOM, and what's available client-side at the time of hydration. At server render, the template is provided a In order to make sure hydration happens without error, you need to provide the same prop on the client before the custom element is registered so that by the time hydration happens the element has the same data it had when it was server rendered. See https://stackblitz.com/edit/lit-ssr-global-urdvns?file=src%2Fpages%2Findex.js Alternatively, since your example data is serializable, you could provide it on the server as an attribute binding with a JSON string representation of the array, then you wouldn't need to add the data separately on the client script. See https://stackblitz.com/edit/lit-ssr-global-csyetv?file=src%2Fpages%2Findex.js |
Thanks you so much, this is very helpful.
|
Ahhh okay the setter makes it problematic since the setter will only work on the element when it is registered, and the component needs It'll let you register the custom element without triggering hydration. You can control when that happens by setting the data first and removing the attribute. Here's your repro modified with that approach. Notice the We now first import of the component definition and await for its registration, then set the |
Thanks again, this works perfectly. |
Which package(s) are affected?
SSR (@lit-labs/ssr)
Description
I'm currently experimenting with lit-ssr and I'm running into the problem that a hydrated component is rendered twice. I have a component that needs to be SSR'ed and then hydrated with an array of objects. That data is coming from an api and I notice that the delay that this causes also causes the component to be rendered twice. I forked the example from the lit website and simulated this delay with setTimeout.
Reproduction
https://stackblitz.com/edit/lit-ssr-global-ziy5z1
Workaround
I have not found a workaround.
Is this a regression?
No or unsure. This never worked, or I haven't tried before.
Affected versions
Failing in 3.0.1
Browser/OS/Node environment
Browser: Chrome 109.0.5414.119
OS: MacOS Ventura 13.1
Node version: 18.14.0
NPM version: 9.3.1
The text was updated successfully, but these errors were encountered: