今日已更新 215 条资讯 | 累计 25765 条内容
关于我们

标签:#sitemap

找到 1 篇相关文章

开发者

Next.js Sitemap Not Updating? Here's the Real Fix

Next.js Sitemap Not Updating? Here's the Real Fix If your Next.js sitemap is not updating after you publish new content, you're dealing with a cache-coherence bug that almost nobody writes up. It has an exact symptom, a reproducible root cause, and a one-line fix. This is the guide you'll wish you had the moment you notice /sitemap.xml serving fewer entries than your real site. The symptom: your sitemap lags behind your published content The mismatch is impossible to miss once you look. On our own site, /lab lists 11 published posts, yet /sitemap.xml shows only 7. Same database, same deploy, two different answers. If that gap sounds familiar, you're in the right place. You might have checked your afterChange hook, verified that revalidateTag('posts') fires, and even confirmed that the tagged data refreshes — only to find the sitemap still frozen. That's because the problem lives between two cache layers, not inside the data fetch. Why revalidateTag doesn't fix a stale Next.js sitemap The answer lies in what sitemap.ts actually is. According to the Next.js Metadata Files: sitemap.xml documentation, it's a special Route Handler. And like any Route Handler, Next.js caches its rendered output by default. Here's what happened in our own repository (this bug is documented in a comment at the top of app/(frontend)/sitemap.ts because it cost real indexation time): We read content from Payload using unstable_cache , tagged with the collection slug posts . An afterChange hook called revalidateTag('posts') whenever a post was published. That call did work — it invalidated the inner unstable_cache data entry. But the route's statically-rendered outer XML output was never re-run. The frozen route output kept serving the old XML built from the old data, long after the inner cache was refreshed. Two cache layers. Tag-based revalidation busted the inner one, but the outer route handler cache was never told to re-execute. That's the missing piece. The one-line fix: route-level ISR o

2026-07-30 原文 →