fix(react): support SSR for A2uiSurface#2081
Conversation
There was a problem hiding this comment.
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.
|
@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. |
|
@Varun-S10 Thanks! I've updated the branch with the latest changes from main. It's ready for review now. |
|
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? |
Description
Close #2080.
A2uiSurfacecould not render in an SSR environment because the React v0.9 calls touseSyncExternalStoredid not providegetServerSnapshot. React requires this callback during server rendering and threw aMissing getServerSnapshoterror before hydration.This change uses each store's existing stable snapshot getter as its server snapshot provider in both
A2uiSurfaceand the component binding adapter.The added tests verify that:
There are no visual or public API changes.
Pre-launch Checklist
One time:
For this PR:
If you need help, consider asking for advice on the discussion board.