Skip to content

Commit 812996c

Browse files
authored
[CC] Rename "unstable_prefetch" to "unstable_instant" (vercel#89448)
Mostly mechanical rename. Also changes the error page to `errors/invalid-instant-configuration`. I'm not really worried about dangling links here because this is a new API and we don't expect anyone to be using it yet.
1 parent 12f8545 commit 812996c

File tree

64 files changed

+174
-167
lines changed

Some content is hidden

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

64 files changed

+174
-167
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
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 = {
15-
mode: 'static',
14+
export const unstable_instant = {
15+
prefetch: 'static',
1616
}
1717
```
1818

1919
#### Runtime Prefetching
2020

2121
```tsx filename="app/[slug]/page.tsx"
22-
export const unstable_prefetch = {
23-
mode: 'runtime',
22+
export const unstable_instant = {
23+
prefetch: 'runtime',
2424
samples: [
2525
{
2626
cookies: [{ name: 'experiment', value: 'A' }],

errors/next-prerender-runtime-crypto.mdx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ 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 = {
23-
mode: 'runtime',
22+
export const unstable_instant = {
23+
prefetch: 'runtime',
2424
samples: [...],
2525
}
2626

@@ -40,8 +40,8 @@ export default async function Page({ params }) {
4040
After:
4141

4242
```jsx filename="app/page.js"
43-
export const unstable_prefetch = {
44-
mode: 'runtime',
43+
export const unstable_instant = {
44+
prefetch: 'runtime',
4545
samples: [...],
4646
}
4747

@@ -65,8 +65,8 @@ 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 = {
69-
mode: 'runtime',
68+
export const unstable_instant = {
69+
prefetch: 'runtime',
7070
samples: [...],
7171
}
7272

@@ -84,8 +84,8 @@ export default async function Page({ params }) {
8484
After:
8585

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

@@ -107,8 +107,8 @@ 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 = {
111-
mode: 'runtime',
110+
export const unstable_instant = {
111+
prefetch: 'runtime',
112112
samples: [...],
113113
}
114114

@@ -122,8 +122,8 @@ export default async function Page({ params }) {
122122
After:
123123

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

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ 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 = {
27-
mode: 'runtime',
26+
export const unstable_instant = {
27+
prefetch: 'runtime',
2828
samples: [...],
2929
}
3030

@@ -42,8 +42,8 @@ export default async function Page({ params }) {
4242
After:
4343

4444
```jsx filename="app/page.js"
45-
export const unstable_prefetch = {
46-
mode: 'runtime',
45+
export const unstable_instant = {
46+
prefetch: 'runtime',
4747
samples: [...],
4848
}
4949

@@ -67,8 +67,8 @@ 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 = {
71-
mode: 'runtime',
70+
export const unstable_instant = {
71+
prefetch: 'runtime',
7272
samples: [...],
7373
}
7474

@@ -96,8 +96,8 @@ export default async function Page({ params }) {
9696
After:
9797

9898
```jsx filename="app/page.js"
99-
export const unstable_prefetch = {
100-
mode: 'runtime',
99+
export const unstable_instant = {
100+
prefetch: 'runtime',
101101
samples: [...],
102102
}
103103

@@ -136,8 +136,8 @@ 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 = {
140-
mode: 'runtime',
139+
export const unstable_instant = {
140+
prefetch: 'runtime',
141141
samples: [...],
142142
}
143143

@@ -193,8 +193,8 @@ export function RelativeTime({ when }) {
193193
```
194194
195195
```jsx filename="app/page.js"
196-
export const unstable_prefetch = {
197-
mode: 'runtime',
196+
export const unstable_instant = {
197+
prefetch: 'runtime',
198198
samples: [...],
199199
}
200200

@@ -230,8 +230,8 @@ 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 = {
234-
mode: 'runtime',
233+
export const unstable_instant = {
234+
prefetch: 'runtime',
235235
samples: [...],
236236
}
237237

@@ -249,8 +249,8 @@ export default async function Page() {
249249
After:
250250
251251
```jsx filename="app/page.js"
252-
export const unstable_prefetch = {
253-
mode: 'runtime',
252+
export const unstable_instant = {
253+
prefetch: 'runtime',
254254
samples: [...],
255255
}
256256

errors/next-prerender-runtime-random.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ 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 = {
27-
mode: 'runtime',
26+
export const unstable_instant = {
27+
prefetch: 'runtime',
2828
samples: [...],
2929
}
3030

@@ -40,8 +40,8 @@ export default async function Page({ params }) {
4040
After:
4141

4242
```jsx filename="app/page.js"
43-
export const unstable_prefetch = {
44-
mode: 'runtime',
43+
export const unstable_instant = {
44+
prefetch: 'runtime',
4545
samples: [...],
4646
}
4747

@@ -68,8 +68,8 @@ 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 = {
72-
mode: 'runtime',
71+
export const unstable_instant = {
72+
prefetch: 'runtime',
7373
samples: [...],
7474
}
7575

@@ -85,8 +85,8 @@ export default async function Page({ params }) {
8585
After:
8686

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

packages/next/errors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,5 +987,6 @@
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",
989989
"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": "Loaded static props were from an outdated deployment, forcing a hard reload"
990+
"989": "Loaded static props were from an outdated deployment, forcing a hard reload",
991+
"990": "Page \"%s\" cannot use \\`export const unstable_instant = ...\\` without enabling \\`cacheComponents\\`."
991992
}

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: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,59 +21,65 @@ const RuntimeSampleSchema = z
2121
})
2222
.strict()
2323

24-
const StaticPrefetchSchema = z
24+
const InstantConfigStaticSchema = z
2525
.object({
26-
mode: z.literal('static'),
26+
prefetch: 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({
34-
mode: z.literal('runtime'),
34+
prefetch: z.literal('runtime'),
3535
samples: z.array(RuntimeSampleSchema).min(1),
3636
from: z.array(z.string()).optional(),
3737
expectUnableToVerify: z.boolean().optional(),
3838
})
3939
.strict()
4040

41-
const PrefetchSchema = z.discriminatedUnion('mode', [
42-
StaticPrefetchSchema,
43-
RuntimePrefetchSchema,
41+
const InstantConfigSchema = z.discriminatedUnion('prefetch', [
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 {
55-
mode: string
56+
interface __GenericInstantConfig {
57+
prefetch: string
5658
samples?: Array<WideRuntimeSample>
5759
from?: string[]
5860
expectUnableToVerify?: boolean
5961
}
60-
interface StaticPrefetch {
61-
mode: 'static'
62+
63+
interface InstantConfigStatic {
64+
prefetch: 'static'
6265
from?: string[]
6366
expectUnableToVerify?: boolean
6467
}
65-
interface RuntimePrefetch {
66-
mode: 'runtime'
68+
69+
interface InstantConfigRuntime {
70+
prefetch: '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 \`prefetch: "static"\` or \`prefetch: "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?.prefetch === 'runtime'
233233

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

0 commit comments

Comments
 (0)