Skip to content

getServerSnapshot infinite-loop error spams the console on every page #438

Open

Description

@thinkclay

Every page in the local dev server logs this repeatedly:

The result of getServerSnapshot should be cached to avoid an infinite loop

Reproduced on /jobs/<slug> (public, no login needed) at a 375×812 viewport. It fires many times per load, and on that page the splash overlay stops responding to clicks — "Skip" and the cookie banner buttons do nothing — which is consistent with a render loop, though I haven't proven the two are the same fault.

What I ruled out

packages/ui's useResponsive had a genuine version of this bug — _getServerSnapshot allocated a fresh { width: 1280, height: 900 } on every call, which is exactly what the warning describes. Fixed in Scaffald/ui#14.

It did not resolve this. The error still fires after:

  • rebuilding packages/ui/dist with the fix present (verified _SERVER_SNAPSHOT in the output)
  • wiping the Metro cache, apps/scaffald/.expo and node_modules/.cache
  • a full cold rebuild of the dev server
  • confirming both node_modules/@scaffald/ui symlinks resolve to the fixed copy

And useResponsive is the only useSyncExternalStore call site in the entire workspace — packages, apps, and both submodules. Nothing in node_modules implements getServerSnapshot except react-devtools-core.

So the remaining source is almost certainly inside react-native-web or expo-router — both of which use useSyncExternalStore internally and are exactly the layers SSR exercises hardest.

Why it matters

