Urgent.News

What's breaking now, across thousands of outlets.

Tech

Isomorphic hydration in Fitz: first paint on the server, then WASM adopts the DOM

TL;DR — Mark a component hydrate and the same .fitzv does two jobs: the server renders it to HTML for a fast first paint (SEO, works-without-JS), and on boot the client-WASM runtime adopts that exact DOM — restoring the serialized state from an embedded <script> , walking the existing nodes, and wiring the event listeners — instead of wiping and rebuilding. No re-render flash, no lost DOM…

Fitz offers a method called isomorphic hydration, which combines server-side rendering and client-side adoption of the exact DOM. The server generates HTML for the first paint, which improves SEO and works without JavaScript. Following this, the client-side WASM runtime takes over the existing DOM, retaining the serialized state from the server and maintaining the node structure.

This approach eliminates the need for a flash or lost DOM identity, addressing the common issue of hydration mismatch. Unlike traditional approaches, Fitz's client is a full-fledged application, not merely a framework runtime. The server-side rendering is achieved by compiling the component twice: once as server HTML and once as a standalone WASM app.

The hydration process is initiated by calling the hydrate() function, which restores the serialized state from a script tag embedded in the server's HTML. It then walks the existing DOM, mapping each node to its corresponding keep-node handles used during the initial build process. Event listeners are wired to the adopted nodes, enabling seamless updates to state without requiring a full page rebuild.

The end-to-end verification demonstrates that the node was adopted rather than recreated. The implementation details include the use of opt-in markers, support for composite state restoration, and handling of various component shapes. Overall, Fitz's approach to hydration combines the benefits of server-side rendering with the efficiency of client-side adoption, resulting in a seamless user experience without the drawbacks typically associated with such techniques.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Also reported by 1 other outlet

Read the original at dev.to →

More in Tech

More from Thursday 17 September →