perf: implement ISR caching with tag-based revalidation#602
Merged
codercatdev merged 19 commits intodevfrom Mar 5, 2026
Merged
perf: implement ISR caching with tag-based revalidation#602codercatdev merged 19 commits intodevfrom
codercatdev merged 19 commits intodevfrom
Conversation
- Create sanity/lib/fetch.ts: ISR-compatible sanityFetch with cache tags - Production: uses Sanity CDN + Next.js revalidate + cache tags - Draft mode: bypasses cache, uses token for draft content - Update sanity/lib/live.ts: re-export new sanityFetch, keep SanityLive for drafts - Fix sanity/lib/token.ts: warn instead of throw when token missing - Create /api/webhooks/sanity-revalidate: on-demand cache invalidation - Add generateStaticParams to 13 dynamic routes (posts, podcasts, courses, etc.) - Add revalidate exports to 20 pages (60s listings, 3600s detail, 86400s static) - Add cache tags to all sanityFetch calls across 24 files - Conditionally render SanityLive + VisualEditing only in draft mode Expected impact: - TTFB: 300-800ms → 50-100ms (edge cached) - Sanity API calls: every page view → 1 per revalidation period - Content freshness: 60s for listings, on-demand for detail pages
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Reverts the custom sanityFetch/fetch.ts approach in favor of defineLive's
built-in caching. defineLive automatically:
- Sets cache tags (opaque sanity: prefixed tags)
- Revalidates via SanityLive component listening to Live Content API
- Integrates with ISR so all visitors see fresh content
Changes:
- Revert sanity/lib/live.ts to standard defineLive pattern
- Delete sanity/lib/fetch.ts (not needed)
- SanityLive always renders (required for cache revalidation)
- Remove manual tags from all sanityFetch calls
- Fix generateStaticParams to use client.fetch directly
- Keep revalidate exports as safety net (20 pages)
- Keep generateStaticParams for build-time pre-rendering (13 routes)
- Simplify webhook to revalidateTag("sanity") backup
Courses have been removed from navigation and are no longer active. Route files already deleted. This commit cleans up all remaining references: - queries.ts: remove course/lesson queries, partials, and related content refs - types.ts: remove course/lesson from ContentType enum - more-content.tsx: remove course query case - algolia-search.tsx: remove course/lesson icon cases - layout.tsx: remove courses RSS link - sitemap.ts: remove course/lesson URL generation - user-related.tsx: remove course from related content check - internalLink.ts: remove course from reference types Sanity schemas (course.ts, lesson.ts) kept for Studio access to existing data.
- pro-benefits.tsx: replace course marketing copy with generic content terms - rss.ts: remove dead course case from typePath() - algolia-search.tsx: remove commented-out course initialUiState - sanity.config.ts: remove course/lesson schema imports and registrations - Deleted: sanity/schemas/documents/course.ts, lesson.ts
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.
⚡ Next.js Caching Optimization + Course Removal
Caching: Aligned with next-sanity
defineLiveBest PracticesAfter reading the next-sanity caching docs, we aligned with the recommended
defineLiveapproach:defineLive'ssanityFetchautomatically sets cache tags — opaquesanity:prefixed tags generated by the backend<SanityLive />automatically revalidates — listens to Live Content API and callsrevalidateTag()when content changes<SanityLive />always renders (not behind draft mode) — required for cache revalidationWhat this PR adds:
generateStaticParams— Pre-renders all posts, podcasts, authors, guests, sponsors, pages at build timerevalidateexports — Safety net: 60s for listings, 3600s for detail pages, 86400s for static pages/api/webhooks/sanity-revalidate— callsrevalidateTag("sanity")for when no visitors are activetoken.tsfix — Warns instead of throwing whenSANITY_API_READ_TOKENis missingWhat we intentionally kept as-is:
defineLivepattern insanity/lib/live.ts— handles caching automatically<SanityLive />always rendered in layout — triggers cache revalidation for all visitorssanityFetchcalls —defineLivegenerates themCourse Removal 🧹
Courses have been removed from navigation and are no longer active.
Deleted (13 route files):
app/(main)/(course)/— all pages, lessons, RSS feedsCleaned up references in:
sanity/lib/queries.ts— removed course/lesson queries, partials, related content refslib/types.ts— removed course/lesson from ContentType enumcomponents/more-content.tsx— removed course query casecomponents/algolia-search.tsx— removed course/lesson icon casesapp/(main)/layout.tsx— removed courses RSS linkapp/sitemap.ts— removed course/lesson URL generationcomponents/user-related.tsx— removed course from related contentsanity/schemas/custom/internalLink.ts— removed course from reference typesKept:
sanity/schemas/documents/course.tsandlesson.ts— for Sanity Studio access to existing dataSetup After Merge
SANITY_REVALIDATE_SECRETenv var + Sanity webhook for backup revalidation when no visitors are active