supabase-nextjs-debugger
Skill5 starsChanged 2 months agoMITView on GitHub
Diagnose and fix Supabase + Next.js App Router bugs on Vercel serverless. Use when: "Vercel 404/500", "Supabase RLS error", "pre-commit not found", "serverless state lost", "hydration error #418", "API works locally but not on Vercel", "env vars not working on Vercel", "NEXT_PUBLIC_ not available at runtime". Do NOT use for: general Next.js UI bugs, Supabase schema design, or non-Vercel deployments.
- Reads credentials
- Sends data out
In this repository25 other files it gives its agents.
- AGENTS.mdAGENTS.md
- adk-engineerSkill
- agent-orchestratorSkill
- brainstormingSkill
- bugfixSkill
- classify-reviewSkill
- code-reviewerSkill
- codex-reviewSkill
- context7-skillsSkill
- developer-growth-analysisSkill
- file-organizerSkill
- gcp-deploy-guardianSkill
- gws-workspaceSkill
- handoverSkill
- modern-architectureSkill
- planSkill
- repo-cleanSkill
- review-loopSkill
- security-reviewSkill
- skill-creatorSkill
- tdd-workflowSkill
- test-falsifySkill
- ui-design-systemSkill
- ui-skillsSkill
- ux-researcher-designerSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 7 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 28
When a Supabase + Next.js app fails on Vercel, check these in order:
- Distinctive: line 36
Fix: Add runtime fallback in the Supabase client:
- Very specific: line 55
Never rely on in-memory Map/Set across requests
- Distinctive: line 56
All state must go through Supabase (or another external store)
- Distinctive: line 57
If using fallback in-memory store, understand it's per-instance only </important>
- Distinctive: line 70
Fix: Use INSERT + catch unique_violation (23505) instead of upsert when RLS is restrictive.
- Distinctive: line 72
Verify: Check ALL policies on the table:
- Distinctive: line 126
Fix: Use the deferred state as a dependency:
- Distinctive: line 144
Fix: Always log Supabase errors before returning undefined:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Supabase + Next.js on Vercel Debugger
Critical: Verification Protocol
NEVER claim a fix is complete without these checks:
npx tsc --noEmit(zero errors)npx vitest run(all pass)npx next build(successful)- curl test against production URL (full API flow → 200)
- Vercel runtime logs check (zero 404/500 after deploy)
- Ask user to test in browser (curl success != browser success)
<important if="debugging Vercel environment variable issues or Supabase client silently failing on Vercel">
## Diagnostic ChecklistWhen a Supabase + Next.js app fails on Vercel, check these in order:
1. Environment Variables (Most Common)
NEXT_PUBLIC_ vars are inlined at build time by Next.js. If env vars were added to Vercel AFTER the build, they won't be available in compiled code.
Symptom: API works with curl but Supabase operations silently fail; isSupabaseConfigured is false.
Fix: Add runtime fallback in the Supabase client:
const supabaseUrl =
process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL;
const supabaseAnonKey =
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || process.env.SUPABASE_ANON_KEY;Action: Tell user to add non-prefixed env vars (SUPABASE_URL, SUPABASE_ANON_KEY) to Vercel, OR redeploy after setting NEXT_PUBLIC_ vars.
</important>
<important if="debugging intermittent API failures on Vercel or state lost between serverless invocations">
### 2. Serverless StatelessnessVercel serverless functions do NOT share in-memory state across instances.
Symptom: API works intermittently (warm instance reuse) but fails on cold starts.
Fix:
- Never rely on in-memory
Map/Setacross requests - All state must go through Supabase (or another external store)
- If using fallback in-memory store, understand it's per-instance only
</important>
<important if="debugging Supabase RLS policy errors, silent INSERT/SELECT/UPDATE failures, or upsert conflicts">
### 3. Supabase RLS Policy ConflictsSymptom: INSERT succeeds (200) but subsequent SELECT returns no rows, or UPDATE fails silently.
Common traps:
WITH CHECK (revealed = true)blocks UPDATE that setsrevealed = false- Upsert (
onConflict) triggers UPDATE path, which may be blocked by restrictive RLS - Missing SELECT policy (RLS enabled but no
FOR SELECTpolicy)
Fix: Use INSERT + catch unique_violation (23505) instead of upsert when RLS is restrictive.
Verify: Check ALL policies on the table:
SELECT * FROM pg_policies WHERE tablename = 'your_table';</important><important if="debugging 404 on page refresh or stale localStorage session data causing Supabase query misses">
### 4. Stale Data from Persistent Session IDsSymptom: First visit works, subsequent visits/refreshes get 404. Works with new incognito window.
Root cause: localStorage persists a sessionId across page loads. Old rows in Supabase (e.g., revealed = true) conflict with new INSERTs (unique_violation ignored), and SELECTs filter by revealed = false -> no match -> 404.
Fix: Either:
- Generate fresh sessionId per page load (no localStorage persistence)
- Or handle stale rows: DELETE old row before INSERT (requires RLS DELETE policy)
- Or use
revealedfilter only in SELECT, not as the sole lookup key</important>
<important if="fixing React hydration error #418 or SSR/client content mismatch">
### 5. React Hydration Error #418Symptom: Uncaught Error: Minified React error #418 in browser console.
Root cause: Text content differs between SSR and client hydration. Common causes:
useState(() => randomValue())-- generates different values on server vs clientuseState(() => uuid())-- different UUID on each rendertypeof window === "undefined"conditional rendering with different textnew Date()/Math.random()in render path
Fix pattern:
// BAD: different values on SSR vs client
const [id] = useState(() => uuidv4());
const [personality] = useState(() => randomPersonalityType());
// GOOD: deterministic default on SSR, randomize in useEffect
const [id, setId] = useState("");
const [personality, setPersonality] = useState<Type>("default");
useEffect(() => {
setId(uuidv4());
setPersonality(randomPersonalityType());
}, []);</important><important if="debugging useEffect race conditions or API calls firing before state initialization">
### 6. useEffect Initialization OrderSymptom: API call fires before client-side state is initialized.
Root cause: useEffect with [] dependency runs on mount, but deferred state (from another useEffect) hasn't been set yet.
Fix: Use the deferred state as a dependency:
// BAD: runs before sessionId is set
useEffect(() => { startRound(); }, []);
// GOOD: waits for sessionId
useEffect(() => {
if (!sessionId) return;
startRound();
}, [sessionId]);</important><important if="debugging silent Supabase query failures or undefined return values without error logs">
### 7. Silent Supabase Query FailuresSymptom: getPreCommit returns undefined but no error logged.
Fix: Always log Supabase errors before returning undefined:
if (error) {
console.error("[getPreCommit] query failed:", error.message, error.code);
return undefined;
}</important><important if="verifying a Supabase + Next.js fix before reporting completion">
## Verification Commands# 1. Type check
npx tsc --noEmit
# 2. Tests
npx vitest run
# 3. Production build
npx next build
# 4. curl smoke test (replace URL and session)
SESSION=$(python3 -c 'import uuid; print(uuid.uuid4())')
curl -s -X POST https://YOUR_APP.vercel.app/api/start-round \
-H "Content-Type: application/json" \
-d "{\"session_id\":\"$SESSION\",...}" | jq .
curl -s -w "\nHTTP: %{http_code}\n" \
-X POST https://YOUR_APP.vercel.app/api/play \
-H "Content-Type: application/json" \
-d "{\"session_id\":\"$SESSION\",...}"
# 5. Check Vercel runtime logs via MCP tools
# Filter by statusCode "404" and "500" after deploy</important><important if="diagnosing Vercel deployment errors or runtime 404/500 via MCP tools">
## Vercel MCP Tools for Diagnosislist_projects-> find project IDlist_deployments-> confirm latest deployment is READYget_deployment_build_logs-> check for build errorsget_runtime_logswithstatusCode: "404"or"500"-> find API errorsget_runtime_logswithlevel: ["error"]-> find application errors</important>
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

