forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dynamicIO] update prerender cache scoping and cache warming for vali…
…dation (vercel#71822) Updates the heuristic to scoping prerender caches during dev. A cache scope will be created for every request if one does not already exist. If the request is a server action we create a new one. existing caches already expire after 30 seconds (unchanged) This updates the prefetch cache purge to be 5 seconds since so we don't mask short lifetime caches This also adds cache tracking to the first RSC render of the validation render. This means we now need to always do a second render regardless of whether there is a sync abort.
- Loading branch information
Showing
11 changed files
with
306 additions
and
82 deletions.
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
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
9 changes: 9 additions & 0 deletions
9
test/development/app-dir/dynamic-io-dev-cache-scope/app/api/data.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,9 @@ | ||
function delay() { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, 100) | ||
}) | ||
} | ||
export async function fetchData() { | ||
await delay() | ||
return '' + Math.random() | ||
} |
42 changes: 42 additions & 0 deletions
42
test/development/app-dir/dynamic-io-dev-cache-scope/app/cached/page.tsx
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,42 @@ | ||
import { | ||
revalidateTag, | ||
unstable_cacheLife as cacheLife, | ||
unstable_cacheTag, | ||
} from 'next/cache' | ||
import { fetchData } from '../api/data' | ||
// import { Suspense } from 'react' | ||
// import { cookies, headers } from 'next/headers' | ||
|
||
function InnerComponent({ children }) { | ||
return <span id="value">{children}</span> | ||
} | ||
|
||
async function refresh() { | ||
'use server' | ||
revalidateTag('hello') | ||
} | ||
|
||
async function reload() { | ||
'use server' | ||
} | ||
|
||
async function Component() { | ||
'use cache' | ||
cacheLife({ revalidate: 30 }) | ||
unstable_cacheTag('hello') | ||
return <InnerComponent>{await fetchData()}</InnerComponent> | ||
} | ||
|
||
export default async function Home() { | ||
return ( | ||
<> | ||
<form action={refresh}> | ||
<button id="refresh">Refresh</button> | ||
</form> | ||
<form action={reload}> | ||
<button id="reload">Reload</button> | ||
</form> | ||
<Component /> | ||
</> | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
test/development/app-dir/dynamic-io-dev-cache-scope/app/layout.tsx
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,9 @@ | ||
export default function Root({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html> | ||
<body> | ||
<main>{children}</main> | ||
</body> | ||
</html> | ||
) | ||
} |
33 changes: 33 additions & 0 deletions
33
test/development/app-dir/dynamic-io-dev-cache-scope/app/uncached/page.tsx
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,33 @@ | ||
import { fetchData } from '../api/data' | ||
// import { Suspense } from 'react' | ||
// import { cookies, headers } from 'next/headers' | ||
|
||
function InnerComponent({ children }) { | ||
return <span id="value">{children}</span> | ||
} | ||
|
||
async function refresh() { | ||
'use server' | ||
} | ||
|
||
async function reload() { | ||
'use server' | ||
} | ||
|
||
async function Component() { | ||
return <InnerComponent>{await fetchData()}</InnerComponent> | ||
} | ||
|
||
export default async function Home() { | ||
return ( | ||
<> | ||
<form action={refresh}> | ||
<button id="refresh">Refresh</button> | ||
</form> | ||
<form action={reload}> | ||
<button id="reload">Reload</button> | ||
</form> | ||
<Component /> | ||
</> | ||
) | ||
} |
Oops, something went wrong.