feat(ssr): run hooks during server rendering (v3.5.0)#36
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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