From a8b31a537994572aa426a914d8f0a6a184b63532 Mon Sep 17 00:00:00 2001 From: Leander Furumo Date: Fri, 30 Oct 2026 21:18:07 +0100 Subject: [PATCH] Expire cache tags immediately on webhook revalidation The "max" profile serves stale content once more while revalidating, so the first visit after publishing showed the old version. Co-Authored-By: Claude Opus 5.5 --- src/app/api/revalidate/route.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/app/api/revalidate/route.ts b/src/app/api/revalidate/route.ts index 0c71965..d9404c0 100644 --- a/src/app/api/revalidate/route.ts +++ b/src/app/api/revalidate/route.ts @@ -1,6 +1,10 @@ import { revalidateTag } from "next/cache" import { NextRequest, NextResponse } from "next/server" +// Expire immediately so the first visit after a publish gets fresh content. +// The "max" profile would serve the stale version once more while refetching +const expireTag = (tag: string) => revalidateTag(tag, { expire: 0 }) + export async function POST(request: NextRequest) { const secret = request.nextUrl.searchParams.get("secret") @@ -17,19 +21,19 @@ export async function POST(request: NextRequest) { ) if (_type === "post") { - revalidateTag("blog-posts", "max") + expireTag("blog-posts") if (slug?.current) { - revalidateTag(`post-${slug.current}`, "max") + expireTag(`post-${slug.current}`) } } else if (_type === "event") { - revalidateTag("events", "max") + expireTag("events") if (slug?.current) { - revalidateTag(`event-${slug.current}`, "max") + expireTag(`event-${slug.current}`) } } else if (_type === "author") { - revalidateTag("authors", "max") + expireTag("authors") // Blog posts show the author's name and image - revalidateTag("blog-posts", "max") + expireTag("blog-posts") } return NextResponse.json({