Skip to content

fix(scf-core): lazy-init the Supabase client; run the EAS builder on Node 22 - #516

Merged
thinkclay merged 1 commit into
mainfrom
claude/lazy-supabase-client-node22
Jul 30, 2026
Merged

thinkclay merged 1 commit into
mainfrom
claude/lazy-supabase-client-node22

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #512 (both remediation halves — each sufficient alone, both taken).

What

  1. Lazy client. packages/scf-core/utils/supabase/client.ts no longer calls createClient at module scope. expo-router evaluates route modules under Node at build time to generate the server manifest, and this module is reachable from route layouts (useProtectedRoute → useUser → client.ts). Construction now happens on first property access behind a Proxy — importing the module is side-effect-free, and every existing supabase.… call site works unchanged.
  2. Node 22 builder. eas.json production profile: node 20.19.4 → 22.20.0 (matching this machine, so local verification runs on what production builds on), plus root engines.node >=22.

The harness — and why v1.16.0 passed local verification while breaking on EAS

Plain expo export --platform ios does not exercise the failing path: it skips the "Exporting server" step entirely. The EAS EAGER_BUNDLE phase runs expo export:embed --eager, which additionally bundles and evaluates getServerManifest under Node. That's the gap that let the v1.16.0 regression through.

Reproduction (Node 20 simulated via NODE_OPTIONS=--require preload that deletes globalThis.WebSocket):

state export:embed --eager result
eager client + supabase-js 2.110.9 + no WebSocket exit 1 — Node.js detected but native WebSocket not found (the exact EAS error) ✅
lazy client + supabase-js 2.110.9 + no WebSocket exit 0 — bundle written ✅

Same command, same deps, same stripped runtime; only the lazy-init differs. Causal.

Deliberately not in this PR

@supabase/supabase-js stays pinned at ~2.86. The build-time blocker is gone (proven above against 2.110.9), but the 2.86→2.110 runtime surface (auth/realtime behavior in the app) deserves its own PR with its own validation. The catalog note now says exactly that.

APP_IOS_BUILD_NUMBER → 11203 so a Node-22 validation build can't collide with the shipped 11202 (#513 tracks automating this in release.sh).

Fresh (cache-skipped) scf-core typecheck, unit tests, and prepush all pass. Next step after merge: a production-profile EAS build without submit to validate the Node 22 toolchain on the real builder.

🤖 Generated with Claude Code

…Node 22

Two halves of #512, each sufficient alone, both taken:

1. packages/scf-core/utils/supabase/client.ts no longer calls createClient at
   module scope. expo-router evaluates route modules UNDER NODE at build time
   to generate the server manifest (export:embed → exportStandaloneServerAsync
   → getBuildTimeServerManifestAsync), and this module is reachable from route
   layouts via useProtectedRoute → useUser. Construction now happens on first
   property access behind a Proxy, so importing the module is side-effect-free
   and every existing `supabase.…` call site works unchanged.

2. apps/scaffald/eas.json production builder moves node 20.19.4 → 22.20.0
   (matching this machine, so local verification runs on what production
   builds on) and root package.json declares engines.node >=22. Node 22 has
   the native WebSocket global that newer @supabase/realtime-js demands.

Verified with a harness that reproduces EAS's EAGER_BUNDLE locally — plain
`expo export --platform ios` does NOT exercise the failing path (it skips the
"Exporting server" step), which is why the v1.16.0 breakage passed local
verification. The real invocation is `expo export:embed --eager`:

  NODE_OPTIONS=--require strip-websocket.cjs   # delete globalThis.WebSocket,
  expo export:embed --eager --platform ios --dev false   # = Node 20 behavior

  eager client + supabase-js 2.110.9 → exit 1, "Node.js detected but native
                                       WebSocket not found" (the EAS error)
  lazy client  + supabase-js 2.110.9 → exit 0, bundle written

Same command, same deps, same stripped runtime; only the lazy-init differs.

supabase-js itself stays pinned at ~2.86: the build-time blocker is gone, but
the 2.86→2.110 runtime surface (auth/realtime) deserves its own PR. The
catalog note now says exactly that. APP_IOS_BUILD_NUMBER moves to 11203 so a
validation build cannot collide with the shipped 11202 (#513 tracks making
release.sh do this).

Refs #512, refs #513

Co-Authored-By: Claude Fable 5 <[email protected]>
@thinkclay
thinkclay merged commit 5513577 into main Jul 30, 2026
4 of 6 checks passed
@thinkclay
thinkclay deleted the claude/lazy-supabase-client-node22 branch July 30, 2026 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EAS builder pins Node 20.19.4, which caps @supabase/supabase-js at 2.86 (realtime-js needs a native WebSocket)

1 participant