Skip to content

feat(ssr): run hooks during server rendering (v3.5.0)#36

Merged
monstercameron merged 1 commit into
masterfrom
react-parity/ssr-hooks
Jun 25, 2026
Merged

feat(ssr): run hooks during server rendering (v3.5.0)#36
monstercameron merged 1 commit into
masterfrom
react-parity/ssr-hooks

Conversation

@monstercameron

Copy link
Copy Markdown
Owner

Feature: SSR hooks

ui.RenderToString now runs hooks: useState (initial), useRef/useMemo, useContext (resolves provider value, context flows through host elements + nested providers override), useEffect skipped on server — matching React's ReactDOMServerIntegrationHooks. Lets GWC server-render real hook-using components.

Implemented by threading an inherited context map through the SSR renderer (derived at each ContextProvider). Buffered path fully supported; streaming runs hooks but context-threading is a documented follow-up. Full suite + native/wasm builds pass; no regression. Ships as v3.5.0 (minor).

🤖 Generated with Claude Code

ui.RenderToString was hook-less — a component calling any hook errored
("called outside component context"), so only hook-free trees could be
server-rendered. RenderToString now installs a transient hook fiber per
component (withSSRHookFiber): GoUseState returns its initial value, GoUseRef/
GoUseMemo compute, GoUseContextValue resolves to the nearest provider value, and
GoUseEffect is queued but never committed (so effects don't run on the server) —
matching React's ReactDOMServerIntegrationHooks.

Context propagation: the SSR renderer threads an inherited context map
(descriptor ID -> value) through the recursion, derived at each ContextProvider
boundary via deriveContextValues, so context flows through host elements and
nested providers override correctly.

Scope/limits: hook-component SSR uses the package-global current fiber (like the
client reconciler), so a process renders hook trees one at a time. The streaming
SSR path runs hooks but passes nil context (context threading there is a
follow-up); the buffered RenderToString path is fully supported.

Replaces the old boundary test with ui/ssr_hooks_test.go (useState/useRef/
useMemo/useContext + effect-skip + nested-provider). Full suite passes,
native + wasm build clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@monstercameron monstercameron merged commit e3f8ef5 into master Jun 25, 2026
3 checks passed
@monstercameron monstercameron deleted the react-parity/ssr-hooks branch June 25, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants