You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clarifies that static vs dynamic resources now influence the static /
dynamic staleTime that is used which should hopefully be more intuitive.
Reference PR:
- #67868
Also updates the JSDoc for `<Link />` since it was fairly out of date
and lacking any info about app router behavior.
---------
Co-authored-by: Delba de Oliveira <[email protected]>
Copy file name to clipboardExpand all lines: docs/02-app/01-building-your-application/04-caching/index.mdx
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -363,13 +363,13 @@ This results in an improved navigation experience for the user:
363
363
The cache is stored in the browser's temporary memory. Two factors determine how long the router cache lasts:
364
364
365
365
-**Session**: The cache persists across navigation. However, it's cleared on page refresh.
366
-
-**Automatic Invalidation Period**: The cache of an individual segment is automatically invalidated after a specific time. The duration depends on how the resource was [prefetched](/docs/app/api-reference/components/link#prefetch):
367
-
-**Default Prefetching** (`prefetch={null}` or unspecified): 30 seconds
368
-
-**Full Prefetching**: (`prefetch={true}` or `router.prefetch`): 5 minutes
366
+
-**Automatic Invalidation Period**: The cache of layouts and loading states is automatically invalidated after a specific time. The duration depends on how the resource was [prefetched](/docs/app/api-reference/components/link#prefetch), and if the resource was [statically generated](/docs/app/building-your-application/rendering/server-components#static-rendering-default):
367
+
-**Default Prefetching** (`prefetch={null}` or unspecified): not cached for dynamic pages, 5 minutes for static pages.
368
+
-**Full Prefetching** (`prefetch={true}` or `router.prefetch`): 5 minutes for both static & dynamic pages.
369
369
370
370
While a page refresh will clear **all** cached segments, the automatic invalidation period only affects the individual segment from the time it was prefetched.
371
371
372
-
> **Note**: There is [experimental support](/docs/app/api-reference/next-config-js/staleTimes)for configuring these values as of v14.2.0-canary.53.
372
+
> **Good to know**: The experimental [`staleTimes`](/docs/app/api-reference/next-config-js/staleTimes)config option can be used to adjust the automatic invalidation times mentioned above.
Copy file name to clipboardExpand all lines: docs/02-app/02-api-reference/05-next-config-js/staleTimes.mdx
+12-7Lines changed: 12 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,16 +27,21 @@ module.exports = nextConfig
27
27
28
28
The `static` and `dynamic` properties correspond with the time period (in seconds) based on different types of [link prefetching](/docs/app/api-reference/components/link#prefetch).
29
29
30
-
- The `dynamic` property is used when the `prefetch` prop on `Link` is left unspecified.
31
-
- Default: 30 seconds
32
-
- The `static` property is used when the `prefetch` prop on `Link` is set to `true`, or when calling [`router.prefetch`](/docs/app/building-your-application/caching#routerprefetch).
30
+
- The `dynamic` property is used when the page is neither statically generated nor fully prefetched (i.e., with prefetch={true}).
31
+
- Default: 0 seconds (not cached)
32
+
- The `static` property is used for statically generated pages, or when the `prefetch` prop on `Link` is set to `true`, or when calling [`router.prefetch`](/docs/app/building-your-application/caching#routerprefetch).
33
33
- Default: 5 minutes
34
34
35
35
> **Good to know:**
36
36
>
37
37
> -[Loading boundaries](/docs/app/api-reference/file-conventions/loading) are considered reusable for the `static` period defined in this configuration.
38
-
> - This doesn't disable [partial rendering support](/docs/app/building-your-application/routing/linking-and-navigating#4-partial-rendering), **meaning shared layouts won't automatically be refetched every navigation, only the new segment data.**
39
-
> - This doesn't change [back/forward caching](/docs/app/building-your-application/caching#router-cache) behavior to prevent layout shift & to prevent losing the browser scroll position.
40
-
> - The different properties of this config refer to variable levels of "liveness" and are unrelated to whether the segment itself is opting into static or dynamic rendering. In other words, the current `static` default of 5 minutes suggests that data feels static by virtue of it being revalidated infrequently.
38
+
> - This doesn't affect [partial rendering](/docs/app/building-your-application/routing/linking-and-navigating#4-partial-rendering), **meaning shared layouts won't automatically be refetched on every navigation, only the page segment that changes.**
39
+
> - This doesn't change [back/forward caching](/docs/app/building-your-application/caching#client-side-router-cache) behavior to prevent layout shift and to prevent losing the browser scroll position.
41
40
42
-
You can learn more about the Client Router Cache [here](/docs/app/building-your-application/caching#router-cache).
41
+
You can learn more about the Client Router Cache [here](/docs/app/building-your-application/caching#client-side-router-cache).
Copy file name to clipboardExpand all lines: packages/next/src/client/link.tsx
+13-5Lines changed: 13 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,7 @@ type InternalLinkProps = {
57
57
*/
58
58
scroll?: boolean
59
59
/**
60
-
* Update the path of the current page without rerunning [`getStaticProps`](/docs/pages/building-your-application/data-fetching/get-static-props), [`getServerSideProps`](/docs/pages/building-your-application/data-fetching/get-server-side-props) or [`getInitialProps`](/docs/pages/api-reference/functions/get-initial-props).
60
+
* Update the path of the current page without rerunning [`getStaticProps`](https://nextjs.org/docs/pages/building-your-application/data-fetching/get-static-props), [`getServerSideProps`](https://nextjs.org/docs/pages/building-your-application/data-fetching/get-server-side-props) or [`getInitialProps`](/docs/pages/api-reference/functions/get-initial-props).
61
61
*
62
62
* @defaultValue `false`
63
63
*/
@@ -70,12 +70,20 @@ type InternalLinkProps = {
70
70
passHref?: boolean
71
71
/**
72
72
* Prefetch the page in the background.
73
-
* Any `<Link />` that is in the viewport (initially or through scroll) will be preloaded.
74
-
* Prefetch can be disabled by passing `prefetch={false}`. When `prefetch` is set to `false`, prefetching will still occur on hover in pages router but not in app router. Pages using [Static Generation](/docs/basic-features/data-fetching/get-static-props.md) will preload `JSON` files with the data for faster page transitions. Prefetching is only enabled in production.
73
+
* Any `<Link />` that is in the viewport (initially or through scroll) will be prefetched.
74
+
* Prefetch can be disabled by passing `prefetch={false}`. Prefetching is only enabled in production.
75
75
*
76
-
* @defaultValue `true`
76
+
* In App Router:
77
+
* - `null` (default): For statically generated pages, this will prefetch the full React Server Component data. For dynamic pages, this will prefetch up to the nearest route segment with a [`loading.js`](https://nextjs.org/docs/app/api-reference/file-conventions/loading) file. If there is no loading file, it will not fetch the full tree to avoid fetching too much data.
78
+
* - `true`: This will prefetch the full React Server Component data for all route segments, regardless of whether they contain a segment with `loading.js`.
79
+
* - `false`: This will not prefetch any data, even on hover.
80
+
*
81
+
* In Pages Router:
82
+
* - `true` (default): The full route & its data will be prefetched.
83
+
* - `false`: Prefetching will not happen when entering the viewport, but will still happen on hover.
84
+
* @defaultValue `true` (pages router) or `null` (app router)
77
85
*/
78
-
prefetch?: boolean
86
+
prefetch?: boolean|null
79
87
/**
80
88
* The active locale is automatically prepended. `locale` allows for providing a different locale.
81
89
* When `false` `href` has to include the locale as the default behavior is disabled.
0 commit comments