Conversation
Replace the documented stub in src/lib/realtime/supabase.ts with a real createSupabaseRealtimeProvider(): subscribes to postgres_changes on public.orders (scoped by location_id for KDS, id for the customer tracker) via the @supabase/ssr browser client, so the websocket runs as the signed-in user and Realtime enforces the same RLS SELECT policies as PostgREST. Same RealtimeProvider.subscribe() contract as the poller, so use-kitchen-board and use-order-tracking are unchanged. Initial load uses the same fetcher; live deltas re-run it (debounced, de-duped) to keep the server-computed payload as the single source of truth; reconnect re-fetches; teardown is idempotent. getRealtimeProvider() selects Supabase Realtime when the public Supabase env is present and falls back to polling otherwise (zero-env build/preview/tests stay green), mirroring the getPosDriver() guard. No new deps; components, auth/middleware, payments, and next.config untouched. Docs: supabase/README.md gains the exact publication SQL (REPLICA IDENTITY FULL + add orders to supabase_realtime) for the orchestrator. Plan saved at plans/focaccia-51842-realtime.md. New env-free Vitest covers selection + fallback. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@
Summary
Upgrades the realtime layer from interval polling to Supabase Realtime, behind the existing
getRealtimeProvider()seam. The KDS board and the customer order tracker now receive instant websocket pushes in production, with zero component changes and the zero-env build/preview/test invariant fully intact.src/lib/realtime/supabase.ts— replaces the documented stub with a realcreateSupabaseRealtimeProvider(). Subscribes topostgres_changes(event: "*") onpublic.orders, scoped by a server-side filter parsed from the topic the hooks already pass:kds:<tenant>:<location>→location_id=eq.<location>,track:<orderId>→id=eq.<orderId>. Uses the@supabase/ssrbrowser client (getBrowserSupabase()), so the socket runs as the signed-in user and Realtime enforces the same RLS SELECT policies as PostgREST.fetcherthe poller used; live deltas re-run it (debounced 150ms, concurrent runs de-duped) so the server-computed payload (KDS elapsed/age/station, tracker live delivery state) stays the single source of truth.SUBSCRIBEDtransition to reconcile anything missed offline.src/lib/realtime/index.ts—getRealtimeProvider()selects Supabase Realtime whenNEXT_PUBLIC_SUPABASE_URL+NEXT_PUBLIC_SUPABASE_ANON_KEYare present, else the poller. Read lazily at call time (memoized); nothing touches env at module load — mirrors thegetPosDriver()/readDbConfig()guard.src/lib/realtime/realtime.test.ts— new env-free Vitest covering selection (poller with no env, Supabase with env, memoized) and the provider's per-subscription initial-fetch fallback for both topic shapes.supabase/README.md— new "Enabling Supabase Realtime" section with the exact publication SQL + verification queries.plans/focaccia-51842-realtime.md— design + plan.Scope
Only the realtime layer + its doc/test. No new deps (
@supabase/supabase-jsand@supabase/ssralready present). No changes to auth/middleware, payments,next.config, orpackage.json. Components, money, and RLS correctness untouched.Verified locally (no env vars)
npm install && npm run build && npm run typecheck && npm run lint && npm run test:run— all green (127 tests).Orchestrator: enable Realtime on the LIVE DB
Run once on the live Supabase project (RLS is unchanged — Realtime reuses the existing
ordersSELECT policies):Verify:
Not required for the build/deploy — it only makes updates instant once env vars are set.
🤖 Generated with Claude Code
@