Server rendering
The core never touches the DOM, and gridla/react does not read browser globals at import time, so both import cleanly in Node. GridProvider renders items at their source coordinates when no size has been measured, which is what renderToString produces.
The markup contains each item's transform: translate(x, y) in source coordinates. On the client, GridCanvas measures itself after mount and the provider projects the layout onto the measured size.
Avoiding the jump
If the element's width differs from the source canvas width, items move after hydration. Three ways to avoid a visible jump:
- Author at the rendered width. When the canvas has a known width (a fixed-width column, a print layout), save layouts at that width so projection is the identity.
- Turn responsiveness off.
responsive={false}sizes the canvas element to the layout and never projects; the page scrolls instead of reflowing. - Hide until measured. Read
state.sizeand fade the canvas in once it is non-null.
Do the projection on the server instead when you know the viewport (for example from a hint header): projectLayout(layout, { width }) before rendering. The core is the same code on both sides, so the result matches what the client would compute.
Frameworks
Nothing here is framework-specific. In a React Server Components setup, the provider and canvas are client components (they use hooks and events); the layout is plain data and can be produced in a server component and passed down.