@rsc-kit/mcp 0.40.0 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/recipes.js +37 -20
- package/dist/recipes.js.map +1 -1
- package/guides/admin-plugins.md +206 -6
- package/guides/api-routes.md +159 -215
- package/guides/authorization.md +103 -114
- package/guides/backend-answered-pages.md +301 -250
- package/guides/bap-vs-inertia.md +67 -25
- package/guides/blueprints.md +307 -174
- package/guides/bun.md +42 -25
- package/guides/caching.md +46 -49
- package/guides/coming-from-inertia.md +5 -5
- package/guides/commands.md +251 -200
- package/guides/connection.md +50 -54
- package/guides/content-security-policy.md +133 -84
- package/guides/domains.md +190 -149
- package/guides/edge-caching.md +242 -268
- package/guides/emails.md +96 -45
- package/guides/errors.md +116 -137
- package/guides/feature-flags.md +100 -30
- package/guides/file-uploads.md +101 -26
- package/guides/fonts.md +139 -110
- package/guides/forms.md +520 -538
- package/guides/images.md +87 -28
- package/guides/index.json +13 -33
- package/guides/instrumentation.md +134 -95
- package/guides/isr.md +3 -3
- package/guides/live-data-in-production.md +695 -0
- package/guides/live-data.md +170 -839
- package/guides/mcp.md +83 -59
- package/guides/metadata.md +124 -179
- package/guides/navigation.md +118 -147
- package/guides/no-javascript.md +49 -57
- package/guides/offline.md +118 -153
- package/guides/openapi.md +100 -35
- package/guides/pages.md +160 -50
- package/guides/ppr.md +178 -256
- package/guides/pwa.md +251 -218
- package/guides/queries.md +171 -300
- package/guides/react-compiler.md +90 -50
- package/guides/redirects.md +141 -177
- package/guides/response-headers.md +76 -74
- package/guides/route-interception.md +112 -111
- package/guides/routing.md +216 -322
- package/guides/sections.md +63 -66
- package/guides/seo-files.md +127 -65
- package/guides/server-actions.md +285 -357
- package/guides/static-generation.md +131 -199
- package/guides/testing.md +272 -150
- package/guides/third-party-scripts.md +94 -47
- package/guides/typed-routes.md +115 -113
- package/guides/url-validation.md +113 -61
- package/guides/validation.md +53 -62
- package/guides/view-transitions.md +159 -132
- package/guides/where-it-runs.md +226 -162
- package/package.json +2 -2
- package/guides/admin.md +0 -520
- package/guides/deployment.md +0 -598
- package/guides/go.md +0 -538
- package/guides/laravel.md +0 -786
- package/guides/your-own-backend.md +0 -587
package/guides/ppr.md
CHANGED
|
@@ -2,204 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
> Storing what every visitor sees the same, and rendering the rest per request.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
There is nothing to switch on, and no mode to pick. Every route goes through
|
|
10
|
-
the same probe, and this is one of the things it can find.
|
|
11
|
-
|
|
12
|
-
## How the build decides
|
|
13
|
-
|
|
14
|
-
```text
|
|
15
|
-
Build time
|
|
16
|
-
→ the page is rendered with a budget
|
|
17
|
-
→ anything still waiting when the budget expires is postponed
|
|
18
|
-
→ React has already flushed what did not need the request: layouts, static
|
|
19
|
-
markup, and the Suspense fallbacks standing in for the rest
|
|
20
|
-
→ that markup is stored as the route's shell, and beside it, where it stopped
|
|
21
|
-
Request time
|
|
22
|
-
→ the shell is served straight from disk — fast, no render
|
|
23
|
-
→ the render is picked up from where it stopped, against data that exists now
|
|
24
|
-
→ only the unfinished boundaries are written, onto the same response
|
|
25
|
-
→ a script React emits beside each one moves it into place as the HTML parses
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
**Postponed, not merely abandoned.** The difference matters. Aborting a render
|
|
29
|
-
gives you the bytes that flushed and nothing else — React has no record of
|
|
30
|
-
where it got to, so the holes can only be filled later by the browser.
|
|
31
|
-
Postponing keeps that record, which is what lets the boundaries be finished
|
|
32
|
-
at the origin and arrive with the document.
|
|
33
|
-
|
|
34
|
-
So the content is in the first response. It appears without waiting for the app
|
|
35
|
-
bundle or for hydration — on a slow connection, the difference between a spinner
|
|
36
|
-
and a page — and it is in the HTML a crawler reads.
|
|
37
|
-
|
|
38
|
-
This is not the same as working with scripting off: with JavaScript disabled the
|
|
39
|
-
fallbacks stay.
|
|
40
|
-
|
|
41
|
-
If anything goes wrong — the engine cannot resume, or the render fails — the
|
|
42
|
-
shell is served on its own and the client fills the boundaries when it
|
|
43
|
-
hydrates, exactly as it did before any of this existed. A slower hole, never a
|
|
44
|
-
wrong page.
|
|
45
|
-
|
|
46
|
-
A page is rendered **once per visit**. Hydrating needs the page as a payload as
|
|
47
|
-
well as HTML, and the render's payload streams into the document beside the
|
|
48
|
-
HTML — a slow region's with its HTML — so the browser never asks for it
|
|
49
|
-
separately. The page's queries run once, its backend is called once, and the
|
|
50
|
-
tree the browser hydrates against is the one its HTML came from. A page the
|
|
51
|
-
build stored whole fetches its stored payload, which costs no render.
|
|
52
|
-
|
|
53
|
-
The shell is stored per route **pattern**, not per url. `/posts/[slug]` has one
|
|
54
|
-
shell serving every slug, because everything that varies by slug is behind a
|
|
55
|
-
boundary the request fills. That includes the metadata: a route with a
|
|
56
|
-
`generateMetadata` streams it under a boundary of its own, so the shell has a
|
|
57
|
-
hole where the title goes and the request fills it with the page's real
|
|
58
|
-
title. Nothing is looked up before the shell is sent. A route with only
|
|
59
|
-
static `metadata` has it in the shell.
|
|
60
|
-
|
|
61
|
-
## A shell and the server that finishes it are one build
|
|
62
|
-
|
|
63
|
-
A replay matches a slot by component **name** — `displayName`, then `name` —
|
|
64
|
-
so anything that renames a component between the build and the server breaks
|
|
65
|
-
every slot below it. A bundler run over the build's output does exactly that
|
|
66
|
-
when it merges module scopes: two different components of one name is
|
|
67
|
-
ordinary (a wrapper named after the primitive it wraps), and the merge renames
|
|
68
|
-
one of them.
|
|
69
|
-
|
|
70
|
-
The build pins every component's name as it is in the build's output, as a
|
|
71
|
-
`displayName` written into the server bundle. Whatever a later bundler calls
|
|
72
|
-
the binding, React reads the name the shell recorded — which is why a page
|
|
73
|
-
compiled into a single binary is resumed like any other, with no flag.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
A postponed state names the components React has to find when it replays, and
|
|
77
|
-
a name is whatever that build's minifier assigned. Resumed against a different
|
|
78
|
-
bundle, the same component answers to something else:
|
|
79
|
-
|
|
80
|
-
```text
|
|
81
|
-
Expected the resume to render <J> in this slot but instead it rendered <J2>.
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Two names for one component is the fingerprint of two builds. Every shell is
|
|
85
|
-
stamped with the build that froze it, and a host that finds a shell from
|
|
86
|
-
another build serves it but renders the page whole instead of resuming it,
|
|
87
|
-
with a line in the log saying so.
|
|
88
|
-
|
|
89
|
-
How they drift apart in practice: a Docker layer, a CI cache or a volume that
|
|
90
|
-
keeps a previous prerender output while the server bundle is rebuilt. Build
|
|
91
|
-
both together, or clear the output directory between builds.
|
|
92
|
-
|
|
93
|
-
## A shell for a pattern is one shape
|
|
94
|
-
|
|
95
|
-
A route with params that listed no urls is frozen **once**, for the pattern —
|
|
96
|
-
the build has no url, so every param is a placeholder and anything that reads
|
|
97
|
-
one postpones. What resumes it renders the tree the shell froze and fills the
|
|
98
|
-
holes with the real values.
|
|
99
|
-
|
|
100
|
-
So the shape above a boundary cannot depend on a param:
|
|
101
|
-
|
|
102
|
-
```tsx
|
|
103
|
-
// Refuses to resume: two different components in one slot
|
|
104
|
-
const { id } = await params
|
|
105
|
-
return id === 'new' ? <CreateForm /> : <Record />
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
React replays the postponed tree by position and type. A different component
|
|
109
|
-
in a slot ends the replay:
|
|
110
|
-
|
|
111
|
-
```text
|
|
112
|
-
Expected the resume to render <Record> in this slot but instead it
|
|
113
|
-
rendered <CreateForm>. The tree doesn't match so React will fallback
|
|
114
|
-
to client rendering.
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
Every hole then falls back to client rendering, which arrives as a page whose
|
|
118
|
-
buttons do nothing.
|
|
119
|
-
|
|
120
|
-
The engine holds up its end: the resume is given the placeholders the shell
|
|
121
|
-
was frozen with, and the real params separately, so a component that reads
|
|
122
|
-
them is inside a hole by construction. What an app must not do is branch on a
|
|
123
|
-
param **above** its boundary. Put the branch inside the `<Suspense>`, or give
|
|
124
|
-
the route a `generateStaticParams` so each url is frozen as itself.
|
|
125
|
-
|
|
126
|
-
## What makes a page dynamic
|
|
127
|
-
|
|
128
|
-
Anything the build cannot know:
|
|
129
|
-
|
|
130
|
-
- **`await params`** — the url, for a route that has not listed its urls
|
|
131
|
-
- **`usePathname()`** in a client component, for the same route, answers
|
|
132
|
-
`""` in that shell: one shell serves every url it matches, so no link is
|
|
133
|
-
active and a breadcrumb is empty until hydration, when the hook moves to
|
|
134
|
-
the browser's url on its own. The payload such a document boots from
|
|
135
|
-
agrees with the shell, so there is no mismatch to repair. Where the url is
|
|
136
|
-
known — a listed url, a client navigation — the hook answers as always.
|
|
137
|
-
- **`await searchParams`** — the query string
|
|
138
|
-
- **`await headers()` / `await cookies()`** — the request
|
|
139
|
-
- **a host call**, on a host that has one
|
|
140
|
-
- **slow work of your own** that outlasts the budget
|
|
141
|
-
|
|
142
|
-
All of them behave the same way: the read suspends, the nearest fallback above
|
|
143
|
-
it goes into the shell, and the real value arrives per request.
|
|
144
|
-
|
|
145
|
-
## Where to put the boundaries
|
|
146
|
-
|
|
147
|
-
Only content inside a `<Suspense>` boundary can stream. Content above every
|
|
148
|
-
boundary has to finish before anything paints — which is the difference between
|
|
149
|
-
a route the build can store and one it refuses.
|
|
5
|
+
Most pages have markup that is the same for everybody and data that isn't. The
|
|
6
|
+
build stores the first as a shell, and the rest is rendered per request and
|
|
7
|
+
streamed into the same response:
|
|
150
8
|
|
|
151
9
|
```tsx title="src/app/posts/[slug]/page.tsx"
|
|
152
10
|
import { Suspense } from 'react';
|
|
153
|
-
import { findPost } from '../../../data';
|
|
154
|
-
|
|
155
|
-
async function Body({ params }: { params: Promise<{ slug: string }> }) {
|
|
156
|
-
const { slug } = await params;
|
|
157
|
-
const post = await findPost(slug);
|
|
158
|
-
|
|
159
|
-
return <article><h1>{post.title}</h1><p>{post.body}</p></article>;
|
|
160
|
-
}
|
|
161
11
|
|
|
162
12
|
export default function PostPage({ params }: { params: Promise<{ slug: string }> }) {
|
|
163
13
|
return (
|
|
164
|
-
<
|
|
165
|
-
<
|
|
166
|
-
|
|
14
|
+
<main>
|
|
15
|
+
<nav>All posts</nav>
|
|
16
|
+
<Suspense fallback={<Skeleton className="h-40" />}>
|
|
17
|
+
<Post params={params} />
|
|
18
|
+
</Suspense>
|
|
19
|
+
</main>
|
|
167
20
|
);
|
|
168
21
|
}
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
`Body` is still waiting when the budget expires, so the shell holds the
|
|
172
|
-
fallback. At request time the slug resolves and React replaces it.
|
|
173
|
-
|
|
174
|
-
### A fallback that has painted stays up for 300 ms
|
|
175
22
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
placeholder and content on a slow connection.
|
|
180
|
-
|
|
181
|
-
A stored shell and its holes come in one response, the holes a moment after
|
|
182
|
-
the shell. When the data is fast, it arrives after the shell has painted but
|
|
183
|
-
inside those 300 ms, so the fallback shows for the full 300 ms anyway. On an
|
|
184
|
-
installed app that is a flash of placeholders on every launch.
|
|
23
|
+
async function Post({ params }: { params: Promise<{ slug: string }> }) {
|
|
24
|
+
const { slug } = await params;
|
|
25
|
+
const post = await findPost(slug);
|
|
185
26
|
|
|
186
|
-
|
|
27
|
+
return <article><h1>{post.title}</h1><p>{post.body}</p></article>;
|
|
28
|
+
}
|
|
29
|
+
```
|
|
187
30
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
size and the same colour with the numbers left blank. Then 300 ms of it
|
|
193
|
-
reads as the page, not as a flash, and nothing moves when the data lands.
|
|
194
|
-
- **Leave out `animate-pulse` for anything that is usually gone quickly.** A
|
|
195
|
-
pulse is what makes a short fallback look like a flash.
|
|
31
|
+
The nav and the skeleton are stored at build time and served from disk. The
|
|
32
|
+
post is rendered when someone asks for it. There is nothing to switch on: every
|
|
33
|
+
route is rendered by the build, and this is what it stores when part of a page
|
|
34
|
+
waits.
|
|
196
35
|
|
|
197
|
-
##
|
|
36
|
+
## Where to put the boundaries
|
|
198
37
|
|
|
199
|
-
Write the page as a synchronous component.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
own `<Suspense>`, with a skeleton the shape of what it stands for:
|
|
38
|
+
Write the page as a plain synchronous component. Put each read in its own async
|
|
39
|
+
component, under its own `<Suspense>`, with a skeleton the shape of what it
|
|
40
|
+
stands for:
|
|
203
41
|
|
|
204
42
|
```tsx title="src/app/integrations/shopify/page.tsx"
|
|
205
43
|
import { Suspense } from 'react';
|
|
@@ -238,50 +76,68 @@ export async function ConnectionSlot() {
|
|
|
238
76
|
}
|
|
239
77
|
```
|
|
240
78
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
- **
|
|
244
|
-
|
|
245
|
-
- **
|
|
246
|
-
|
|
247
|
-
- **The skeleton can be exact.** It stands for one known thing — a list of
|
|
248
|
-
one row, a button — so nothing moves when the content lands.
|
|
79
|
+
- **The visitor sees the page, not a placeholder of it.** The heading and copy
|
|
80
|
+
are in the shell. Only the parts that wait show a skeleton.
|
|
81
|
+
- **Each part arrives when it's ready.** A fast read isn't held back by a slow
|
|
82
|
+
one beside it.
|
|
83
|
+
- **The skeleton can be exact.** It stands for one known thing, so nothing
|
|
84
|
+
moves when the content lands.
|
|
249
85
|
- **A slot is self-contained.** It does its own read and its own permission
|
|
250
|
-
check, so it can move to another page, or be
|
|
251
|
-
[section](/guides/sections)
|
|
86
|
+
check, so it can move to another page, or be refreshed as a
|
|
87
|
+
[section](/guides/sections).
|
|
88
|
+
|
|
89
|
+
Only content inside a `<Suspense>` boundary can stream. Content above every
|
|
90
|
+
boundary has to finish before anything paints, and a page with nothing to
|
|
91
|
+
paint can't be stored.
|
|
252
92
|
|
|
253
|
-
##
|
|
93
|
+
## What makes a page dynamic
|
|
254
94
|
|
|
255
|
-
|
|
256
|
-
that is one read and nothing else, such as a detail page whose skeleton really
|
|
257
|
-
is the page. Elsewhere it costs more than it saves:
|
|
95
|
+
Anything the build can't know:
|
|
258
96
|
|
|
259
|
-
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
- **
|
|
263
|
-
|
|
264
|
-
- **A status decided inside it is not the response's.** A page under
|
|
265
|
-
`loading.tsx` that calls `notFound()` or `redirect()`, or reads a backend
|
|
266
|
-
that answers 404, may already have sent its shell with a 200. Whether a page
|
|
267
|
-
exists for this visitor is a check for [`middleware.ts`](/guides/authorization),
|
|
268
|
-
which runs before anything is sent.
|
|
269
|
-
- **It does not cover its layout.** It sits below the layout beside it, so a
|
|
270
|
-
layout that waits — on its params, on the session — needs a `<Suspense>` of
|
|
271
|
-
its own inside the layout.
|
|
272
|
-
- **At the root it catches mistakes.** A root `loading.tsx` wraps every page,
|
|
273
|
-
so a page waiting in the wrong place is stored behind the app-wide
|
|
274
|
-
fallback, and the build can only warn. See below.
|
|
97
|
+
- **`await params`**, for a route that hasn't listed its URLs
|
|
98
|
+
- **`await searchParams`**, the query string
|
|
99
|
+
- **`await headers()` and `await cookies()`**, the request
|
|
100
|
+
- **a host call**, on a host that has one
|
|
101
|
+
- **slow work of your own** that outlasts the build's time budget
|
|
275
102
|
|
|
276
|
-
|
|
103
|
+
Each one suspends, the nearest fallback above it goes into the shell, and the
|
|
104
|
+
real value arrives per request.
|
|
277
105
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
106
|
+
`usePathname()` in a client component answers `""` in a shell for a route that
|
|
107
|
+
hasn't listed its URLs: one shell serves every URL it matches, so no link is
|
|
108
|
+
active and a breadcrumb is empty until hydration. In the browser the hook moves
|
|
109
|
+
to the real URL on its own, with no mismatch to repair. Where the URL is
|
|
110
|
+
known (a listed URL, a client navigation) it answers as always.
|
|
111
|
+
|
|
112
|
+
A page whose data resolves inside the budget is stored **whole**, even one that
|
|
113
|
+
called `fetch()`. To make a page reflect the world at request time, read the
|
|
114
|
+
request; there is no flag.
|
|
115
|
+
|
|
116
|
+
## Making fallbacks look right
|
|
117
|
+
|
|
118
|
+
Once a fallback has been on screen, React holds back the content that replaces
|
|
119
|
+
it until 300 ms after that paint, even when the content arrived sooner. This is
|
|
120
|
+
React's rule, not rsc-kit's. A stored shell and its holes arrive in one
|
|
121
|
+
response, so with fast data the fallback often shows for the full 300 ms. On an
|
|
122
|
+
installed app that's a flash of placeholders on every launch.
|
|
123
|
+
|
|
124
|
+
- **Put a boundary only where the wait is real.** Data that is always back in a
|
|
125
|
+
few milliseconds doesn't need a fallback. Rendered directly, it's in the
|
|
126
|
+
first paint.
|
|
127
|
+
- **Make the fallback the shape of the content.** The same card, size and
|
|
128
|
+
colour with the numbers left blank reads as the page, not a flash.
|
|
129
|
+
- **Leave out `animate-pulse` for anything usually gone quickly.** A pulse is
|
|
130
|
+
what makes a short fallback look like a flash.
|
|
131
|
+
|
|
132
|
+
## Using loading.tsx
|
|
133
|
+
|
|
134
|
+
Put a `loading.tsx` beside a page and the build wraps that page in
|
|
135
|
+
`<Suspense fallback={<Loading />}>` for you, so the page can await at its top
|
|
136
|
+
level:
|
|
281
137
|
|
|
282
138
|
```tsx title="src/app/posts/[slug]/loading.tsx"
|
|
283
139
|
export default function Loading() {
|
|
284
|
-
return <div className="h-6 w-50
|
|
140
|
+
return <div className="h-6 w-50 rounded-lg bg-zinc-800" />;
|
|
285
141
|
}
|
|
286
142
|
```
|
|
287
143
|
|
|
@@ -293,30 +149,37 @@ export default async function PostPage({ params }: { params: Promise<{ slug: str
|
|
|
293
149
|
}
|
|
294
150
|
```
|
|
295
151
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
one chain stack as nested boundaries:
|
|
152
|
+
It fits a page that is one read and nothing else, such as a detail page whose
|
|
153
|
+
skeleton really is the page. Like `layout.tsx`, the nearest `loading.tsx` wins,
|
|
154
|
+
and several in one chain nest:
|
|
300
155
|
|
|
301
156
|
```text
|
|
302
157
|
src/app/
|
|
303
|
-
layout.tsx
|
|
304
|
-
loading.tsx fallback for everything without a closer one
|
|
305
158
|
docs/
|
|
306
159
|
loading.tsx fallback for /docs/*
|
|
307
160
|
[slug]/
|
|
308
161
|
page.tsx uses docs/loading.tsx
|
|
309
|
-
dashboard/
|
|
310
|
-
page.tsx uses app/loading.tsx
|
|
311
162
|
```
|
|
312
163
|
|
|
313
|
-
|
|
164
|
+
Elsewhere, prefer `<Suspense>` in the page:
|
|
314
165
|
|
|
315
|
-
It
|
|
316
|
-
|
|
317
|
-
|
|
166
|
+
- **It hides what the page already knows.** The heading and copy wait with the
|
|
167
|
+
data.
|
|
168
|
+
- **The slowest read decides for all of them.** Everything under the one
|
|
169
|
+
boundary paints when the last of it is ready.
|
|
170
|
+
- **A status decided inside it isn't the response's.** A page under
|
|
171
|
+
`loading.tsx` that calls `notFound()` or `redirect()`, or reads a backend
|
|
172
|
+
that answers 404, may already have sent its shell with a 200. Decide whether
|
|
173
|
+
a page exists for this visitor in [`middleware.ts`](/guides/authorization),
|
|
174
|
+
which runs before anything is sent.
|
|
175
|
+
- **It doesn't cover its layout.** It sits below the layout beside it, so a
|
|
176
|
+
layout that waits needs a `<Suspense>` of its own.
|
|
177
|
+
|
|
178
|
+
### Don't put one at the root
|
|
318
179
|
|
|
319
|
-
|
|
180
|
+
A root `loading.tsx` wraps every page, so a page that waits in the wrong place
|
|
181
|
+
is still stored, behind the fallback the whole app shares. It looks exactly
|
|
182
|
+
like a page whose boundary is in the right place, so the build warns:
|
|
320
183
|
|
|
321
184
|
```text
|
|
322
185
|
◐ /locale
|
|
@@ -324,20 +187,38 @@ So the build says so:
|
|
|
324
187
|
shares is standing in for this page. Put a boundary where the waiting is.
|
|
325
188
|
```
|
|
326
189
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
costs nothing for the rest.
|
|
190
|
+
The build finds these by rendering the route a second time without the root
|
|
191
|
+
fallback, and only for routes with no closer `loading.tsx`. Moving the boundary
|
|
192
|
+
to where the waiting is fixes it.
|
|
331
193
|
|
|
332
|
-
|
|
333
|
-
is shared: every page in the app shows the same fallback while this one waits,
|
|
334
|
-
and the fallback cannot say anything about what is loading. Moving the boundary
|
|
335
|
-
to where the waiting is fixes both.
|
|
194
|
+
## Branching on a param
|
|
336
195
|
|
|
337
|
-
|
|
196
|
+
A route with params that listed no URLs has **one** shell for every URL, frozen
|
|
197
|
+
with placeholders. The shape above a boundary can't depend on a param:
|
|
338
198
|
|
|
339
|
-
|
|
340
|
-
|
|
199
|
+
```tsx
|
|
200
|
+
// Refuses to resume: two different components in one slot
|
|
201
|
+
const { id } = await params
|
|
202
|
+
return id === 'new' ? <CreateForm /> : <Record />
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
React fills in the shell by position and component type, and a different
|
|
206
|
+
component in a slot ends it:
|
|
207
|
+
|
|
208
|
+
```text
|
|
209
|
+
Expected the resume to render <Record> in this slot but instead it
|
|
210
|
+
rendered <CreateForm>. The tree doesn't match so React will fallback
|
|
211
|
+
to client rendering.
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Every hole then falls back to client rendering, and the page's buttons do
|
|
215
|
+
nothing until it hydrates. Put the branch inside the `<Suspense>`, or give the
|
|
216
|
+
route a `generateStaticParams` so each URL is frozen as itself.
|
|
217
|
+
|
|
218
|
+
## When the build can't store a route
|
|
219
|
+
|
|
220
|
+
If nothing painted before the page blocked, there is no shell to store, and
|
|
221
|
+
the build fails:
|
|
341
222
|
|
|
342
223
|
```text
|
|
343
224
|
Some routes could not be prerendered:
|
|
@@ -351,19 +232,60 @@ Put the part that waits inside <Suspense>, or add a loading.tsx beside
|
|
|
351
232
|
the page, so there is something to store while the rest arrives.
|
|
352
233
|
```
|
|
353
234
|
|
|
354
|
-
|
|
355
|
-
the build cannot store has its boundary in the wrong place; moving the boundary
|
|
356
|
-
is the fix.
|
|
235
|
+
There is no way to declare it away. Moving the boundary is the fix.
|
|
357
236
|
|
|
358
|
-
##
|
|
237
|
+
## Changing the time budget
|
|
359
238
|
|
|
360
|
-
`RSC_PPR_TIMEOUT_MS` sets
|
|
361
|
-
pages be stored whole; lowering it
|
|
239
|
+
`RSC_PPR_TIMEOUT_MS` sets how long the build waits on each page. The default is
|
|
240
|
+
2 seconds. Raising it lets slow pages be stored whole; lowering it turns more
|
|
241
|
+
of them into shells.
|
|
362
242
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
243
|
+
Pages don't wait in line for it. A page that has rendered what it can gives its
|
|
244
|
+
place to the next, so a site of hundreds of shells costs about one budget, not
|
|
245
|
+
one each.
|
|
366
246
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
247
|
+
## Deploying the shell and the server together
|
|
248
|
+
|
|
249
|
+
A shell can only be finished by the server bundle from the same build. Every
|
|
250
|
+
shell is stamped with its build, and a server that finds a shell from another
|
|
251
|
+
build serves it but renders the page whole instead, with a line in the log.
|
|
252
|
+
They usually drift apart through a Docker layer, CI cache or volume that keeps
|
|
253
|
+
an old prerender output while the server is rebuilt. Build both together, or
|
|
254
|
+
clear the output directory between builds.
|
|
255
|
+
|
|
256
|
+
## How it works
|
|
257
|
+
|
|
258
|
+
```text
|
|
259
|
+
Build time
|
|
260
|
+
→ the page is rendered with a budget
|
|
261
|
+
→ anything still waiting when the budget expires is postponed
|
|
262
|
+
→ React has already flushed what did not need the request: layouts, static
|
|
263
|
+
markup, and the Suspense fallbacks standing in for the rest
|
|
264
|
+
→ that markup is stored as the route's shell, and beside it, where it stopped
|
|
265
|
+
Request time
|
|
266
|
+
→ the shell is served straight from disk — fast, no render
|
|
267
|
+
→ the render is picked up from where it stopped, against data that exists now
|
|
268
|
+
→ only the unfinished boundaries are written, onto the same response
|
|
269
|
+
→ a script React emits beside each one moves it into place as the HTML parses
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
- **Postponed, not abandoned.** An aborted render keeps only the bytes that
|
|
273
|
+
flushed. A postponed one keeps a record of where it got to, which is what
|
|
274
|
+
lets the boundaries be finished on the server and arrive with the document.
|
|
275
|
+
The content is in the first response, before the app bundle or hydration,
|
|
276
|
+
and in the HTML a crawler reads. With JavaScript disabled, the fallbacks
|
|
277
|
+
stay.
|
|
278
|
+
- **A slower hole, never a wrong page.** If the resume fails, the shell is
|
|
279
|
+
served on its own and the client fills the boundaries when it hydrates.
|
|
280
|
+
- **Rendered once per visit.** The payload the browser hydrates from streams
|
|
281
|
+
into the document beside the HTML, so the page's queries and backend run
|
|
282
|
+
once. A page stored whole fetches its stored payload, which costs no render.
|
|
283
|
+
- **One shell per pattern.** `/posts/[slug]` has one shell for every slug. A
|
|
284
|
+
`generateMetadata` streams under a boundary of its own, so the shell has a
|
|
285
|
+
hole where the title goes; a route with static `metadata` has it in the
|
|
286
|
+
shell.
|
|
287
|
+
- **Component names are pinned.** The resume matches a slot by component name
|
|
288
|
+
(`displayName`, then `name`). The build writes each component's name into
|
|
289
|
+
the server bundle as a `displayName`, so a later bundler that renames
|
|
290
|
+
bindings, or a page compiled into a single binary, still resumes. Two names
|
|
291
|
+
for one component, as in `Expected the resume to render <J> in this slot but instead it rendered <J2>`, is the fingerprint of two builds.
|