Skip to content

fix(react): support SSR for A2uiSurface#2081

Open
gaoachao wants to merge 2 commits into
a2ui-project:mainfrom
gaoachao:p/gcc/fix-2080-react-ssr
Open

fix(react): support SSR for A2uiSurface#2081
gaoachao wants to merge 2 commits into
a2ui-project:mainfrom
gaoachao:p/gcc/fix-2080-react-ssr

Conversation

@gaoachao

Copy link
Copy Markdown
Contributor

Description

Close #2080.

A2uiSurface could not render in an SSR environment because the React v0.9 calls to useSyncExternalStore did not provide getServerSnapshot. React requires this callback during server rendering and threw a Missing getServerSnapshot error before hydration.

This change uses each store's existing stable snapshot getter as its server snapshot provider in both A2uiSurface and the component binding adapter.

The added tests verify that:

  • A populated surface renders to HTML on the server.
  • The client hydrates the server output without recoverable errors.
  • Data model updates remain reactive after hydration.

There are no visual or public API changes.

Pre-launch Checklist

One time:

For this PR:

  • I have updated the relevant CHANGELOG.md file.
  • No documentation update is needed because this change does not modify the public API or usage.
  • My code changes have tests.
  • If my branch is on a fork, I have verified that scripts/e2e_test.sh passes.

If you need help, consider asking for advice on the discussion board.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for server-side rendering (SSR) and hydration in the React renderer by passing the third argument (getServerSnapshot) to useSyncExternalStore in both A2uiSurface and the component adapter. Additionally, a new test suite has been added to verify SSR rendering and hydration, and the changelog has been updated. I have no feedback to provide.

@Varun-S10 Varun-S10 self-assigned this Jul 24, 2026
@Varun-S10

Copy link
Copy Markdown
Collaborator

@gaoachao, could you please update your PR branch with the latest changes from the base branch (main)? Once updated, the PR will be reviewed. Thank you for your patience and understanding.

@gaoachao

Copy link
Copy Markdown
Contributor Author

@Varun-S10 Thanks! I've updated the branch with the latest changes from main. It's ready for review now.

@Varun-S10

Copy link
Copy Markdown
Collaborator

Hi @gaoachao, I have reviewed and verified the changes. Thank you for your contribution.

Hi @ditman, I would like to escalate this PR. Could you please take a look?

@ditman

ditman commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

This look great! @gaoachao how are you using A2UI with React SSR? Do you have anything server-specific, or are you using the standard stack? Can you show a demo maybe with hardcoded JSON or similar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A2uiSurface throws on SSR: useSyncExternalStore missing getServerSnapshot

3 participants