-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add experimental client router cache config (#62856)
This introduces an experimental router flag (`experimental.staleTimes`) to change the router cache behavior. Specifically: ```ts // next.config.js module.exports = { experimental: { staleTimes: { dynamic: <seconds>, static: <seconds>, }, }, }; ``` - `dynamic` is the value that is used when the `prefetch` `Link` prop is left unspecified. (Default 30 seconds) - `static` is the value that is used when the `prefetch` `Link` prop is `true`. (Default 5 minutes) Additional details: - Loading boundaries are considered reusable for the time period indicated by the `static` property (default 5 minutes) - This doesn't disable partial rendering support, **meaning shared layouts won't automatically be refetched every navigation, only the new segment data**. - This also doesn't change back/forward caching behavior to ensure things like scroll restoration etc still work nicely. Please see the original proposal [here](#54075 (comment)) for more information. The primary difference is that this is a global configuration, rather than a per-segment configuration, and it isn't applied to layouts. (We expect this to be a "stop-gap" and not the final router caching solution) Closes NEXT-2703
- Loading branch information
Showing
12 changed files
with
461 additions
and
86 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
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
21 changes: 21 additions & 0 deletions
21
test/e2e/app-dir/app-client-cache/app/without-loading/[id]/page.js
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,21 @@ | ||
import Link from 'next/link' | ||
|
||
export default async function Page({ searchParams: { timeout } }) { | ||
const randomNumber = await new Promise((resolve) => { | ||
setTimeout( | ||
() => { | ||
resolve(Math.random()) | ||
}, | ||
timeout !== undefined ? Number.parseInt(timeout, 10) : 0 | ||
) | ||
}) | ||
|
||
return ( | ||
<> | ||
<div> | ||
<Link href="/without-loading">Back to Home</Link> | ||
</div> | ||
<div id="random-number">{randomNumber}</div> | ||
</> | ||
) | ||
} |
36 changes: 36 additions & 0 deletions
36
test/e2e/app-dir/app-client-cache/app/without-loading/page.js
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,36 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Page() { | ||
return ( | ||
<> | ||
<div> | ||
<Link href="/without-loading/0?timeout=0" prefetch={true}> | ||
To Random Number - prefetch: true | ||
</Link> | ||
</div> | ||
<div> | ||
<Link href="/without-loading/0?timeout=1000" prefetch={true}> | ||
To Random Number - prefetch: true, slow | ||
</Link> | ||
</div> | ||
<div> | ||
<Link href="/without-loading/1">To Random Number - prefetch: auto</Link> | ||
</div> | ||
<div> | ||
<Link href="/without-loading/2" prefetch={false}> | ||
To Random Number 2 - prefetch: false | ||
</Link> | ||
</div> | ||
<div> | ||
<Link href="/without-loading/2?timeout=1000" prefetch={false}> | ||
To Random Number 2 - prefetch: false, slow | ||
</Link> | ||
</div> | ||
<div> | ||
<Link href="/without-loading/1?timeout=1000"> | ||
To Random Number - prefetch: auto, slow | ||
</Link> | ||
</div> | ||
</> | ||
) | ||
} |
Oops, something went wrong.