-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
SSR rehydrate #1060
Comments
Where are you injecting the script tag? |
@nlhkh, I was running into the same issue. Found a solution in #24. |
Hmm, I think I'm also seeing this. With the equivalent of const root = document.getElementById("root")
render(<App />, root.parentElement, root) it seems to blow away the contents of |
React 16 has |
There is no meaningful difference between hydrate() and render() within Preact, since we don't use checksums. If you're seeing a flash of white or similar, check that you're not rendering something that is initially different from your server-rendered HTML. Also make sure you're interpreting the meaning of "parent" and "root" correctly: const App = () => <div id="app">foo</div>
// our "server-side render":
document.write('<html><body><div id="root">' + renderToString(<App />) + '</div></body></html>')
// how "hydrate" from that:
render(<App />, document.getElementById('#root'), document.getElementById('#app')) If you'd like a hydrate method, here's a simple one: function hydrate(vnode, parent) {
return preact.render(vnode, parent, parent.firstElementChild);
} |
Sweet. This can be closed then, correct? |
@developit Very helpful. Could that go in the docs somewhere? |
It works when the component has a root element but It doesn't work using For that case is better to use the normal
|
For completeness: We do ship with a |
I have the same html tree as on the SSR but I also get flaky hydration results with some intermediate version where HTML is missing. |
@bm-stschneider That sounds suspicious. Can you file a new issue for that? |
I think that was a fault on my part, loading async data and loading that while initializing component elements, now I fetch all data before mounting that seems to work |
This is a question.
In React 16, when using SSR, in the client-side code, we need to use
hydrate
instead ofrender
so that React only registers event handler. I guess that React does this by comparing the checksum between server-side rendered html and supposed-to-be client-side rendered html.While playing with Preact and attempting to perform SSR, I notice that at first my component was rendered twice.
The rendering code is
and the resulting html is
When I change the client code to be
The rendered html appears to be correct
but I wonder if it was the original html with preact event all hooked up, or if the content was replaced with exactly the same content.
Please help me shed some light on this.
The text was updated successfully, but these errors were encountered: