Next.js sitemap contains preview addresses instead of production domain
Sitemap XML works, but its loc elements indicate the temporary domain of deploya Vercel. Addresses in sitemap were built from an unstable variable VERCEL URL instead of from the public canonical domain.
How to identify the source of the problem
Open a production sitemap and check the prefix of several random loc items. Compare the address design in app/sitemap.ts with the canonical domain set in metadataBase.
Compare the message from the console with the result of the production compilation and the condition after the page has been refreshed.
Repair steps
Use the open canonical production domain in the map generator and build the absolute URL of all important sites. Separate the preview environment map from production if you publish previews indexed only for your own needs.
How to Test Solution
Sitemap contains the addresses of the appropriate HTTPS host, and their canonical indicates the same host.
Security and restrictions
Do not enter in the sitemap every short-term preview domain, because this makes it difficult to consolidate the URL.