Conversation
There was a problem hiding this comment.
Pull request overview
This PR shifts Contentful data fetching from a custom in-memory cache to Next.js cache primitives, and introduces webhook-driven on-demand revalidation with an optional “fully static” mode.
Changes:
- Replace
services/cache.tsusage withunstable_cache+ cache tags inservices/cms.ts. - Add
/api/revalidatewebhook handler that revalidates pages and busts data-cache tags. - Introduce
IS_STATIC_MODEand updategetStaticPropsrevalidation behavior across pages; update ISR intervals and docs.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| services/cms.ts | Migrates Contentful fetches to unstable_cache, adds cache tags, and adjusts fetch behavior. |
| services/cache.ts | Removes the custom in-memory cache implementation. |
| pages/api/revalidate.ts | Adds Contentful webhook endpoint for on-demand revalidation and cache-tag invalidation. |
| constants/cms.ts | Adds IS_STATIC_MODE and changes default revalidate intervals. |
| constants/index.ts | Re-exports IS_STATIC_MODE. |
| pages/[slug].tsx | Disables time-based ISR in static mode and tweaks revalidation logging. |
| pages/tag/[tag].tsx | Disables time-based ISR in static mode. |
| pages/faq.tsx | Disables time-based ISR in static mode. |
| pages/blog/index.tsx | Moves RSS generation here and updates revalidation behavior. |
| pages/index.tsx | Removes RSS generation and ISR revalidate setting. |
| next.config.js | Exposes additional env vars (including webhook/static-mode settings). |
| README.md | Documents Contentful webhook setup and revalidation behavior. |
| .env.example | Adds WEBHOOK_SECRET and FORCE_STATIC examples. |
| lib/app_localization | Updates submodule pointer. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,175 @@ | |||
| import type { NextApiRequest, NextApiResponse } from 'next'; | |||
| import { revalidateTag } from 'next/cache'; | |||
| import nextConfig from 'next.config'; | |||
Comment on lines
+10
to
+11
| const locales: string[] = nextConfig.i18n.locales; | ||
| const defaultLocale: string = nextConfig.i18n.defaultLocale; |
|
|
||
| if (slug) { | ||
| // The post itself — posts are English-only, no locale-prefixed variants | ||
| paths.push(`/${slug}`); |
Comment on lines
+128
to
+136
| if (_entries.items.length === 0) { | ||
| throw new Error(`Failed to fetch entries for ${tag}`); | ||
| } | ||
| } | ||
|
|
||
| // Check if we have pages cached | ||
| const allPagesKey = 'all_pages'; | ||
| const cachedPages = blogCache.get<IPage[]>(allPagesKey); | ||
|
|
||
| if (cachedPages) { | ||
| const found = cachedPages.some(page => page.slug === slug); | ||
| if (found) { | ||
| return true; | ||
|
|
||
| const results = await generateEntries(_entries, 'post', taglist); | ||
| return { | ||
| entries: results.entries as Array<IPost>, | ||
| total: results.total, | ||
| }; |
Comment on lines
+97
to
+101
| const remainingPages = Array.from({ length: totalPages - 1 }, (_, i) => i + 2); | ||
| const batches = await Promise.all( | ||
| remainingPages.map((page) => fetchBlogEntries(CONTENTFUL_PAGE_SIZE, page)) | ||
| ); | ||
| for (const { entries } of batches) { |
Comment on lines
+142
to
+144
| } | ||
| // For page unpublish/delete without a slug, the data cache tag has already been busted | ||
| // above. Next requests will fetch fresh data; we can't target a specific path without the slug. |
| - Bust the relevant Next.js data cache tag so subsequent requests fetch fresh content. | ||
| - Revalidate listing pages (blog index, faq) so removed content disappears from lists. | ||
| - For posts: the post's own page at `/${slug}` will naturally return 404 on the next visit because it's no longer in Contentful. ISR handles this via `notFound: true` in `getStaticProps`. | ||
| - For pages: without a slug, the specific page path cannot be targeted. The stale page will persist until the next visitor triggers a background regeneration (which will then 404 it). |
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.
No description provided.