From 125ff2442294a79f2de4dfd5fef3bf48d6d7774e Mon Sep 17 00:00:00 2001 From: Hansi Lee Date: Tue, 3 Nov 2026 20:47:19 -0800 Subject: [PATCH] Fix Next.js dev prerender warnings on / and /profile - getSchedule: raise cacheLife stale to 300s (revalidate stays 30s) so the schedule stays in the prefetched App Shell; stale < 5 min excluded it. - getCurrentUser: await connection() before Supabase getClaims(), which reads Date.now() to check token expiry. Co-Authored-By: Claude Opus 5.5 --- src/lib/auth.ts | 4 ++++ src/lib/data.ts | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/auth.ts b/src/lib/auth.ts index e736f6c..3796e58 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -1,5 +1,6 @@ import "server-only"; import { cache } from "react"; +import { connection } from "next/server"; import { notFound, redirect } from "next/navigation"; import { isOrganizer } from "@/lib/data"; import { createClient } from "@/lib/supabase/server"; @@ -11,6 +12,9 @@ export type CurrentUser = { id: string; email: string }; export const getCurrentUser = cache(async (): Promise => { if (!isSupabaseConfigured) return null; + // getClaims() reads Date.now() to check token expiry; mark this as + // request-time work so Next doesn't try to prerender it. + await connection(); const supabase = await createClient(); const { data } = await supabase.auth.getClaims(); const claims = data?.claims; diff --git a/src/lib/data.ts b/src/lib/data.ts index 1e08ed3..952621a 100644 --- a/src/lib/data.ts +++ b/src/lib/data.ts @@ -13,8 +13,10 @@ export type ScheduleResult = { events: EventRow[]; error: string | null }; export async function getSchedule(): Promise { "use cache"; cacheTag("events"); - // Organizers edit events in the dashboard; show changes within ~30s. - cacheLife({ stale: 30, revalidate: 30, expire: 3600 }); + // /admin edits call updateTag("events") and show immediately; edits made + // straight in Supabase reach the server within ~30s. stale must stay at + // 5 minutes or more, or the schedule drops out of the prefetched App Shell. + cacheLife({ stale: 300, revalidate: 30, expire: 3600 }); if (!isSupabaseConfigured) return { events: [], error: null };