The output changes the shape of the rendered tree, and with it the hydration keys. Inlining a component, removing a provider, or unrolling a list removes an owner. Compile a server build and its client build from the same code with the same options.
What changes the keys#
- Component inlining removes the component's owner.
- Context inlining removes the provider's owner.
- Folding of a
<For>over a constant list unrolls it. Each row had its own owner, so the keys after it shift.
What the plugin does#
The Vite plugin does this for you. A hydrating build runs in module mode, where every decision depends only on the modules, never on how the bundler splits chunks. A server build and its client build split chunks differently, so decisions that depend on chunks would differ.
Module mode also keeps two modules that import each other from copying each other's components, and it copies components of a listed package only when the package is bundled. A listed package has to be bundled in every build.
What you do#
- Use the same
optimizeroptions in the server build and the client build. - Bundle the packages in
optimizer.packagesin every build. - If you use
compiledirectly, pass the same options for both.
Related#
- Chunk and module mode for how
'auto'picks a mode. - Inline components from packages for bundling listed packages.
- Use compile without Vite for the API.