Common mistakes
Common mistakes in the SSR, hydration and streaming guide.
- Browser-only code in a component body.
window,localStorage,matchMediathrow on the server. Move them intoonMount, which does not run there. - Different output on the first client render. Locale formatting, timezones,
Math.random(),Date.now(),window.innerWidth. Compute them on both sides from the same input (pass them in the serialized data) or defer them toonMount. - Module-level request state. Signals and stores defined at module scope are shared by all requests.
- Unkeyed resources that move. Give
useResourceakeywhen the server data must find its resource again. - Waterfalls. Child resources that depend on a parent's value cost one pass each. Fetch in parallel.
- Serializing secrets. See the caution above.
- Expecting comments on the client. The markers are a server-HTML detail. Do not query for them.
- Forgetting the portal collector. A dialog open at render time is missing from the HTML unless the render gets
portalsand the document emitsportals.html()(see "Portals on the server").@shadow-js/duskdoes both.