Skip to content

Fix: cms revalidate content#24

Open
Aerilym wants to merge 6 commits intomainfrom
fix/cms_static_content
Open

Fix: cms revalidate content#24
Aerilym wants to merge 6 commits intomainfrom
fix/cms_static_content

Conversation

@Aerilym
Copy link
Copy Markdown
Collaborator

@Aerilym Aerilym commented Mar 16, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 16, 2026 22:41
@Aerilym Aerilym changed the title Fix/cms static content Fix: cms revalidate content Mar 16, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts usage with unstable_cache + cache tags in services/cms.ts.
  • Add /api/revalidate webhook handler that revalidates pages and busts data-cache tags.
  • Introduce IS_STATIC_MODE and update getStaticProps revalidation 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.

Comment thread pages/api/revalidate.ts
@@ -0,0 +1,175 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { revalidateTag } from 'next/cache';
import nextConfig from 'next.config';
Comment thread pages/api/revalidate.ts
Comment on lines +10 to +11
const locales: string[] = nextConfig.i18n.locales;
const defaultLocale: string = nextConfig.i18n.defaultLocale;
Comment thread app/api/revalidate/route.ts Outdated

if (slug) {
// The post itself — posts are English-only, no locale-prefixed variants
paths.push(`/${slug}`);
Comment thread services/cms.ts
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 thread services/cms.ts
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 thread pages/api/revalidate.ts Outdated
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.
Comment thread README.md
- 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants