Next.js sitemap cache bug causes stale XML; one-line fix resolves it
A cache-coherence bug in Next.js can cause sitemap.xml to display fewer entries than actually exist on a site, even after new content is published. The issue stems from two separate cache layers: tag-based revalidation clears the inner data cache but leaves the outer route handler cache serving outdated XML. Because Next.js treats sitemap.ts as a Route Handler and caches its rendered output by default, the sitemap never re-executes after a content update. Adding a single export — 'export const revalidate = 3600' — enables Incremental Static Regeneration at the route level, forcing the sitemap to re-render on a set interval. Once route-level revalidation is in place, the inner unstable_cache wrapper becomes redundant and can be removed to simplify the data-fetching logic.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in