The apex runs server-rendered (web.output: 'server'). An unstable server snapshot means React can re-render in a loop during hydration, which costs CPU on first paint for every visitor to a public page — the marketing landing, profiles, job listings. It also buries real errors under identical noise, which is how the notification-panel bug (#382) went unnoticed for months.

Suggested next step

Bisect by rendering a trivial route with no layout primitives and see whether it still fires; that separates our component tree from the router/runtime. If it's expo-router, worth checking against SDK 56 upstream issues before working around it.

Not urgent — it's a warning, not a crash, and production has been serving fine. But it should not be permanent background noise.

Activity

  1. added
    bug
    on Jul 30, 2026
  2. thinkclay commented on Jul 30, 2026

    @thinkclay
    ContributorAuthor

    Bisected. It is not our code, and the scope is narrower than I could claim before.

    The decisive test

    Created a route containing nothing but raw react-native primitives — no @scaffald/ui, no scf-core, no providers:

    import { Text, View } from 'react-native'
    export default function Bisect438() {
      return <View><Text>bisect probe</Text></View>
    }

    Also short-circuited the root _layout to render <Stack> alone, with SafeAreaProvider / UniversalThemeProvider / ThemeBridge / GestureHandlerRootView / Provider / ErrorBoundary all removed.

    The warning still fires — after watchman watch-del, a wiped Metro cache, wiped .expo, and a cold rebuild. So it comes from expo-router / react-native-web / the React 19 renderer, not from anything we wrote or compose.

    Suspects, from reading the source

    expo-router has ten useSyncExternalStore call sites. Most pass stable references (store.getState, navigation.isFocused, arrow-bound loaderCache.getSnapshot — that one even has a comment explaining the stability requirement). Two are worth a closer look:

    • global-state/useRouteInfo.js → store.getRouteInfo, which returns storeRef.current.routeInfo || defaultRouteInfo. defaultRouteInfo is a module constant, so it's stable itself — but getRouteInfoFromState spreads it ({ ...defaultRouteInfo, ... }) on the not-found/sitemap path, producing a fresh object per call. routeInfoCache exists precisely to dedupe these, keyed on a WeakMap over state plus a JSON.stringify value cache — so a miss during hydration would return a new identity.
    • imperative-api.js → routingQueue.snapshot, which returns routingQueue.queue. run() reassigns queue = [], so identity changes by design, though that alone shouldn't trip the server snapshot check.

    @tanstack/react-query is clean — every call site passes () => observer.getCurrentResult() backed by a cached observer result.

    Also observed

    Every load logs An error occurred in the <ContextNavigator> component (twice, matching the double render). ContextNavigator is expo-router's own — likely the same fault surfacing as a caught error rather than a separate one.

    What I tried and could not use

    An interception wrapper around React.useSyncExternalStore (to print the offending getServerSnapshot source) never installed — Metro's module registry hands each consumer its own binding, so mutating the react export from app code doesn't reach node_modules callers. Patching react-dom's dev bundle to log the offender was blocked by the sandbox. Both are dead ends worth recording so nobody repeats them; a working approach would be a Metro resolver alias or patching via pnpm patch.

    Status

    Scaffald/ui#14 still stands on its own merits — useResponsive did return a fresh object from getServerSnapshot, which is a real contract violation — but it is confirmed not the cause here. The superproject submodule pointer has been left at the current commit; it should be bumped after that PR merges, not before.

    Next step for whoever picks this up: pnpm patch expo-router and log identities in useRouteInfo, or check SDK 56 upstream for an existing report before working around it.

  3. thinkclay commented on Jul 30, 2026

    @thinkclay
    ContributorAuthor

    Picked this up. Three results: one cause found, two red herrings eliminated, and the user-visible half is still unresolved.

    1. Scaffald/ui#14 was never merged

    The PR was still open, so our submodule pointer (262b73d) still contained the buggy _getServerSnapshot. I verified by reading the source at our pinned SHA — the fresh-object-literal return was right there.

    That's very likely why "rebuilding packages/ui/dist with the fix present" appeared not to help: apps/scaffald/metro.config.js prefers the source export condition for workspace packages, so the dev server bundles packages/ui/src/**, not dist. Rebuilding dist with a fix in a local working copy changes nothing the dev server reads. Merged as Scaffald/ui#14 → PR #446 bumps the pointer.

    2. But I could not reproduce the warning, so I'm not claiming #14 fixes this

    Being explicit because it matters for closing this out:

    • Initial repro succeeded: 2 occurrences on /jobs/pipe-welder-fabricator-apex, with a week-old Metro cache.
    • After rm -rf of metro-cache + apps/scaffald/.expo + node_modules/.cache, the warning stopped — with the fix applied.
    • I then reverted the fix (buggy source back on disk, confirmed by reading the file), cold-restarted the server, and loaded several public job pages plus a storage-cleared fresh SSR+hydration pass. The warning did not return.

    So the variable that actually correlated was cache state, not the source. The one observation came from a stale bundle compiled from older code — the metro-cache trap pattern again. I can't prove #14 was the cure, and I'd rather say that than imply a fix I didn't demonstrate.

    Worth re-checking on a machine that still has a stale cache, if anyone has one.

    3. Two things ruled out (so nobody else chases them)

    • DIV#S:0 next to DIV#root is not a duplicate app. I briefly thought it was — it holds a full second copy of the banner markup. It's React's streaming-SSR Suspense placeholder: display: none, 0×0, inert. Not the fault.
    • Doubled console output is StrictMode, not a double mount. Every log/warn appears exactly twice in dev, which reads like a render loop and isn't.

    4. Still unresolved: the clicks-do-nothing symptom

    This half reproduces reliably and I think it's the part that actually hurts users:

    On /jobs/<slug> at 375×812, clicking Reject on the cookie banner with a real mouse event does nothing — no consent written to localStorage, banner stays up. Same for Skip on the splash.

    What I established:

    • Nothing is intercepting. document.elementFromPoint at the button's centre returns the button itself; pointer-events: auto all the way up the chain; no overlay above it.
    • The handler chain is correctly wired — CookieConsentBanner's Reject → rejectAll → persistSelections → setConsentState, and the banner gates on isReady && !consentState.
    • A synthetic .click() behaves differently from a real click: it does write consent to localStorage, but the banner still doesn't hide. A real click writes nothing at all.

    That split (handler reachable programmatically, not via real pointer events; and state written without the UI reacting) points at react-native-web Pressable event handling under SSR hydration rather than anything in our banner code. I didn't get to the bottom of it and don't want to guess further.

    Suggest: keep this issue open for the click bug and retitle it accordingly, since the getServerSnapshot line is now the less important half. Happy to keep digging if it's worth prioritising — it affects every public page (marketing, job listings, profiles), which makes it more than cosmetic.

  4. thinkclay commented on Jul 30, 2026

    @thinkclay
    ContributorAuthor

    Follow-up on the clicks-do-nothing half. I have it narrowed to two separate faults, both reproducible on /jobs/<slug> at 375×812 (which redirects to /auth for a signed-out user — the banner and login form are what's on screen).

    Fault A — the press only fires from a bare click event, not from a real pointer sequence

    Three tests against the same Reject button on one fresh page load:

    How the button was pressed Consent written?
    Real mouse click (CDP Input.dispatchMouseEvent, correct coords, verified 2× DPR) ❌ no
    Synthetic pointerover/enter/down + mousedown + pointerup/mouseup, no trailing click ❌ no
    element.click() (dispatches only a click event) ✅ yes

    Supporting detail: the button's React props contain onClick and no pointer/responder handlers — ["onMouseEnter","onMouseLeave","onKeyDown","onClick","onContextMenu","onBlur","onFocus"]. It is not disabled (disabled: false, no aria-disabled), nothing overlays it (elementFromPoint at its centre returns the button; pointer-events: auto for ten ancestors up), and no ancestor carries responder/scroll handlers.

    So the press path is onClick-only, and a genuine pointer-down→up→click sequence does not reach it. The shape of that — a real pointerdown suppressing the trailing click — is consistent with react-native-web's document-level responder listeners calling preventDefault() on pointerdown, which in Blink can cancel the click that follows. I did not confirm that mechanism in RNW's source, so treat it as the leading hypothesis, not a conclusion.

    Correction to something I implied earlier: I also tried invoking props.onClick(fakeEvent) directly and it didn't write consent. Discount that result — my hand-rolled event object was almost certainly missing fields the handler reads, so it proves nothing either way.

    Caveat worth stating: all of my "real" clicks come through CDP. That's normally indistinguishable from human input, but if RNW's behaviour depends on trusted-sequence specifics, a human mouse might behave differently. Since you observed the same dead buttons independently, I think it's real for humans — but someone should confirm with a physical click before anyone invests in an RNW workaround.

    Fault B — persisting consent at runtime does not hide the banner

    Independent of A, and cleanly reproducible:

    • element.click() on Reject → scf-cookie-consent is written to localStorage → banner stays visible.
    • Yet on a fresh load with that key already present, the banner correctly never appears.

    So load-time gating works and runtime state propagation doesn't. The chain reads correctly on paper (rejectAll → persistSelections → setConsentState, banner gated on isReady && !consentState), which makes this the more interesting of the two: the visible banner isn't re-rendering off the state that was just set. Worth checking whether CookieConsentProvider ends up mounted more than once, given packages/scf-core/provider/index.tsx builds the tree through a reduce-based compose with no initial value.

    Why this matters more than the console warning

    Fault A means no button on a public page responds to a first-load press — I confirmed "Sign in with password" is equally dead, so it isn't banner-specific. That's every visitor to the marketing landing, job listings and profiles on the apex.

    I'd suggest retitling this issue to the click failure and demoting the getServerSnapshot line to a footnote (PR #446 lands the stable-snapshot fix as latent-bug removal regardless).

    Stopping here rather than guessing at an RNW workaround — happy to keep going if you want this prioritised, but the next step is either an upstream RNW/expo-router check for SDK 56 or a physical-click confirmation, and you're better placed to say which.

  5. thinkclay commented on Jul 30, 2026

    @thinkclay
    ContributorAuthor

    Two notes to keep the trail accurate, then I'm parking this.

    The doubled CookieConsentProvider in the fiber tree is benign — don't chase it. Walking the live fiber up from the Reject button gives:

    button → … → CookieConsentBanner → CookieConsentProvider → CookieConsentProvider → DatePickerProvider → Provider
    

    Two entries with the same name looks like a duplicate mount, and I thought it might explain Fault B. It doesn't: packages/scf-core/provider/cookie-consent/CookieConsentProvider.tsx imports the ui one as CookieConsentProvider as BeyondCookieConsentProvider and renders it inside itself, so both fibers legitimately carry the name CookieConsentProvider. One logical provider, nested wrapper. I also confirmed the reduce-based compose in provider/index.tsx mounts it once, and that there is exactly one Reject button in #root.

    Fault B is therefore deeper than a context/memo mistake. For the record I checked and ruled out the obvious candidates:

    • useMemo deps on the context value are complete — consentState and shouldShowBanner are both listed.
    • The stored payload is unmistakably rejectAll's own output ({"version":"1","updatedAt":…,"selections":{"strictly-necessary":true,"performance":false}}), so persistSelections really ran, which means setConsentState(state) ran on the same provider that renders the visible banner.
    • Single banner, correct provider, complete deps, state set — and it still doesn't hide.

    That combination is genuinely odd and I don't want to speculate further without reading RNW/React internals properly.

    One caveat on my own evidence, since it affects how much weight to give Fault B: during part of the session a #S:0 streaming placeholder was present that also contained a Reject button, so an unscoped querySelectorAll('button') could have targeted the wrong copy. The Fault B measurement I trust is the one scoped explicitly to document.querySelector('#root') — that one wrote consent and left the #root banner visible. The unscoped variants should be re-run by whoever picks this up.

    Net for triage: Fault A (first-load presses dead on public pages) is the one with clean, repeatable evidence and the real user impact. Fault B is real but its mechanism is unexplained. PR #446 is independent of both.

  6. thinkclay commented on Jul 30, 2026

    @thinkclay
    ContributorAuthor

    Noting for anyone who lands here later: this was closed as not planned at 11:17, which was before my last two comments went up — so the investigation notes above outlived the issue.

    The getServerSnapshot half is genuinely resolved: Scaffald/ui#14 had been sitting open and unmerged, and PR #446 landed the stable-snapshot fix on main (submodule now at 043505e). Closing this is fair on that basis.

    The two faults I found while digging are not resolved, so I've refiled them standalone rather than leaving them in comments here:

    Both carry the full evidence, the red herrings I ruled out (#S:0 is an inert streaming placeholder; the doubled CookieConsentProvider is a same-named nested wrapper), and an explicit caveat that all my "real" clicks came via CDP and want a physical-mouse confirmation before anyone writes an RNW workaround.

    No action needed on this issue — pointers only.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions