Skip to content

useObservable: add getServerSnapshot to useSyncExternalStore for SSR #748

Description

@tyler-reitz

`useObservable` calls `useSyncExternalStore(subscribe, getSnapshot)` with only two arguments. React 18 requires a third `getServerSnapshot` for server rendering. Without it, React throws during SSR and Next.js App Router falls back to client rendering for any subtree using a reactfire hook.

The fix is to pass a `getServerSnapshot` that returns the same seeded `immutableStatus` the client snapshot returns. The server snapshot must be stable across server/client to avoid hydration mismatches, so `initialData` seeding is the natural tie-in.

Flagged in the arch review as a V5 "just do it" item: not a spike, not blocked on any API decision.

Metadata

Metadata

Assignees

No one assigned

    Labels

    v5Planned for v5

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions