#fetch memorization issue on vercel, nextjs 16.0.3
1 messages · Page 1 of 1 (latest)
Based on the knowledge sources, I can address both issues you're experiencing after upgrading to Next.js 16:
1. Meta tags appearing in <body> instead of <head>
This is actually intentional behavior introduced in Next.js 15.2+. According to the Metadata adding in body issue, Next.js now streams metadata into the <body> for regular visitors to improve page load performance. However, for bots (which expect metadata in the <head>), Next.js delays rendering until metadata is available so it appears in the <head>.
Workaround: If you need metadata to always appear in the <head>, add this to your next.config.ts:
htmlLimitedBots: /.*/
This configuration treats all user agents as "limited bots," forcing metadata to render in the <head>. Multiple users confirmed this works in the Metadata renders inside <body> instead of <head> discussion.
More details: Streaming Metadata documentation
2. API calls not being memoized
The knowledge sources don't contain specific information about fetch memoization issues in Next.js 16.0.3. However, there is a related issue about 'use cache' being ignored in dynamic routes in Next.js 16, where users report caching not working as expected on Vercel deployments.
One important change to note: In Next.js 15+, fetch requests are no longer cached by default. To cache specific requests, you need to explicitly add:
const data = await fetch('<https://...',> { cache: 'force-cache' })
Or use the segment config option to opt all fetches into caching:
export const fetchCache = 'default-cache'
If you're experiencing issues beyond this default behavior change, the knowledge sources don't contain enough specific information about fetch memoization problems in Next.js 16.0.3 to provide a definitive solution.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@sage falcon Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@ivory pilot I add force cache and try on development and next build with pnpm start, as I check the log it got cache hit. but on vercel I call the api function 9 times, in backend also call 9 times. its not memoized at all
Let me check the knowledge base for you again. Give me one moment! :books:
Based on the knowledge sources, this is a known issue with caching behavior differences between local development and Vercel deployments in Next.js. Here's what's happening:
The Problem
Your fetch requests are being cached locally (with force-cache) but not on Vercel. This is a documented behavior difference, not a bug. According to the 'use cache' directive not working on Vercel production issue, there's a fundamental difference in how caching works on Vercel:
"On Vercel however Next.js is deployed in a serverless context and sharing memory has some complications. Storing the cache entries remotely is possible but this has a cost both in dollars, but also in latency... So by default Vercel's dynamic 'use cache' handler is forgetful. It essentially never actually stores the result so it's a miss every time."
Solutions
1. Set CDN Cache Headers
According to the Inconsistency between Local and Vercel related to Cache Data issue, you may need to set cache control headers:
// Set CDN-Cache-Control and/or Vercel-CDN-Cache-Control headers
One user reported: "For those who have a similar problem, you may need to set CDN-Cache-Control and/or Vercel-CDN-Cache-Control."
2. Use fetch with Tags for Revalidation
From the Vercel guide on sharing cache across deployments:
const res = await fetch('<https://api.vercel.app/blog',> {
next: { tags: ['blogs'] }
});
This uses Vercel's Data Cache, which persists across deployments.
3. Check Environment Variables
According to the Vercel deployment using filesystem cache handler issue, the problem might be missing environment variables. The build pipeline needs SUSPENSE_CACHE_URL, SUSPENSE_CACHE_ENDPOINT, and SUSPENSE_CACHE_AUTH_TOKEN to use Vercel's Data Cache properly.
4. Verify Cache Lifetime
From the PPR "use cache" functions not working issue, if you're using cacheLife or revalidation times less than 5 minutes (300 seconds), Vercel treats them as dynamic and doesn't cache them.