Unverified Commit 3452ebbc authored by Joseph's avatar Joseph Committed by GitHub

Remove unstable_ prefix from navigation() and prefetch() (#99241)

Remove unstable_ prefixes from navigation and prefetch in the entire
codebase.


[NAR-932](https://linear.app/vercel/issue/NAR-932/remove-prefixes-from-unstable-navigation-unstable-prefetch)
parent 72003a79
...@@ -725,8 +725,8 @@ impl ReactServerComponentValidator { ...@@ -725,8 +725,8 @@ impl ReactServerComponentValidator {
"unstable_cacheLife", "unstable_cacheLife",
"cacheTag", "cacheTag",
"unstable_cacheTag", "unstable_cacheTag",
"unstable_navigation", "navigation",
"unstable_prefetch", "prefetch",
// "unstable_noStore" // no-op in client, but allowed for legacy reasons // "unstable_noStore" // no-op in client, but allowed for legacy reasons
], ],
), ),
......
import { unstable_prefetch } from 'next/cache' import { navigation } from 'next/cache'
export async function test() { export async function test() {
await unstable_prefetch() await navigation()
return null return null
} }
import { unstable_prefetch } from 'next/cache'; import { navigation } from 'next/cache';
export async function test() { export async function test() {
await unstable_prefetch(); await navigation();
return null; return null;
} }
x You're importing a module that depends on "navigation" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with "use client",
| so this module is also a Client Component.
| Learn more: https://nextjs.org/docs/app/building-your-application/rendering
|
|
,-[input.js:1:1]
1 | import { navigation } from 'next/cache'
: ^^^^^^^^^^
`----
import { unstable_prefetch } from 'next/cache' import { prefetch } from 'next/cache'
export async function test() { export async function test() {
await unstable_prefetch() await prefetch()
return null return null
} }
import { unstable_prefetch } from 'next/cache'; import { prefetch } from 'next/cache';
export async function test() { export async function test() {
await unstable_prefetch(); await prefetch();
return null; return null;
} }
x You're importing a module that depends on "prefetch" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with "use client", so
| this module is also a Client Component.
| Learn more: https://nextjs.org/docs/app/building-your-application/rendering
|
|
,-[input.js:1:1]
1 | import { prefetch } from 'next/cache'
: ^^^^^^^^
`----
x You're importing a module that depends on "unstable_navigation" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with "use
| client", so this module is also a Client Component.
| Learn more: https://nextjs.org/docs/app/building-your-application/rendering
|
|
,-[input.js:1:1]
1 | import { unstable_navigation } from 'next/cache'
: ^^^^^^^^^^^^^^^^^^^
`----
x You're importing a module that depends on "unstable_prefetch" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with "use
| client", so this module is also a Client Component.
| Learn more: https://nextjs.org/docs/app/building-your-application/rendering
|
|
,-[input.js:1:1]
1 | import { unstable_prefetch } from 'next/cache'
: ^^^^^^^^^^^^^^^^^
`----
import { unstable_navigation } from 'next/cache' import { navigation } from 'next/cache'
export async function test() { export async function test() {
await unstable_navigation() await navigation()
return null return null
} }
import { unstable_navigation } from 'next/cache'; import { navigation } from 'next/cache';
export async function test() { export async function test() {
await unstable_navigation(); await navigation();
return null; return null;
} }
x You're importing a module that depends on "unstable_prefetch". This API is only available in Server Components in the App Router, but you are using it in the Pages Router. x You're importing a module that depends on "navigation". This API is only available in Server Components in the App Router, but you are using it in the Pages Router.
| Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components | Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
| |
| |
,-[input.js:1:1] ,-[input.js:1:1]
1 | import { unstable_prefetch } from 'next/cache' 1 | import { navigation } from 'next/cache'
: ^^^^^^^^^^^^^^^^^ : ^^^^^^^^^^
`---- `----
import { unstable_navigation } from 'next/cache' import { prefetch } from 'next/cache'
export async function test() { export async function test() {
await unstable_navigation() await prefetch()
return null return null
} }
import { unstable_navigation } from 'next/cache'; import { prefetch } from 'next/cache';
export async function test() { export async function test() {
await unstable_navigation(); await prefetch();
return null; return null;
} }
x You're importing a module that depends on "unstable_navigation". This API is only available in Server Components in the App Router, but you are using it in the Pages Router. x You're importing a module that depends on "prefetch". This API is only available in Server Components in the App Router, but you are using it in the Pages Router.
| Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components | Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
| |
| |
,-[input.js:1:1] ,-[input.js:1:1]
1 | import { unstable_navigation } from 'next/cache' 1 | import { prefetch } from 'next/cache'
: ^^^^^^^^^^^^^^^^^^^ : ^^^^^^^^
`---- `----
...@@ -345,6 +345,8 @@ Each card is clickable and opens a page with patterns, code samples, and trade-o ...@@ -345,6 +345,8 @@ Each card is clickable and opens a page with patterns, code samples, and trade-o
} }
``` ```
> **Good to know**: If the page or layout already calls [`prefetch()`](/docs/app/api-reference/functions/prefetch), import it under another name, for example `import { prefetch as prefetchStage } from 'next/cache'`, so it doesn't collide with the `prefetch` export.
2. Deploy the change. Links to the adopted destination load the App Shell, and the insight keeps surfacing for the destinations you haven't reached. 2. Deploy the change. Links to the adopted destination load the App Shell, and the insight keeps surfacing for the destinations you haven't reached.
3. Repeat until every destination in scope is adopted, then [enable the flag](#enable-partial-prefetching). 3. Repeat until every destination in scope is adopted, then [enable the flag](#enable-partial-prefetching).
......
...@@ -198,15 +198,15 @@ Everything inside the scope shares the same lifetime. Colocate `"use cache: priv ...@@ -198,15 +198,15 @@ Everything inside the scope shares the same lifetime. Colocate `"use cache: priv
Optimizing a prefetch also means excluding content from it. Some subtrees are expensive enough to produce that you would rather not pay for them on every prefetch of the route. Optimizing a prefetch also means excluding content from it. Some subtrees are expensive enough to produce that you would rather not pay for them on every prefetch of the route.
Awaiting [`unstable_navigation()`](/docs/app/api-reference/functions/navigation) above the work leaves it out of every prefetch, so it is produced on the navigation. The nearest [`<Suspense>`](https://react.dev/reference/react/Suspense) fallback is what the user sees while it streams in. Take the dashboard again, where a ranking keyed on the session is too expensive to produce for every link into the route: Awaiting [`navigation()`](/docs/app/api-reference/functions/navigation) above the work leaves it out of every prefetch, so it is produced on the navigation. The nearest [`<Suspense>`](https://react.dev/reference/react/Suspense) fallback is what the user sees while it streams in. Take the dashboard again, where a ranking keyed on the session is too expensive to produce for every link into the route:
```tsx filename="app/dashboard/recommendations.tsx" highlight={6} ```tsx filename="app/dashboard/recommendations.tsx" highlight={6}
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
import { unstable_navigation } from 'next/cache' import { navigation } from 'next/cache'
async function Recommendations() { async function Recommendations() {
const session = (await cookies()).get('session')?.value const session = (await cookies()).get('session')?.value
await unstable_navigation() await navigation()
const items = await rank(session) const items = await rank(session)
return <List items={items} /> return <List items={items} />
} }
...@@ -217,13 +217,13 @@ async function rank(session?: string) { ...@@ -217,13 +217,13 @@ async function rank(session?: string) {
} }
``` ```
The session is read above `unstable_navigation()`, so it resolves in the shell like any other session data. Only the ranking is left out, and it keeps its cache lifetime. The session is read above `navigation()`, so it resolves in the shell like any other session data. Only the ranking is left out, and it keeps its cache lifetime.
Without it, keeping a subtree out of a prefetch means leaving it uncached, which gives up that lifetime on the navigation too. Awaiting `unstable_navigation()` inside a cached scope is not allowed, so put the caching directive on a function called below it, as `rank` does here. Without it, keeping a subtree out of a prefetch means leaving it uncached, which gives up that lifetime on the navigation too. Awaiting `navigation()` inside a cached scope is not allowed, so put the caching directive on a function called below it, as `rank` does here.
For a subtree that would otherwise sit in the App Shell, but that a `<Link prefetch={true}>` should still resolve before the click, use [`unstable_prefetch()`](/docs/app/api-reference/functions/prefetch) instead. For a subtree that would otherwise sit in the App Shell, but that a `<Link prefetch={true}>` should still resolve before the click, use [`prefetch()`](/docs/app/api-reference/functions/prefetch) instead.
Unlike [`connection()`](/docs/app/api-reference/functions/connection), `unstable_navigation()` does not make the subtree request-dependent. This lets reusable content keep its cache lifetime while waiting for navigation. See [How `unstable_navigation()` differs from `connection()`](/docs/app/api-reference/functions/navigation#how-unstable_navigation-differs-from-connection) for the full comparison. Unlike [`connection()`](/docs/app/api-reference/functions/connection), `navigation()` does not make the subtree request-dependent. This lets reusable content keep its cache lifetime while waiting for navigation. See [How `navigation()` differs from `connection()`](/docs/app/api-reference/functions/navigation#how-navigation-differs-from-connection) for the full comparison.
## Test prefetched and deferred content ## Test prefetched and deferred content
...@@ -291,6 +291,6 @@ When many links to a route are visible at once, such as a grid of cards, each `< ...@@ -291,6 +291,6 @@ When many links to a route are visible at once, such as a grid of cards, each `<
- [Adopting Partial Prefetching](/docs/app/guides/adopting-partial-prefetching) for how `<Link>` behaves under the new model and how to migrate existing apps. - [Adopting Partial Prefetching](/docs/app/guides/adopting-partial-prefetching) for how `<Link>` behaves under the new model and how to migrate existing apps.
- [`prefetch` API reference](/docs/app/api-reference/file-conventions/route-segment-config/prefetch) for all prefetch modes. - [`prefetch` API reference](/docs/app/api-reference/file-conventions/route-segment-config/prefetch) for all prefetch modes.
- [`use cache: private` reference](/docs/app/api-reference/directives/use-cache-private) for per-user caching specifics. - [`use cache: private` reference](/docs/app/api-reference/directives/use-cache-private) for per-user caching specifics.
- [`unstable_prefetch()`](/docs/app/api-reference/functions/prefetch) and [`unstable_navigation()`](/docs/app/api-reference/functions/navigation) for the full behavior of each prefetch stage. - [`prefetch()`](/docs/app/api-reference/functions/prefetch) and [`navigation()`](/docs/app/api-reference/functions/navigation) for the full behavior of each prefetch stage.
- [Instant navigation guide](/docs/app/guides/instant-navigation) for validating the route's caching structure. - [Instant navigation guide](/docs/app/guides/instant-navigation) for validating the route's caching structure.
- [Caching](/docs/app/getting-started/caching) for background on `use cache`, Suspense, and Partial Prerendering. - [Caching](/docs/app/getting-started/caching) for background on `use cache`, Suspense, and Partial Prerendering.
...@@ -16,6 +16,7 @@ The `prefetch` route segment config controls how a segment is prefetched during ...@@ -16,6 +16,7 @@ The `prefetch` route segment config controls how a segment is prefetched during
> - The `prefetch` export only works when [`cacheComponents`](/docs/app/api-reference/config/next-config-js/cacheComponents) is enabled. > - The `prefetch` export only works when [`cacheComponents`](/docs/app/api-reference/config/next-config-js/cacheComponents) is enabled.
> - `prefetch` cannot be used when the segment is a Client Component. > - `prefetch` cannot be used when the segment is a Client Component.
> - The meaningful values to set are `'partial'` and `'force-disabled'`. `'auto'` is the default and is equivalent to omitting the export; don't write `prefetch = 'auto'` explicitly. > - The meaningful values to set are `'partial'` and `'force-disabled'`. `'auto'` is the default and is equivalent to omitting the export; don't write `prefetch = 'auto'` explicitly.
> - A `page` or `layout` that also calls the [`prefetch()`](/docs/app/api-reference/functions/prefetch) function needs to import it under another name, for example `import { prefetch as prefetchStage } from 'next/cache'`.
```tsx filename="layout.tsx | page.tsx" switcher ```tsx filename="layout.tsx | page.tsx" switcher
export const prefetch = 'partial' export const prefetch = 'partial'
......
...@@ -70,7 +70,9 @@ test('caches the category data', () => { ...@@ -70,7 +70,9 @@ test('caches the category data', () => {
}) })
test('does not use a navigation-stage boundary', () => { test('does not use a navigation-stage boundary', () => {
expect(source).not.toMatch(/\bunstable_navigation\b/) expect(source).not.toMatch(
/import\s*\{[^}]*\bnavigation\b[^}]*\}\s*from\s*['"]next\/cache['"]/
)
}) })
test('prefetches the selected category and cached products', async () => { test('prefetches the selected category and cached products', async () => {
...@@ -79,6 +81,6 @@ test('prefetches the selected category and cached products', async () => { ...@@ -79,6 +81,6 @@ test('prefetches the selected category and cached products', async () => {
A correct solution preserves the existing /catalog?category=... URLs, enables Partial Prefetching globally or on the catalog route, and opts the category Links into per-link prefetching with prefetch={true} or the equivalent bare prefetch prop. The catalog route reads the category from searchParams beneath Suspense and renders both the matching heading and getProducts(category) result in the prefetched result. The category data must use a use cache scope, with either the default cache profile or an explicit cacheLife(); searchParams must remain outside that cache scope. Keep the Suspense boundary: the shared App Shell uses its fallback, while a completed per-link prefetch can resolve the cached content inside it before navigation. A correct solution preserves the existing /catalog?category=... URLs, enables Partial Prefetching globally or on the catalog route, and opts the category Links into per-link prefetching with prefetch={true} or the equivalent bare prefetch prop. The catalog route reads the category from searchParams beneath Suspense and renders both the matching heading and getProducts(category) result in the prefetched result. The category data must use a use cache scope, with either the default cache profile or an explicit cacheLife(); searchParams must remain outside that cache scope. Keep the Suspense boundary: the shared App Shell uses its fallback, while a completed per-link prefetch can resolve the cached content inside it before navigation.
This is the basic URL-data inclusion case. Do not use unstable_navigation(), unstable_prefetch(), connection(), or an uncached request boundary to defer the category content. Reject solutions that only prefetch the reusable Catalog shell while leaving the selected heading or product list behind the loading fallback.` This is the basic URL-data inclusion case. Do not use navigation(), prefetch(), connection(), or an uncached request boundary to defer the category content. Reject solutions that only prefetch the reusable Catalog shell while leaving the selected heading or product list behind the loading fallback.`
) )
}) })
...@@ -62,11 +62,11 @@ test('opts the featured product link into per-link prefetching', () => { ...@@ -62,11 +62,11 @@ test('opts the featured product link into per-link prefetching', () => {
test('uses the prefetch cache stage', () => { test('uses the prefetch cache stage', () => {
const prefetchImport = source.match( const prefetchImport = source.match(
/\bunstable_prefetch(?:\s+as\s+([A-Za-z_$][\w$]*))?/ /import\s*\{[^}]*\bprefetch\b(?:\s+as\s+([A-Za-z_$][\w$]*))?[^}]*\}\s*from\s*['"]next\/cache['"]/
) )
expect(prefetchImport).not.toBeNull() expect(prefetchImport).not.toBeNull()
const localName = prefetchImport?.[1] ?? 'unstable_prefetch' const localName = prefetchImport?.[1] ?? 'prefetch'
expect(source).toMatch(new RegExp(`await\\s+${localName}\\s*\\(`)) expect(source).toMatch(new RegExp(`await\\s+${localName}\\s*\\(`))
}) })
...@@ -80,8 +80,8 @@ test('includes related products only in the selected prefetch', async () => { ...@@ -80,8 +80,8 @@ test('includes related products only in the selected prefetch', async () => {
await expect(environment).toSatisfyCriterion( await expect(environment).toSatisfyCriterion(
`The related-products section must be available before navigation from the featured-product Link without joining the default product App Shell. `The related-products section must be available before navigation from the featured-product Link without joining the default product App Shell.
Render related products through an async component that awaits unstable_prefetch() before calling the cached getRelatedProducts() function. The unstable_prefetch() call must be outside every use cache scope, while the existing cached data function stays below it. Render related products through an async component that awaits prefetch() before calling the cached getRelatedProducts() function. The prefetch() call must be outside every use cache scope, while the existing cached data function stays below it.
Reject solutions that replace the stage with connection() or unstable_navigation(), make the related-products data uncached, or defer it until after navigation. Accept equivalent component and file organization.` Reject solutions that replace the stage with connection() or navigation(), make the related-products data uncached, or defer it until after navigation. Accept equivalent component and file organization.`
) )
}) })
...@@ -63,11 +63,11 @@ test('opts the project link into per-link prefetching', () => { ...@@ -63,11 +63,11 @@ test('opts the project link into per-link prefetching', () => {
test('uses the navigation cache stage', () => { test('uses the navigation cache stage', () => {
const navigationImport = source.match( const navigationImport = source.match(
/\bunstable_navigation(?:\s+as\s+([A-Za-z_$][\w$]*))?/ /import\s*\{[^}]*\bnavigation\b(?:\s+as\s+([A-Za-z_$][\w$]*))?[^}]*\}\s*from\s*['"]next\/cache['"]/
) )
expect(navigationImport).not.toBeNull() expect(navigationImport).not.toBeNull()
const localName = navigationImport?.[1] ?? 'unstable_navigation' const localName = navigationImport?.[1] ?? 'navigation'
expect(source).toMatch(new RegExp(`await\\s+${localName}\\s*\\(`)) expect(source).toMatch(new RegExp(`await\\s+${localName}\\s*\\(`))
}) })
...@@ -75,14 +75,14 @@ test('includes the project title in the selected prefetch', async () => { ...@@ -75,14 +75,14 @@ test('includes the project title in the selected prefetch', async () => {
await expect(environment).toSatisfyCriterion( await expect(environment).toSatisfyCriterion(
`The selected project's title must be available before the click from the dashboard's per-link prefetch. Keep the params-dependent title inside Suspense so the reusable App Shell can show a fallback while the selected prefetch resolves the title. The title must render before the nested boundary that waits for navigation. `The selected project's title must be available before the click from the dashboard's per-link prefetch. Keep the params-dependent title inside Suspense so the reusable App Shell can show a fallback while the selected prefetch resolves the title. The title must render before the nested boundary that waits for navigation.
Accept equivalent component and file organization. Reject solutions that leave the title behind the reusable shell fallback, put it behind unstable_navigation(), disable prefetching, or prefetch the entire page.` Accept equivalent component and file organization. Reject solutions that leave the title behind the reusable shell fallback, put it behind navigation(), disable prefetching, or prefetch the entire page.`
) )
}) })
test('waits until navigation for project details', async () => { test('waits until navigation for project details', async () => {
await expect(environment).toSatisfyCriterion( await expect(environment).toSatisfyCriterion(
`Project activity, deployments, description, and other detail content must not join the prefetch. Render those details inside a nested Suspense boundary through an async component that awaits unstable_navigation() before loading or rendering them. `Project activity, deployments, description, and other detail content must not join the prefetch. Render those details inside a nested Suspense boundary through an async component that awaits navigation() before loading or rendering them.
The unstable_navigation() call must remain outside every use cache scope; cached data functions may be called after it. Reject solutions that fetch project details before reaching unstable_navigation(), replace it with connection() or an uncached fetch, or prefetch the entire page. Accept equivalent component and file organization.` The navigation() call must remain outside every use cache scope; cached data functions may be called after it. Reject solutions that fetch project details before reaching navigation(), replace it with connection() or an uncached fetch, or prefetch the entire page. Accept equivalent component and file organization.`
) )
}) })
...@@ -164,5 +164,5 @@ export function cacheLife(profile: { ...@@ -164,5 +164,5 @@ export function cacheLife(profile: {
export const unstable_cacheLife: typeof cacheLife export const unstable_cacheLife: typeof cacheLife
export const unstable_cacheTag: typeof cacheTag export const unstable_cacheTag: typeof cacheTag
export { unstable_navigation } from 'next/dist/server/request/cache-stages' export { navigation } from 'next/dist/server/request/cache-stages'
export { unstable_prefetch } from 'next/dist/server/request/cache-stages' export { prefetch } from 'next/dist/server/request/cache-stages'
...@@ -25,8 +25,8 @@ if (process.env.NEXT_RUNTIME === '') { ...@@ -25,8 +25,8 @@ if (process.env.NEXT_RUNTIME === '') {
refresh: notAvailableInClient('refresh'), refresh: notAvailableInClient('refresh'),
cacheLife: notAvailableInClient('cacheLife'), cacheLife: notAvailableInClient('cacheLife'),
cacheTag: notAvailableInClient('cacheTag'), cacheTag: notAvailableInClient('cacheTag'),
unstable_navigation: notAvailableInClient('unstable_navigation'), navigation: notAvailableInClient('navigation'),
unstable_prefetch: notAvailableInClient('unstable_prefetch'), prefetch: notAvailableInClient('prefetch'),
} }
} else { } else {
// Keep server requires in this branch so browser builds can DCE them. // Keep server requires in this branch so browser builds can DCE them.
...@@ -51,10 +51,8 @@ if (process.env.NEXT_RUNTIME === '') { ...@@ -51,10 +51,8 @@ if (process.env.NEXT_RUNTIME === '') {
io: require('next/dist/server/request/io').io, io: require('next/dist/server/request/io').io,
cacheLife: require('next/dist/server/use-cache/cache-life').cacheLife, cacheLife: require('next/dist/server/use-cache/cache-life').cacheLife,
cacheTag: require('next/dist/server/use-cache/cache-tag').cacheTag, cacheTag: require('next/dist/server/use-cache/cache-tag').cacheTag,
unstable_navigation: require('next/dist/server/request/cache-stages') navigation: require('next/dist/server/request/cache-stages').navigation,
.unstable_navigation, prefetch: require('next/dist/server/request/cache-stages').prefetch,
unstable_prefetch: require('next/dist/server/request/cache-stages')
.unstable_prefetch,
} }
} }
...@@ -101,5 +99,5 @@ exports.cacheTag = cacheExports.cacheTag ...@@ -101,5 +99,5 @@ exports.cacheTag = cacheExports.cacheTag
exports.unstable_cacheTag = cacheExports.unstable_cacheTag exports.unstable_cacheTag = cacheExports.unstable_cacheTag
exports.refresh = cacheExports.refresh exports.refresh = cacheExports.refresh
exports.io = cacheExports.io exports.io = cacheExports.io
exports.unstable_navigation = cacheExports.unstable_navigation exports.navigation = cacheExports.navigation
exports.unstable_prefetch = cacheExports.unstable_prefetch exports.prefetch = cacheExports.prefetch
...@@ -358,7 +358,7 @@ export function getGuidanceVariant(message: string): GuidanceVariant { ...@@ -358,7 +358,7 @@ export function getGuidanceVariant(message: string): GuidanceVariant {
// Discriminates between `createNavigationBodyErrorInNavigation`, // Discriminates between `createNavigationBodyErrorInNavigation`,
// `createLinkBodyErrorInNavigation`, `createRuntimeBodyError`, and // `createLinkBodyErrorInNavigation`, `createRuntimeBodyError`, and
// `createDynamicBodyError` (and their in-navigation variants). // `createDynamicBodyError` (and their in-navigation variants).
if (message.includes('encountered `unstable_navigation()`')) { if (message.includes('encountered `navigation()`')) {
return 'navigation' return 'navigation'
} }
if ( if (
...@@ -900,8 +900,7 @@ export function Errors({ ...@@ -900,8 +900,7 @@ export function Errors({
case 'navigation': case 'navigation':
errorMessage = ( errorMessage = (
<> <>
Next.js encountered <code>unstable_navigation()</code> outside of Next.js encountered <code>navigation()</code> outside of Suspense.
Suspense.
</> </>
) )
break break
...@@ -1020,7 +1019,7 @@ export function Errors({ ...@@ -1020,7 +1019,7 @@ export function Errors({
case 'navigation': case 'navigation':
errorMessage = ( errorMessage = (
<> <>
Next.js encountered <code>unstable_navigation()</code> in{' '} Next.js encountered <code>navigation()</code> in{' '}
<code>generateMetadata()</code>. <code>generateMetadata()</code>.
</> </>
) )
...@@ -1095,7 +1094,7 @@ export function Errors({ ...@@ -1095,7 +1094,7 @@ export function Errors({
case 'navigation': case 'navigation':
errorMessage = ( errorMessage = (
<> <>
Next.js encountered <code>unstable_navigation()</code> in{' '} Next.js encountered <code>navigation()</code> in{' '}
<code>generateViewport()</code>. <code>generateViewport()</code>.
</> </>
) )
......
...@@ -5222,7 +5222,7 @@ async function prepareValidationInputsInPartialPrefetching( ...@@ -5222,7 +5222,7 @@ async function prepareValidationInputsInPartialPrefetching(
// (see `needsRuntimeShell` and callsites of `trackIncompatibleShellContent`) // (see `needsRuntimeShell` and callsites of `trackIncompatibleShellContent`)
// This includes: // This includes:
// - static `params` // - static `params`
// - `unstable_navigation()` and `unstable_prefetch()` // - `navigation()` and `prefetch()`
// - caches with `stale < MIN_SHELL_STALE` are excluded from app shells // - caches with `stale < MIN_SHELL_STALE` are excluded from app shells
// but are included in static prerenders // but are included in static prerenders
// If one of these APIs is used, the render can't be used for both Instant Validation and // If one of these APIs is used, the render can't be used for both Instant Validation and
......
...@@ -46,8 +46,8 @@ export function createLinkBodyErrorInNavigation(route: string): Error { ...@@ -46,8 +46,8 @@ export function createLinkBodyErrorInNavigation(route: string): Error {
export function createNavigationBodyErrorInNavigation(route: string): Error { export function createNavigationBodyErrorInNavigation(route: string): Error {
// TODO(cache-stages): docs link // TODO(cache-stages): docs link
return new Error( return new Error(
`Route "${route}": Next.js encountered \`unstable_navigation()\` during prerendering or a navigation.\n\n` + `Route "${route}": Next.js encountered \`navigation()\` during prerendering or a navigation.\n\n` +
`\`unstable_navigation()\` called outside of \`<Suspense>\` may prevent the navigation from being instant, leading to a slower user experience.\n\n` + `\`navigation()\` called outside of \`<Suspense>\` may prevent the navigation from being instant, leading to a slower user experience.\n\n` +
`Ways to fix this:\n` + `Ways to fix this:\n` +
` - [stream] Provide a placeholder with \`<Suspense fallback={...}>\` around the data access\n` + ` - [stream] Provide a placeholder with \`<Suspense fallback={...}>\` around the data access\n` +
` - [block] Set \`export const instant = false\` to allow a blocking route\n\n` + ` - [block] Set \`export const instant = false\` to allow a blocking route\n\n` +
...@@ -109,8 +109,8 @@ export function createRuntimeMetadataError(route: string): Error { ...@@ -109,8 +109,8 @@ export function createRuntimeMetadataError(route: string): Error {
export function createNavigationMetadataError(route: string): Error { export function createNavigationMetadataError(route: string): Error {
// TODO(cache-stages): docs link // TODO(cache-stages): docs link
return new Error( return new Error(
`Route "${route}": Next.js encountered \`unstable_navigation()\` in \`generateMetadata()\`.\n\n` + `Route "${route}": Next.js encountered \`navigation()\` in \`generateMetadata()\`.\n\n` +
`This route's metadata is blocked, but the rest of its content can be prefetched. \`unstable_navigation()\` called in \`generateMetadata()\` prevents it from being prefetched.\n\n` + `This route's metadata is blocked, but the rest of its content can be prefetched. \`navigation()\` called in \`generateMetadata()\` prevents it from being prefetched.\n\n` +
`Ways to fix this:\n` + `Ways to fix this:\n` +
` - [static] Use a static metadata export instead of \`generateMetadata()\`\n` + ` - [static] Use a static metadata export instead of \`generateMetadata()\`\n` +
` - [dynamic] Render a marker component that calls \`await connection()\` inside \`<Suspense>\` on the page\n\n` + ` - [dynamic] Render a marker component that calls \`await connection()\` inside \`<Suspense>\` on the page\n\n` +
...@@ -154,8 +154,8 @@ export function createRuntimeViewportError(route: string): Error { ...@@ -154,8 +154,8 @@ export function createRuntimeViewportError(route: string): Error {
export function createNavigationViewportError(route: string): Error { export function createNavigationViewportError(route: string): Error {
// TODO(cache-stages): docs link // TODO(cache-stages): docs link
return new Error( return new Error(
`Route "${route}": Next.js encountered \`unstable_navigation()\` in \`generateViewport()\`.\n\n` + `Route "${route}": Next.js encountered \`navigation()\` in \`generateViewport()\`.\n\n` +
`\`unstable_navigation()\` in \`generateViewport()\` prevents creating a shell, leading to a slower user experience.\n\n` + `\`navigation()\` in \`generateViewport()\` prevents creating a shell, leading to a slower user experience.\n\n` +
`Ways to fix this:\n` + `Ways to fix this:\n` +
` - [static] Use a static viewport export instead of \`generateViewport()\`\n` + ` - [static] Use a static viewport export instead of \`generateViewport()\`\n` +
` - [block] Set \`export const instant = false\` to allow a blocking route\n\n` + ` - [block] Set \`export const instant = false\` to allow a blocking route\n\n` +
......
...@@ -198,7 +198,7 @@ export function makeUnknownRuntimeDataHangingPromise<T>( ...@@ -198,7 +198,7 @@ export function makeUnknownRuntimeDataHangingPromise<T>(
/** /**
* Constructs a promise that never resolves, standing in for data that is only * Constructs a promise that never resolves, standing in for data that is only
* accessible in the prefetch, but not in the shell, e.g. `unstable_prefetch()`. * accessible in the prefetch, but not in the shell, e.g. `prefetch()`.
* This usage does *not* indicate that a runtime request is needed, * This usage does *not* indicate that a runtime request is needed,
* only that the data is not available in a shell. * only that the data is not available in a shell.
* *
......
...@@ -138,16 +138,16 @@ follow the static-shell documentation used by ...@@ -138,16 +138,16 @@ follow the static-shell documentation used by
authorization behavior. Change only what the selected contract requires. authorization behavior. Change only what the selected contract requires.
When reusable UI should wait for navigation, follow the When reusable UI should wait for navigation, follow the
[`unstable_navigation()`](https://nextjs.org/docs/app/api-reference/functions/navigation) [`navigation()`](https://nextjs.org/docs/app/api-reference/functions/navigation)
reference, including its comparison with `connection()`. Then verify both reference, including its comparison with `connection()`. Then verify both
properties independently. The `instant()` assertion proves that the UI is properties independently. The `instant()` assertion proves that the UI is
absent from the prefetch; it does not prove that the underlying work stayed absent from the prefetch; it does not prove that the underlying work stayed
reusable. Verify that reusable work remains cached below the stage boundary. reusable. Verify that reusable work remains cached below the stage boundary.
When the contract needs an explicit runtime stage, follow the API references When the contract needs an explicit runtime stage, follow the API references
for [`unstable_prefetch()`](https://nextjs.org/docs/app/api-reference/functions/prefetch) for [`prefetch()`](https://nextjs.org/docs/app/api-reference/functions/prefetch)
and and
[`unstable_navigation()`](https://nextjs.org/docs/app/api-reference/functions/navigation). [`navigation()`](https://nextjs.org/docs/app/api-reference/functions/navigation).
Work one accepted navigation to GREEN before moving to another. Do not create Work one accepted navigation to GREEN before moving to another. Do not create
an app-wide Link or cache abstraction from a single case. an app-wide Link or cache abstraction from a single case.
......
import { cookies, headers } from 'next/headers' import { cookies, headers } from 'next/headers'
import { CachedData } from '../../data-fetching' import { CachedData } from '../../data-fetching'
import { connection } from 'next/server' import { connection } from 'next/server'
import { import { navigation, prefetch as prefetchStage } from 'next/cache'
unstable_navigation as navigation,
unstable_prefetch,
} from 'next/cache'
import { Suspense } from 'react' import { Suspense } from 'react'
export const instant = true export const instant = true
...@@ -26,7 +23,7 @@ export default function Page({ params, searchParams }) { ...@@ -26,7 +23,7 @@ export default function Page({ params, searchParams }) {
<LogAfter label="headers" api={() => headers()} /> <LogAfter label="headers" api={() => headers()} />
<LogAfter label="params" api={() => params} /> <LogAfter label="params" api={() => params} />
<LogAfter label="searchParams" api={() => searchParams} /> <LogAfter label="searchParams" api={() => searchParams} />
<LogAfter label="prefetch" api={() => unstable_prefetch()} /> <LogAfter label="prefetch" api={() => prefetchStage()} />
<LogAfter label="navigation" api={() => navigation()} /> <LogAfter label="navigation" api={() => navigation()} />
{/* Dynamic */} {/* Dynamic */}
......
import { cookies, headers } from 'next/headers' import { cookies, headers } from 'next/headers'
import { CachedData } from '../../data-fetching' import { CachedData } from '../../data-fetching'
import { connection } from 'next/server' import { connection } from 'next/server'
import { import { navigation, prefetch } from 'next/cache'
unstable_navigation as navigation,
unstable_prefetch,
} from 'next/cache'
import { Suspense } from 'react' import { Suspense } from 'react'
const CACHE_KEY = __dirname + '/__PAGE__' const CACHE_KEY = __dirname + '/__PAGE__'
...@@ -23,7 +20,7 @@ export default function Page({ params, searchParams }) { ...@@ -23,7 +20,7 @@ export default function Page({ params, searchParams }) {
<LogAfter label="headers" api={() => headers()} /> <LogAfter label="headers" api={() => headers()} />
<LogAfter label="params" api={() => params} /> <LogAfter label="params" api={() => params} />
<LogAfter label="searchParams" api={() => searchParams} /> <LogAfter label="searchParams" api={() => searchParams} />
<LogAfter label="prefetch" api={() => unstable_prefetch()} /> <LogAfter label="prefetch" api={() => prefetch()} />
<LogAfter label="navigation" api={() => navigation()} /> <LogAfter label="navigation" api={() => navigation()} />
{/* Dynamic */} {/* Dynamic */}
......
import { unstable_navigation } from 'next/cache' import { navigation } from 'next/cache'
import { Suspense } from 'react' import { Suspense } from 'react'
import UncachedTimePage from '../uncached-time/page' import UncachedTimePage from '../uncached-time/page'
async function Content() { async function Content() {
// The navigation stage defers this subtree past the initial Flight rows. The // The navigation stage defers this subtree past the initial Flight rows. The
// private cache in UncachedTimePage still resolves before the dynamic stage. // private cache in UncachedTimePage still resolves before the dynamic stage.
await unstable_navigation() await navigation()
return <UncachedTimePage /> return <UncachedTimePage />
} }
......
import { unstable_navigation } from 'next/cache' import { navigation } from 'next/cache'
// NOTE: the page must export the following literally, we can't // NOTE: the page must export the following literally, we can't
// reexport them from here: // reexport them from here:
...@@ -23,6 +23,6 @@ export default async function Page() { ...@@ -23,6 +23,6 @@ export default async function Page() {
} }
async function Navigation() { async function Navigation() {
await unstable_navigation() await navigation()
return <div>Navigation data</div> return <div>Navigation data</div>
} }
import { unstable_prefetch } from 'next/cache' import { prefetch } from 'next/cache'
// NOTE: the page must export the following literally, we can't // NOTE: the page must export the following literally, we can't
// reexport them from here: // reexport them from here:
...@@ -23,6 +23,6 @@ export default async function Page() { ...@@ -23,6 +23,6 @@ export default async function Page() {
} }
async function Prefetch() { async function Prefetch() {
await unstable_prefetch() await prefetch()
return <div>Prefetch data</div> return <div>Prefetch data</div>
} }
import { Instant } from 'next' import { Instant } from 'next'
import { unstable_navigation as navigation } from 'next/cache' import { navigation } from 'next/cache'
export const instant: Instant = { export const instant: Instant = {
level: 'experimental-error', level: 'experimental-error',
......
import { Instant } from 'next' import { Instant } from 'next'
import { unstable_prefetch } from 'next/cache' import { prefetch as prefetchStage } from 'next/cache'
export const instant: Instant = { export const instant: Instant = {
level: 'experimental-error', level: 'experimental-error',
...@@ -20,6 +20,6 @@ export default async function Page() { ...@@ -20,6 +20,6 @@ export default async function Page() {
} }
async function PrefetchContent() { async function PrefetchContent() {
await unstable_prefetch() await prefetchStage()
return <div>{`Prefetch content`}</div> return <div>{`Prefetch content`}</div>
} }
import { Instant } from 'next' import { Instant } from 'next'
import { unstable_navigation as navigation } from 'next/cache' import { navigation } from 'next/cache'
import { Suspense } from 'react' import { Suspense } from 'react'
export const instant: Instant = { export const instant: Instant = {
......
import { Instant } from 'next' import { Instant } from 'next'
import { unstable_prefetch } from 'next/cache' import { prefetch as prefetchStage } from 'next/cache'
import { Suspense } from 'react' import { Suspense } from 'react'
export const instant: Instant = { export const instant: Instant = {
...@@ -23,6 +23,6 @@ export default async function Page() { ...@@ -23,6 +23,6 @@ export default async function Page() {
} }
async function PrefetchContent() { async function PrefetchContent() {
await unstable_prefetch() await prefetchStage()
return <div>{`Prefetch content`}</div> return <div>{`Prefetch content`}</div>
} }
import { Instant } from 'next' import { Instant } from 'next'
import { unstable_navigation as navigation } from 'next/cache' import { navigation } from 'next/cache'
export const instant: Instant = { export const instant: Instant = {
level: 'experimental-error', level: 'experimental-error',
......
import { Instant } from 'next' import { Instant } from 'next'
import { unstable_prefetch } from 'next/cache' import { prefetch } from 'next/cache'
export const instant: Instant = { export const instant: Instant = {
level: 'experimental-error', level: 'experimental-error',
...@@ -18,6 +18,6 @@ export default async function Page() { ...@@ -18,6 +18,6 @@ export default async function Page() {
} }
async function PrefetchContent() { async function PrefetchContent() {
await unstable_prefetch() await prefetch()
return <div>{`Prefetch content`}</div> return <div>{`Prefetch content`}</div>
} }
import { unstable_navigation as navigation } from 'next/cache' import { navigation } from 'next/cache'
import { Suspense } from 'react' import { Suspense } from 'react'
export const instant = { level: 'experimental-error' } export const instant = { level: 'experimental-error' }
......
import { unstable_prefetch } from 'next/cache' import { prefetch } from 'next/cache'
import { Suspense } from 'react' import { Suspense } from 'react'
export const instant = { level: 'experimental-error' } export const instant = { level: 'experimental-error' }
...@@ -23,6 +23,6 @@ export default async function Page() { ...@@ -23,6 +23,6 @@ export default async function Page() {
} }
async function SyncIOAfterPrefetch() { async function SyncIOAfterPrefetch() {
await unstable_prefetch() await prefetch()
return Date.now() return Date.now()
} }
...@@ -181,7 +181,7 @@ export function registerSyncIoAndBlockingTests( ...@@ -181,7 +181,7 @@ export function registerSyncIoAndBlockingTests(
Learn more: https://nextjs.org/docs/messages/blocking-prerender-current-time Learn more: https://nextjs.org/docs/messages/blocking-prerender-current-time
at a (app/suspense-in-root/sync-io/sync-io-after-prefetch/page.tsx:27:15) at a (app/suspense-in-root/sync-io/sync-io-after-prefetch/page.tsx:27:15)
25 | async function SyncIOAfterPrefetch() { 25 | async function SyncIOAfterPrefetch() {
26 | await unstable_prefetch() 26 | await prefetch()
> 27 | return Date.now() > 27 | return Date.now()
| ^ | ^
28 | } 28 | }
......
import { cookies, headers } from 'next/headers' import { cookies, headers } from 'next/headers'
import { connection } from 'next/server' import { connection } from 'next/server'
import { import { navigation, prefetch } from 'next/cache'
unstable_navigation as navigation,
unstable_prefetch,
} from 'next/cache'
import { Suspense } from 'react' import { Suspense } from 'react'
// Note: intentionally no `export const prefetch` and no `instant` config. This // Note: intentionally no `export const prefetch` and no `instant` config. This
...@@ -89,6 +86,6 @@ async function NavigationContent() { ...@@ -89,6 +86,6 @@ async function NavigationContent() {
} }
async function PrefetchContent() { async function PrefetchContent() {
await unstable_prefetch() await prefetch()
return <p>Prefetch content</p> return <p>Prefetch content</p>
} }
import { getCachedValue, CookieData } from '../../../cached-value' import { getCachedValue, CookieData } from '../../../cached-value'
import { Suspense } from 'react' import { Suspense } from 'react'
import { connection } from 'next/server' import { connection } from 'next/server'
import { unstable_prefetch } from 'next/cache' import { prefetch } from 'next/cache'
export default async function Page() { export default async function Page() {
const cachedValue = await getCachedValue() const cachedValue = await getCachedValue()
...@@ -42,7 +42,7 @@ export default async function Page() { ...@@ -42,7 +42,7 @@ export default async function Page() {
} }
async function PrefetchOnly({ children }) { async function PrefetchOnly({ children }) {
await unstable_prefetch() await prefetch()
return children return children
} }
......
import { getCachedValue, CookieData } from '../../../cached-value' import { getCachedValue, CookieData } from '../../../cached-value'
import { Suspense } from 'react' import { Suspense } from 'react'
import { connection } from 'next/server' import { connection } from 'next/server'
import { unstable_prefetch } from 'next/cache' import { prefetch } from 'next/cache'
export default async function Page() { export default async function Page() {
const cachedValue = await getCachedValue() const cachedValue = await getCachedValue()
...@@ -42,7 +42,7 @@ export default async function Page() { ...@@ -42,7 +42,7 @@ export default async function Page() {
} }
async function PrefetchOnly({ children }) { async function PrefetchOnly({ children }) {
await unstable_prefetch() await prefetch()
return children return children
} }
......
import { ConditionalCookies } from '../../cached-value' import { ConditionalCookies } from '../../cached-value'
import { Suspense } from 'react' import { Suspense } from 'react'
import { connection } from 'next/server' import { connection } from 'next/server'
import { unstable_prefetch } from 'next/cache' import { prefetch } from 'next/cache'
export default async function Page() { export default async function Page() {
return ( return (
...@@ -27,7 +27,7 @@ export default async function Page() { ...@@ -27,7 +27,7 @@ export default async function Page() {
} }
async function PrefetchOnly({ children }) { async function PrefetchOnly({ children }) {
await unstable_prefetch() await prefetch()
return children return children
} }
......
import { ConditionalCookies } from '../../../cached-value' import { ConditionalCookies } from '../../../cached-value'
import { Suspense } from 'react' import { Suspense } from 'react'
import { connection } from 'next/server' import { connection } from 'next/server'
import { unstable_prefetch } from 'next/cache' import { prefetch } from 'next/cache'
export default async function Page() { export default async function Page() {
return ( return (
...@@ -32,6 +32,6 @@ async function DynamicData() { ...@@ -32,6 +32,6 @@ async function DynamicData() {
return <div id="dynamic-data">Dynamic data</div> return <div id="dynamic-data">Dynamic data</div>
} }
async function PrefetchData() { async function PrefetchData() {
await unstable_prefetch() await prefetch()
return <div id="prefetch-data">Prefetch data</div> return <div id="prefetch-data">Prefetch data</div>
} }
import { ConditionalCookies } from '../../../cached-value' import { ConditionalCookies } from '../../../cached-value'
import { Suspense } from 'react' import { Suspense } from 'react'
import { unstable_prefetch } from 'next/cache' import { prefetch } from 'next/cache'
export default async function Page() { export default async function Page() {
return ( return (
...@@ -22,6 +22,6 @@ export default async function Page() { ...@@ -22,6 +22,6 @@ export default async function Page() {
} }
async function PrefetchData() { async function PrefetchData() {
await unstable_prefetch() await prefetch()
return <div id="prefetch-data">Prefetch data</div> return <div id="prefetch-data">Prefetch data</div>
} }
import { cacheTag, revalidateTag, unstable_prefetch } from 'next/cache' import { cacheTag, revalidateTag, prefetch } from 'next/cache'
import * as fs from 'node:fs' import * as fs from 'node:fs'
import { Suspense } from 'react' import { Suspense } from 'react'
...@@ -92,7 +92,7 @@ async function CookieDataImpl({ label }: { label?: string }) { ...@@ -92,7 +92,7 @@ async function CookieDataImpl({ label }: { label?: string }) {
} }
async function RuntimePrefetchData() { async function RuntimePrefetchData() {
await unstable_prefetch() await prefetch()
return ( return (
<div id="cookies-runtime-prefetch-data"> <div id="cookies-runtime-prefetch-data">
Runtime prefetch data (behind cookies) Runtime prefetch data (behind cookies)
......
import { Suspense } from 'react' import { Suspense } from 'react'
import { unstable_navigation as navigation } from 'next/cache' import { navigation } from 'next/cache'
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
import { connection } from 'next/server' import { connection } from 'next/server'
......
import { Suspense } from 'react' import { Suspense } from 'react'
import { unstable_prefetch } from 'next/cache' import { prefetch as prefetchStage } from 'next/cache'
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
import { connection } from 'next/server' import { connection } from 'next/server'
...@@ -24,7 +24,7 @@ export default async function Page({ params }: { params: Promise<Params> }) { ...@@ -24,7 +24,7 @@ export default async function Page({ params }: { params: Promise<Params> }) {
async function PrefetchData() { async function PrefetchData() {
await cookies() // Makes sure this page uses a runtime prefetch await cookies() // Makes sure this page uses a runtime prefetch
await unstable_prefetch() // Exclude the contents below from runtime app shells await prefetchStage() // Exclude the contents below from runtime app shells
return <div id="prefetch-content">Prefetch content</div> return <div id="prefetch-content">Prefetch content</div>
} }
......
import { Suspense } from 'react' import { Suspense } from 'react'
import { unstable_navigation as navigation } from 'next/cache' import { navigation } from 'next/cache'
import { connection } from 'next/server' import { connection } from 'next/server'
export async function generateStaticParams() { export async function generateStaticParams() {
......
import { Suspense } from 'react' import { Suspense } from 'react'
import { unstable_prefetch } from 'next/cache' import { prefetch as prefetchStage } from 'next/cache'
import { connection } from 'next/server' import { connection } from 'next/server'
export async function generateStaticParams() { export async function generateStaticParams() {
...@@ -24,7 +24,7 @@ export default async function Page({ params }: { params: Promise<Params> }) { ...@@ -24,7 +24,7 @@ export default async function Page({ params }: { params: Promise<Params> }) {
} }
async function PrefetchData() { async function PrefetchData() {
await unstable_prefetch() // Exclude the contents below from the shell await prefetchStage() // Exclude the contents below from the shell
return <div id="prefetch-content">Prefetch content</div> return <div id="prefetch-content">Prefetch content</div>
} }
......
import { unstable_navigation } from 'next/cache' import { navigation } from 'next/cache'
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
import { Suspense } from 'react' import { Suspense } from 'react'
...@@ -66,6 +66,6 @@ async function ConditionalCookiesUse({ slug }: { slug: string }) { ...@@ -66,6 +66,6 @@ async function ConditionalCookiesUse({ slug }: { slug: string }) {
} }
async function NavigationContent({ slug }: { slug: string }) { async function NavigationContent({ slug }: { slug: string }) {
await unstable_navigation() await navigation()
return <div>{`Navigation content on ${slug}`}</div> return <div>{`Navigation content on ${slug}`}</div>
} }
import { unstable_prefetch } from 'next/cache' import { prefetch } from 'next/cache'
import { Suspense } from 'react' import { Suspense } from 'react'
/** /**
...@@ -35,6 +35,6 @@ export function PrefetchContent({ text }: { text: string }) { ...@@ -35,6 +35,6 @@ export function PrefetchContent({ text }: { text: string }) {
} }
async function Inner({ text }: { text: string }) { async function Inner({ text }: { text: string }) {
await unstable_prefetch() await prefetch()
return <div id="prefetch-content">{text}</div> return <div id="prefetch-content">{text}</div>
} }
import { Suspense } from 'react' import { Suspense } from 'react'
import { import { navigation, prefetch } from 'next/cache'
unstable_navigation as navigation,
unstable_prefetch,
} from 'next/cache'
type Params = { slug: string } type Params = { slug: string }
...@@ -53,6 +50,6 @@ async function NavigationContent() { ...@@ -53,6 +50,6 @@ async function NavigationContent() {
} }
async function PrefetchContent() { async function PrefetchContent() {
await unstable_prefetch() await prefetch()
return <p id="prefetch-content">Prefetch content</p> return <p id="prefetch-content">Prefetch content</p>
} }
import { unstable_navigation as navigation } from 'next/cache' import { navigation } from 'next/cache'
import { Suspense } from 'react' import { Suspense } from 'react'
type Props = { params: Promise<{ id: string }> } type Props = { params: Promise<{ id: string }> }
......
import { Suspense } from 'react' import { Suspense } from 'react'
import { unstable_navigation as navigation } from 'next/cache' import { navigation } from 'next/cache'
export default function Page() { export default function Page() {
return ( return (
......
import { Suspense } from 'react' import { Suspense } from 'react'
import { unstable_prefetch } from 'next/cache' import { prefetch } from 'next/cache'
export default function Page() { export default function Page() {
return ( return (
...@@ -12,6 +12,6 @@ export default function Page() { ...@@ -12,6 +12,6 @@ export default function Page() {
} }
async function PrefetchContent() { async function PrefetchContent() {
await unstable_prefetch() await prefetch()
return <p id="page-content">Fully static page content (with prefetch())</p> return <p id="page-content">Fully static page content (with prefetch())</p>
} }
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
import { cacheLife } from 'next/dist/server/use-cache/cache-life' import { cacheLife } from 'next/dist/server/use-cache/cache-life'
import { cookies, headers } from 'next/headers' import { cookies, headers } from 'next/headers'
import { unstable_navigation as navigation } from 'next/cache' import { navigation } from 'next/cache'
import { Suspense } from 'react' import { Suspense } from 'react'
export default async function Page() { export default async function Page() {
......
// A page that calls cookies and headers after awaiting `unstable_prefetch()`. // A page that calls cookies and headers after awaiting `prefetch()`.
// Unlike `navigation()`, `prefetch()` doesn't stop runtime-data tracking — the // Unlike `navigation()`, `prefetch()` doesn't stop runtime-data tracking — the
// reads below it still count — so the tree hint stays unset and this route // reads below it still count — so the tree hint stays unset and this route
// can't be prefetched statically. // can't be prefetched statically.
import { cookies, headers } from 'next/headers' import { cookies, headers } from 'next/headers'
import { unstable_prefetch } from 'next/cache' import { prefetch } from 'next/cache'
import { Suspense } from 'react' import { Suspense } from 'react'
export default async function Page() { export default async function Page() {
...@@ -21,7 +21,7 @@ export default async function Page() { ...@@ -21,7 +21,7 @@ export default async function Page() {
} }
async function Prefetch() { async function Prefetch() {
await unstable_prefetch() await prefetch()
return ( return (
<> <>
......
import { import { prefetch, navigation } from 'next/cache'
unstable_prefetch as prefetch,
unstable_navigation as navigation,
} from 'next/cache'
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
import { Suspense } from 'react' import { Suspense } from 'react'
......
import { import { prefetch, navigation } from 'next/cache'
unstable_prefetch as prefetch,
unstable_navigation as navigation,
} from 'next/cache'
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
import { Suspense } from 'react' import { Suspense } from 'react'
......
import { unstable_navigation as navigation } from 'next/cache' import { navigation } from 'next/cache'
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
import { connection } from 'next/server' import { connection } from 'next/server'
import { Suspense } from 'react' import { Suspense } from 'react'
......
import { unstable_prefetch as prefetch } from 'next/cache' import { prefetch } from 'next/cache'
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
import { connection } from 'next/server' import { connection } from 'next/server'
import { Suspense } from 'react' import { Suspense } from 'react'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment