Skip to content

Commit 4119f0c

Browse files
Miriadresearch
andcommitted
fix: scope sanity-revalidate webhook to skip pipeline doc types
The webhook was firing revalidateTag("sanity") on EVERY Sanity document change, including automated pipeline documents (automatedVideo, contentIdea, sponsorLead, etc.) that update frequently via cron jobs. Each webhook call invalidated ALL cached pages simultaneously. Now skips internal/pipeline document types that have no public-facing pages. For public content types, keeps revalidateTag("sanity") as a fallback for when no active visitors trigger SanityLive updates. Skipped types: automatedVideo, contentIdea, sponsorLead, pipeline_config, content_config Co-authored-by: research <research@miriad.systems>
1 parent b302934 commit 4119f0c

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

  • app/api/webhooks/sanity-revalidate

app/api/webhooks/sanity-revalidate/route.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,32 @@ export async function POST(request: NextRequest) {
2323
);
2424
}
2525

26-
// Revalidate all sanity-tagged caches (the "heavy hammer" approach)
27-
// This is a backup for when no visitors are active to trigger SanityLive revalidation
28-
// Next.js 16 requires a second argument — { expire: 0 } for immediate invalidation
29-
revalidateTag("sanity", { expire: 0 });
26+
// With defineLive + <SanityLive />, content pages get real-time updates
27+
// without ISR revalidation. We only keep revalidateTag("sanity") as a
28+
// fallback for when no active visitors are triggering live updates.
29+
//
30+
// IMPORTANT: Skip pipeline/internal document types that don't have
31+
// public-facing pages. These fire frequently (every cron run) and
32+
// were the primary cause of ISR write exhaustion.
33+
const SKIP_TYPES = new Set([
34+
"automatedVideo",
35+
"contentIdea",
36+
"sponsorLead",
37+
"pipeline_config",
38+
"content_config",
39+
]);
40+
41+
if (SKIP_TYPES.has(body._type)) {
42+
return NextResponse.json({
43+
skipped: true,
44+
type: body._type,
45+
reason: "Internal document type — no revalidation needed",
46+
});
47+
}
48+
49+
// For public content types, revalidate the sanity tag as a fallback.
50+
// This only affects pages that still use Next.js cache tags (e.g., sitemap).
51+
revalidateTag("sanity");
3052

3153
return NextResponse.json({
3254
revalidated: true,

0 commit comments

Comments
 (0)