-
Notifications
You must be signed in to change notification settings - Fork 26.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Route handler always returns X-Vercel-Cache: STALE
#65814
Comments
This behavior is changing with Next.js 15 (where Would you might updating to the latest https://nextjs.org/blog/next-15-rc and retesting? |
Hey @leerob, thanks for you answer. What if I want to cache GET request? In my case I have a hCMS with next14.2.3. The flow is I generate dynamic slug pages at build time, all requests are marked with a tag "CMS-content". And then call revalidateTag to make sure all the pages have a up to date content. In 99% of cases it works as expected, but in 1% updated pages return X-Vercel-Cache: STALE and never changes. In order to see updates I have to rebuild the project or purge cache. Maybe you could point me to where the problem could be, since generały it works correct. ❤️🫂 |
Upgraded, but seeing the exact same behavior: joostmeijles/route-handler-stale#1 |
For clarity,
Source: https://vercel.com/docs/edge-network/headers#x-vercel-cache Are you wanting to disable the ability to use ISR entirely here? (which is where the background revalidation functionality is coming from). |
I want to get the same behavior as for a page based route segment. So only perform the background request when used data changes / is revalidated (for simplicity I left this out of the example). An example with a page based route segment can be found here: visiting https://routehandler-stale.vercel.app/items-page/a returns a HIT iso STALE (code: https://github.com/joostmeijles/route-handler-stale/blob/main/app/items-page/%5Bslug%5D/page.tsx). So I would expect that https://github.com/joostmeijles/route-handler-stale/blob/main/app/items/%5Bslug%5D/route.ts results always in HIT (and not STALE) for subsequent requests (when the used data did not change). |
Can you make the deployment link public so I can view it myself? It's currently private. |
https://routehandler-stale.vercel.app/items-page/a is public. Which link do you mean? |
Exactly. That’s the expected behavior as there is no stale data to revalidate. For https://routehandler-stale.vercel.app/items/a I would expect the same as there is nothing to revalidate as well. |
It's using ISR for the dynamic route segments.
|
I want the route response to be generated at runtime and then cached. Other routes should result in a 404.
When visiting https://routehandler-stale.vercel.app/items/a I expect as
|
Got it. As mentioned above, you're then looking for:
https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams |
That works locally, but results in a 404 on Vercel: https://routehandler-stale.vercel.app/items-dynamicparams/a |
That is correct, because they weren't in export async function GET(
request: Request,
{ params }: { params: { slug: string } }
) {
let slug = params.slug;
let res = await fetch(`http://example/{slug}`, next: { tags: `mytag-${slug}`});
return NextResponse.json({ slug });
}
export async function generateStaticParams() {
return ['a', 'b', 'c'];
} |
The possible Please note that specifying slug values when using |
If the values are not possible to be known at build time, then there is no way to statically prerender those files. The behavior you are describing for the page should be the same for the route handler. A route handler is basically the lowest level abstraction of a page, which is why they have the same route segment configuration options. The behavior you are describing where the first visit generates the page, and then the result is cached on the Vercel CDN for subsequent requests, is how both pages and route handlers work. If you are wanting to extend the revalidation period, so you are able to serve cached files longer, you can use the export const revalidate = 3600; |
The issue is that the behaviour of Pages handler (
|
Possible duplicate of #62195 |
Looks largely the same, but this issue is Note that the provided solution (by #62195 (comment)) to set |
@leerob I strongly believe this is not solved and is a bug. Can you please have a look at my clarification in #65814 (comment)? |
Running the examples in Running https://github.com/joostmeijles/route-handler-stale/blob/main/app/items/%5Bslug%5D/route.ts gives:
Running https://github.com/joostmeijles/route-handler-stale/blob/main/app/items-page/%5Bslug%5D/page.tsx gives:
In addition, when running the examples locally the returned |
@joostmeijles Taking a look! |
@joostmeijles I'm not sure if When I use |
@samcx tried with See https://github.com/joostmeijles/route-handler-stale/blob/main/app/items-force-static/%5Bslug%5D/route.ts and https://routehandler-stale.vercel.app/items-force-static/a Please note that I see also |
@joostmeijles Hmm seeing a few Also, are you always seeing |
Always seeing |
Correction: |
@joostmeijles Thanks for confirming. Will be looking to see why we're getting |
@samcx do you have an update on the progress? |
Link to the code that reproduces this issue
https://github.com/joostmeijles/route-handler-stale/tree/main
Route handler example: https://github.com/joostmeijles/route-handler-stale/blob/main/app/items/%5Bslug%5D/route.ts
To Reproduce
x-nextjs-cache: MISS
x-nextjs-cache: HIT
X-Vercel-Cache: STALE
Current vs. Expected behavior
Currently always
X-Vercel-Cache: STALE
is returned.Expected is
X-Vercel-Cache: MISS
on first visit andX-Vercel-Cache: HIT
for subsequent visits.Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.2.0: Fri Nov 11 02:04:44 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T8103 Available memory (MB): 8192 Available CPU cores: 8 Binaries: Node: 20.12.2 npm: 10.5.0 Yarn: N/A pnpm: 8.15.7 Relevant Packages: next: 14.3.0-canary.63 // Latest available version is detected (14.3.0-canary.63). eslint-config-next: N/A react: 19.0.0-beta-4508873393-20240430 react-dom: 19.0.0-beta-4508873393-20240430 typescript: 5.1.3 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
App Router
Which stage(s) are affected? (Select all that apply)
Vercel (Deployed)
Additional context
No response
The text was updated successfully, but these errors were encountered: