-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix revalidation issue with route handlers (#63213)
### What When a route handler uses an API that opts it into dynamic rendering (such as `no-store` on a fetch), and also specifies a `revalidate` time, the `revalidate` time is ignored and route is treated as fully static. ### Why `revalidate: 0` and `revalidate: false` have different semantic meanings: `false` essentially means cache forever, whereas `0` means it's dynamic. Since `0` is also falsey, the code we have to fallback with a default `revalidate` value for route handlers is incorrectly not marking the route as dynamic, and as a result, caching the route without an expiration time. ### How This updates the fallback handling for app routes respect a revalidation value of `0`, so that the page can properly be marked dynamic. ### Test Explanation This adds 2 new routes handlers: both have a revalidation time specified & use `no-store` on a fetch, but only one of them specifies `export const dynamic = 'force-static'`. The one that doesn't specify `force-static` is correctly omitted from the prerender manifest. The one that is `force-static` is correctly in the prerender manifest with the right expiration time. An additional test case was added to verify that this data refreshes after the specified interval. Closes NEXT-2764
- Loading branch information
Showing
4 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
test/e2e/app-dir/app-static/app/route-handler/no-store-force-static/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const dynamic = 'force-static' | ||
export const revalidate = 3 | ||
|
||
export async function GET() { | ||
const data = await fetch( | ||
'https://next-data-api-endpoint.vercel.app/api/random', | ||
{ cache: 'no-store' } | ||
).then((res) => res.text()) | ||
|
||
return Response.json({ now: Date.now(), data }) | ||
} |
10 changes: 10 additions & 0 deletions
10
test/e2e/app-dir/app-static/app/route-handler/no-store/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const revalidate = 5 | ||
|
||
export async function GET() { | ||
const data = await fetch( | ||
'https://next-data-api-endpoint.vercel.app/api/random', | ||
{ cache: 'no-store' } | ||
).then((res) => res.text()) | ||
|
||
return Response.json({ now: Date.now(), data }) | ||
} |