Skip to content

fix(react): let useAgent render on the server - #1644

Open
blove wants to merge 1 commit into
mainfrom
blove/react-use-agent-ssr
Open

blove wants to merge 1 commit into
mainfrom
blove/react-use-agent-ssr

Conversation

@blove

@blove blove commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Summary

useAgent called useSyncExternalStore(subscribe, getSnapshot) with no getServerSnapshot, so any component using it threw during server rendering. Sessions do no I/O at construction or observation (documented on the LangGraph createSession), so the current snapshot is a valid server snapshot. It is now passed as the third argument; subscribe only runs in the browser.

  • Audited every useSyncExternalStore call in libs/react/src: client-tools, A2UI message surfaces and render-spec already pass a server snapshot. Only useAgent and the README editable-surfaces example lacked one.
  • Install docs (langgraph and chat) said useAgent does not support SSR; they now state the precise behavior, including that hydration matches only when the browser session holds the same snapshot.
  • The package-proof SSR fixtures were not extended; they need a packed consumer install and the unit spec covers the behavior.

Verification

  • New use-agent.ssr.spec.tsx failed before the change (threw in renderToString) and passes after.
  • nx run-many -t test lint type-tests -p react: pass.
  • node --test scripts/react-parity/verify-packages.spec.mjs: pass. Inventory check: valid.
  • apps/website vitest: docs content rules pass; 3 unrelated failures (ingest route spec, generate-api-docs, Footer newsletter) in this environment.

🤖 Generated with Claude Code

useAgent called useSyncExternalStore without getServerSnapshot, so any
component using it threw during server rendering. Sessions perform no I/O
at construction or observation, so the current snapshot is a valid server
snapshot. Pass it as the third argument, add a renderToString spec, fix the
README editable-surfaces example the same way, and update the two React
install docs that said SSR was unsupported. The other
useSyncExternalStore callers in libs/react/src already pass one.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@blove
blove enabled auto-merge November 17, 2026 23:58

This branch has not been deployed

No deployments
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.

1 participant