a2ui-project / a2ui-project/a2ui

A2uiSurface throws on SSR: useSyncExternalStore missing getServerSnapshot

Aperta
#2,080 1 commento 0 reazioni 1 assegnatario Rivendicata da @Varun-S10 Vedi su GitHub
P2 status: needs review type: bug
Lingua principale
TypeScript
Stelle
16.4k
Fork
1.3k
Merge medio
3g 15h
PR unite (30g)
134

Descrizione

## Bug

When rendering `` in a server-rendered React app (Next.js App Router, Remix, etc.), React throws during the server pass:

```
Error: Missing getServerSnapshot, which is required for server-rendered content. Will revert to client rendering.
```

Tracked this down to `A2uiSurface` calling `useSyncExternalStore` without a `getServerSnapshot` argument. React requires this on the server to produce a stable, hydration-safe snapshot — without it the call throws on every SSR render.

## Steps to reproduce

1. Install `@a2ui/react@0.10.2` in a Next.js 14+ (App Router) project
2. Render `` anywhere that executes server-side
3. Server logs the above error on first render

## Expected vs actual

Expected: the component either renders gracefully on the server (returning a stable snapshot or `null`) or is documented as client-only with a clear pattern for opting out of SSR.

Actual: React throws during the server render pass. In strict SSR setups (e.g. `experimental.serverActions: true` or a CI render test) this surfaces as a hard error rather than a recoverable warning.

## Workaround

Skip the component server-side via a `useEffect`-guarded mount flag or a `dangerouslySetInnerHTML` fallback. Works, but means the surface is effectively non-functional until JS loads.

## Environment

- `@a2ui/react`: 0.10.2
- `react`: 19.x
- Next.js: 14 (App Router)

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Trova il componente A2uiSurface nella codebase, probabilmente in un file come `packages/react/src/A2uiSurface.tsx`. Cerca la chiamata a `useSyncExternalStore`. Comprendi i requisiti React 19 SSR per `getServerSnapshot`. Controlla se nel progetto esistono pattern per server-side rendering. Il fix consiste nel fornire una funzione `getServerSnapshot` corretta oppure nel rendere il componente client-only. Verifica il fix testando in una configurazione Next.js App Router.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
next.js, react, typescript
Ambito
frontend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Specificata chiaramente
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.