Skip to content

cherry-pick sitemap route handler → main - #1484

Merged
Flotapponnier merged 1 commit into
mainfrom
cherry/sitemap-route-handler-main
Jul 26, 2026
Merged

cherry-pick sitemap route handler → main#1484
Flotapponnier merged 1 commit into
mainfrom
cherry/sitemap-route-handler-main

Conversation

@Flotapponnier

Copy link
Copy Markdown
Collaborator

Cherry-pick of #1483 (dev). Fixes the sitemap Cache-Control that #1474 couldn't hit via next.config headers() — route.ts handler now sets the header directly via Response.

Next Metadata routes ignore next.config.ts headers() — the previous
sitemap.ts left Next in charge of the response headers and hard-coded
Cache-Control: public, max-age=0, must-revalidate on force-dynamic
sitemaps. Every crawler hit re-ran the full loader chain (x-vercel-cache:
MISS observed on prod 2026-07-26 after PR #1473 landed the config-level
attempt). Confirmed by curl: my next.config /sitemap.xml rule was
silently dropped.

Move the builder logic to src/lib/sitemap-builder.ts and add a
Route Handler at src/app/sitemap.xml/route.ts that returns a raw
Response with:
  Content-Type: application/xml
  Cache-Control: public, s-maxage=3600, stale-while-revalidate=86400

Same builder logic, same buildFullSitemap + buildStaticFallback,
just serialized to XML in the route and shipped with a real edge
cache header. Also drop the now-redundant /sitemap.xml rule from
next.config headers().

Co-authored-by: Florent Tapponnier <contact@mobula.io>
@Flotapponnier
Flotapponnier merged commit a0ed300 into main Jul 26, 2026
1 check failed
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.

1 participant