This is a question.
In React 16, when using SSR, in the client-side code, we need to use hydrate instead of render 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
// Server code
app.get("/", (req, res) => {
const html = renderToString(<App />)
res.render('index', { html })
})
// Client code
const root = document.getElementById("root")
render(<App />, root)
and the resulting html is
...
<div id="root">
<div>This is my app.</div>
<div>This is my app.</div>
</div>
...
When I change the client code to be
// Client code
const root = document.getElementById("root")
render(<App />, document.body, root)
The rendered html appears to be correct
...
<div id="root">
<div>This is my app.</div>
</div>
...
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.
This is a question.
In React 16, when using SSR, in the client-side code, we need to use
hydrateinstead ofrenderso 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.