Skip to content

useObservable: add getServerSnapshot to useSyncExternalStore for SSR #748

Closed

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.

Activity

  1. tyler-reitz commented on Jul 21, 2026

    @tyler-reitz
    ContributorAuthor

    Surfaced during sandbox validation of #739. From the PR comment:

    useObservable calls useSyncExternalStore(subscribe, getSnapshot) without a third getServerSnapshot argument. React 18 requires it for server rendering and throws when it's absent. During testing we observed Next.js catch this and fall back gracefully, so the app works, but we didn't characterize exactly what the server sends in that case. The arch review flagged this as a V5 "just do it" item.

    Fix: pass getServerSnapshot returning the same seeded immutableStatus the client snapshot returns. Must be stable across server/client to avoid hydration mismatches — initialData seeding is the natural tie-in.

  2. added a commit that references this issue on Aug 19, 2026
    27dfc44
  3. added a commit that references this issue on Aug 20, 2026
    ac3ccf9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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