Skip to content

Commit 4698f1f

Browse files
committed
rename "unstable_prefetch" to "unstable_instant"
1 parent e01160f commit 4698f1f

File tree

63 files changed

+108
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+108
-101
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
---
2-
title: Invalid Prefetch Configuration
2+
title: Invalid Instant Configuration
33
---
44

55
## Why This Message Occurred
66

7-
You provided an invalid configuration for `export const unstable_prefetch` in a Layout or Page file.
7+
You provided an invalid configuration for `export const unstable_instant` in a Layout or Page file.
88

99
### Example of Correct Usage
1010

1111
#### Static Prefetching
1212

1313
```tsx filename="app/.../layout.tsx"
14-
export const unstable_prefetch = {
14+
export const unstable_instant = {
1515
mode: 'static',
1616
}
1717
```
1818

1919
#### Runtime Prefetching
2020

2121
```tsx filename="app/[slug]/page.tsx"
22-
export const unstable_prefetch = {
22+
export const unstable_instant = {
2323
mode: 'runtime',
2424
samples: [
2525
{

errors/next-prerender-runtime-crypto.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ If you are generating a token to talk to a database that itself should be cached
1919
Before:
2020

2121
```jsx filename="app/page.js"
22-
export const unstable_prefetch = {
22+
export const unstable_instant = {
2323
mode: 'runtime',
2424
samples: [...],
2525
}
@@ -40,7 +40,7 @@ export default async function Page({ params }) {
4040
After:
4141

4242
```jsx filename="app/page.js"
43-
export const unstable_prefetch = {
43+
export const unstable_instant = {
4444
mode: 'runtime',
4545
samples: [...],
4646
}
@@ -65,7 +65,7 @@ If you require this random value to be unique per Request and an async version o
6565
Before:
6666

6767
```jsx filename="app/page.js"
68-
export const unstable_prefetch = {
68+
export const unstable_instant = {
6969
mode: 'runtime',
7070
samples: [...],
7171
}
@@ -84,7 +84,7 @@ export default async function Page({ params }) {
8484
After:
8585

8686
```jsx filename="app/page.js"
87-
export const unstable_prefetch = {
87+
export const unstable_instant = {
8888
mode: 'runtime',
8989
samples: [...],
9090
}
@@ -107,7 +107,7 @@ If you require this random value to be unique per Request and an async version o
107107
Before:
108108

109109
```jsx filename="app/page.js"
110-
export const unstable_prefetch = {
110+
export const unstable_instant = {
111111
mode: 'runtime',
112112
samples: [...],
113113
}
@@ -122,7 +122,7 @@ export default async function Page({ params }) {
122122
After:
123123

124124
```jsx filename="app/page.js"
125-
export const unstable_prefetch = {
125+
export const unstable_instant = {
126126
mode: 'runtime',
127127
samples: [...],
128128
}

errors/next-prerender-runtime-current-time.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ If you are using the current time for performance tracking with elapsed time use
2323
Before:
2424

2525
```jsx filename="app/page.js"
26-
export const unstable_prefetch = {
26+
export const unstable_instant = {
2727
mode: 'runtime',
2828
samples: [...],
2929
}
@@ -42,7 +42,7 @@ export default async function Page({ params }) {
4242
After:
4343

4444
```jsx filename="app/page.js"
45-
export const unstable_prefetch = {
45+
export const unstable_instant = {
4646
mode: 'runtime',
4747
samples: [...],
4848
}
@@ -67,7 +67,7 @@ If you want to read the time when some cache entry is created (such as when a Ne
6767
Before:
6868

6969
```jsx filename="app/page.js"
70-
export const unstable_prefetch = {
70+
export const unstable_instant = {
7171
mode: 'runtime',
7272
samples: [...],
7373
}
@@ -96,7 +96,7 @@ export default async function Page({ params }) {
9696
After:
9797

9898
```jsx filename="app/page.js"
99-
export const unstable_prefetch = {
99+
export const unstable_instant = {
100100
mode: 'runtime',
101101
samples: [...],
102102
}
@@ -136,7 +136,7 @@ If you go with this approach you will need to ensure the Client Component which
136136
Before:
137137

138138
```jsx filename="app/page.js"
139-
export const unstable_prefetch = {
139+
export const unstable_instant = {
140140
mode: 'runtime',
141141
samples: [...],
142142
}
@@ -193,7 +193,7 @@ export function RelativeTime({ when }) {
193193
```
194194
195195
```jsx filename="app/page.js"
196-
export const unstable_prefetch = {
196+
export const unstable_instant = {
197197
mode: 'runtime',
198198
samples: [...],
199199
}
@@ -230,7 +230,7 @@ Next.js enforces that it can always produce at least a partially static initial
230230
Before:
231231
232232
```jsx filename="app/page.js"
233-
export const unstable_prefetch = {
233+
export const unstable_instant = {
234234
mode: 'runtime',
235235
samples: [...],
236236
}
@@ -249,7 +249,7 @@ export default async function Page() {
249249
After:
250250
251251
```jsx filename="app/page.js"
252-
export const unstable_prefetch = {
252+
export const unstable_instant = {
253253
mode: 'runtime',
254254
samples: [...],
255255
}

errors/next-prerender-runtime-random.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ If your random value is cacheable, move the `Math.random()` call to a `"use cach
2323
Before:
2424

2525
```jsx filename="app/page.js"
26-
export const unstable_prefetch = {
26+
export const unstable_instant = {
2727
mode: 'runtime',
2828
samples: [...],
2929
}
@@ -40,7 +40,7 @@ export default async function Page({ params }) {
4040
After:
4141

4242
```jsx filename="app/page.js"
43-
export const unstable_prefetch = {
43+
export const unstable_instant = {
4444
mode: 'runtime',
4545
samples: [...],
4646
}
@@ -68,7 +68,7 @@ If you want the random value to be evaluated on each Request precede it with `aw
6868
Before:
6969

7070
```jsx filename="app/page.js"
71-
export const unstable_prefetch = {
71+
export const unstable_instant = {
7272
mode: 'runtime',
7373
samples: [...],
7474
}
@@ -85,7 +85,7 @@ export default async function Page({ params }) {
8585
After:
8686

8787
```jsx filename="app/page.js"
88-
export const unstable_prefetch = {
88+
export const unstable_instant = {
8989
mode: 'runtime',
9090
samples: [...],
9191
}

packages/next/errors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,5 +986,6 @@
986986
"985": "No response is returned from route handler '%s'. Expected a Response object but received '%s' (method: %s, url: %s). Ensure you return a \\`Response\\` or a \\`NextResponse\\` in all branches of your handler.",
987987
"986": "Server Action arguments list is too long (%s). Maximum allowed is %s.",
988988
"987": "Invalid \\`deploymentId\\` configuration: must be a string. See https://nextjs.org/docs/messages/deploymentid-not-a-string",
989-
"988": "Invalid \\`deploymentId\\` configuration: contains invalid characters. Only alphanumeric characters, hyphens, and underscores are allowed. See https://nextjs.org/docs/messages/deploymentid-invalid-characters"
989+
"988": "Invalid \\`deploymentId\\` configuration: contains invalid characters. Only alphanumeric characters, hyphens, and underscores are allowed. See https://nextjs.org/docs/messages/deploymentid-invalid-characters",
990+
"989": "Page \"%s\" cannot use \\`export const unstable_instant = ...\\` without enabling \\`cacheComponents\\`."
990991
}

packages/next/src/build/analysis/get-page-static-info.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,9 @@ export async function getAppPageStaticInfo({
684684
)
685685
}
686686

687-
if ('unstable_prefetch' in config && !nextConfig.cacheComponents) {
687+
if ('unstable_instant' in config && !nextConfig.cacheComponents) {
688688
throw new Error(
689-
`Page "${page}" cannot use \`export const unstable_prefetch = ...\` without enabling \`cacheComponents\`.`
689+
`Page "${page}" cannot use \`export const unstable_instant = ...\` without enabling \`cacheComponents\`.`
690690
)
691691
}
692692

packages/next/src/build/segment-config/app/app-segment-config.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ const RuntimeSampleSchema = z
2121
})
2222
.strict()
2323

24-
const StaticPrefetchSchema = z
24+
const InstantConfigStaticSchema = z
2525
.object({
2626
mode: z.literal('static'),
2727
from: z.array(z.string()).optional(),
2828
expectUnableToVerify: z.boolean().optional(),
2929
})
3030
.strict()
3131

32-
const RuntimePrefetchSchema = z
32+
const InstantConfigRuntimeSchema = z
3333
.object({
3434
mode: z.literal('runtime'),
3535
samples: z.array(RuntimeSampleSchema).min(1),
@@ -38,42 +38,48 @@ const RuntimePrefetchSchema = z
3838
})
3939
.strict()
4040

41-
const PrefetchSchema = z.discriminatedUnion('mode', [
42-
StaticPrefetchSchema,
43-
RuntimePrefetchSchema,
41+
const InstantConfigSchema = z.discriminatedUnion('mode', [
42+
InstantConfigStaticSchema,
43+
InstantConfigRuntimeSchema,
4444
])
4545

46-
export type Prefetch = StaticPrefetch | RuntimePrefetch
47-
export type PrefetchForTypeCheckInternal = __GenericPrefetch | Prefetch
46+
export type InstantConfig = InstantConfigStatic | InstantConfigRuntime
47+
export type InstantConfigForTypeCheckInternal =
48+
| __GenericInstantConfig
49+
| InstantConfig
4850
// the __GenericPrefetch type is used to avoid type widening issues with
4951
// our choice to make exports the medium for programming a Next.js application
5052
// With exports the type is controlled by the module and all we can do is assert on it
5153
// from a consumer. However with string literals in objects these are by default typed widely
5254
// and thus cannot match the discriminated union type. If we figure out a better way we should
5355
// delete the __GenericPrefetch member.
54-
interface __GenericPrefetch {
56+
interface __GenericInstantConfig {
5557
mode: string
5658
samples?: Array<WideRuntimeSample>
5759
from?: string[]
5860
expectUnableToVerify?: boolean
5961
}
60-
interface StaticPrefetch {
62+
63+
interface InstantConfigStatic {
6164
mode: 'static'
6265
from?: string[]
6366
expectUnableToVerify?: boolean
6467
}
65-
interface RuntimePrefetch {
68+
69+
interface InstantConfigRuntime {
6670
mode: 'runtime'
6771
samples: Array<RuntimeSample>
6872
from?: string[]
6973
expectUnableToVerify?: boolean
7074
}
75+
7176
type WideRuntimeSample = {
7277
cookies?: RuntimeSample['cookies']
7378
headers?: Array<string[]>
7479
params?: RuntimeSample['params']
7580
searchParams?: RuntimeSample['searchParams']
7681
}
82+
7783
type RuntimeSample = {
7884
cookies?: Array<{
7985
name: string
@@ -127,7 +133,7 @@ const AppSegmentConfigSchema = z.object({
127133
/**
128134
* How this segment should be prefetched.
129135
*/
130-
unstable_prefetch: PrefetchSchema.optional(),
136+
unstable_instant: InstantConfigSchema.optional(),
131137

132138
/**
133139
* The preferred region for the page.
@@ -166,10 +172,10 @@ export function parseAppSegmentConfig(
166172
)} on "${route}", must be a non-negative number or false`,
167173
}
168174
}
169-
case 'unstable_prefetch': {
175+
case 'unstable_instant': {
170176
return {
171177
// @TODO replace this link with a link to the docs when they are written
172-
message: `Invalid unstable_prefetch value ${JSON.stringify(ctx.data)} on "${route}", must be an object with a mode of "static" or "runtime". Read more at https://nextjs.org/docs/messages/invalid-prefetch-configuration`,
178+
message: `Invalid unstable_instant value ${JSON.stringify(ctx.data)} on "${route}", must be an object with a mode of "static" or "runtime". Read more at https://nextjs.org/docs/messages/invalid-instant-configuration`,
173179
}
174180
}
175181
default:
@@ -224,7 +230,7 @@ export type AppSegmentConfig = {
224230
/**
225231
* How this segment should be prefetched.
226232
*/
227-
unstable_prefetch?: Prefetch
233+
unstable_instant?: InstantConfig
228234

229235
/**
230236
* The preferred region for the page.

packages/next/src/build/webpack/plugins/next-types-plugin/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ${
5454
: `import type { ResolvingMetadata, ResolvingViewport } from 'next/dist/lib/metadata/types/metadata-interface.js'`
5555
}
5656
57-
import type { PrefetchForTypeCheckInternal } from 'next/dist/build/segment-config/app/app-segment-config.js'
57+
import type { InstantConfigForTypeCheckInternal } from 'next/dist/build/segment-config/app/app-segment-config.js'
5858
5959
type TEntry = typeof import('${relativePath}.js')
6060
@@ -71,7 +71,7 @@ checkFields<Diff<{
7171
}
7272
config?: {}
7373
generateStaticParams?: Function
74-
unstable_prefetch?: PrefetchForTypeCheckInternal
74+
unstable_instant?: InstantConfigForTypeCheckInternal
7575
revalidate?: RevalidateRange<TEntry> | false
7676
dynamic?: 'auto' | 'force-dynamic' | 'error' | 'force-static'
7777
dynamicParams?: boolean

packages/next/src/server/app-render/create-component-tree.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ async function createComponentTreeInternal(
225225
})
226226
: []
227227

228-
const prefetchConfig = layoutOrPageMod
229-
? (layoutOrPageMod as AppSegmentConfig).unstable_prefetch
228+
const instantConfig = layoutOrPageMod
229+
? (layoutOrPageMod as AppSegmentConfig).unstable_instant
230230
: undefined
231231
/** Whether this segment should use a runtime prefetch instead of a static prefetch. */
232-
const hasRuntimePrefetch = prefetchConfig?.mode === 'runtime'
232+
const hasRuntimePrefetch = instantConfig?.mode === 'runtime'
233233

234234
const [Forbidden, forbiddenStyles] =
235235
authInterrupts && forbidden

packages/next/src/server/app-render/staged-validation.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ export async function anySegmentHasRuntimePrefetchEnabled(
99
const { mod: layoutOrPageMod } = await getLayoutOrPageModule(tree)
1010

1111
// TODO(restart-on-cache-miss): Does this work correctly for client page/layout modules?
12-
const prefetchConfig = layoutOrPageMod
13-
? (layoutOrPageMod as AppSegmentConfig).unstable_prefetch
12+
const instantConfig = layoutOrPageMod
13+
? (layoutOrPageMod as AppSegmentConfig).unstable_instant
1414
: undefined
1515
/** Whether this segment should use a runtime prefetch instead of a static prefetch. */
16-
const hasRuntimePrefetch = prefetchConfig?.mode === 'runtime'
16+
const hasRuntimePrefetch = instantConfig?.mode === 'runtime'
1717
if (hasRuntimePrefetch) {
1818
return true
1919
}

0 commit comments

Comments
 (0)