@k8ordo/framework 2.3.1 → 4.0.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/README.md +28 -13
- package/dist/cli.mjs +3 -3
- package/dist/generated.d.mts +13 -13
- package/dist/headers-BxB_jJVk.mjs +73 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +1 -1
- package/dist/paths-type-DXpmjaOr.d.mts +43 -0
- package/dist/runtime/app-router.mjs +21 -8
- package/dist/runtime/browser-payloads.mjs +1 -1
- package/dist/runtime/client-files.d.mts +6 -5
- package/dist/runtime/client-files.mjs +17 -9
- package/dist/runtime/client-ready.d.mts +7 -1
- package/dist/runtime/client-ready.mjs +2 -1
- package/dist/runtime/cookies.d.mts +2 -0
- package/dist/runtime/cookies.mjs +2 -1
- package/dist/runtime/ended.d.mts +7 -0
- package/dist/runtime/ended.mjs +14 -0
- package/dist/runtime/entry.browser.mjs +1 -1
- package/dist/runtime/entry.rsc.d.mts +38 -2
- package/dist/runtime/entry.rsc.mjs +97 -31
- package/dist/runtime/entry.ssr.d.mts +7 -1
- package/dist/runtime/entry.ssr.mjs +12 -6
- package/dist/runtime/guard.d.mts +15 -10
- package/dist/runtime/guard.mjs +8 -2
- package/dist/runtime/mount.mjs +1 -1
- package/dist/runtime/page-boundary.mjs +2 -2
- package/dist/runtime/params.d.mts +5 -4
- package/dist/runtime/params.mjs +2 -2
- package/dist/runtime/payload.d.mts +19 -4
- package/dist/runtime/payload.mjs +20 -5
- package/dist/runtime/prefetch.d.mts +29 -8
- package/dist/runtime/prefetch.mjs +95 -24
- package/dist/runtime/redirect.d.mts +13 -7
- package/dist/runtime/redirect.mjs +25 -9
- package/dist/runtime/request-scope.d.mts +37 -2
- package/dist/runtime/request-scope.mjs +60 -3
- package/dist/runtime/request.d.mts +6 -1
- package/dist/runtime/request.mjs +7 -2
- package/dist/runtime/route.d.mts +4 -2
- package/dist/runtime/route.mjs +13 -5
- package/dist/runtime/server.d.mts +5 -5
- package/dist/runtime/server.mjs +2 -2
- package/dist/runtime/shell.d.mts +2 -1
- package/dist/serve.d.mts +4 -0
- package/dist/serve.mjs +29 -14
- package/dist/static-Be3xIqd8.d.mts +62 -0
- package/dist/{static-file-BAjwBMMl.mjs → static-file-BS-WEiwu.mjs} +311 -134
- package/dist/{static-host-B-1fAfAw.mjs → static-host-tIDLqV8c.mjs} +1 -1
- package/dist/vercel.d.mts +18 -1
- package/dist/vercel.mjs +131 -19
- package/dist/vite.d.mts +6 -3
- package/dist/vite.mjs +366 -156
- package/docs/GUIDE.md +173 -46
- package/docs/llms.txt +129 -65
- package/docs/references/actions.md +14 -5
- package/docs/references/boundaries.md +23 -2
- package/docs/references/csp.md +91 -2
- package/docs/references/deploy.md +154 -25
- package/docs/references/errors.md +57 -12
- package/docs/references/guards.md +100 -29
- package/docs/references/params.md +234 -126
- package/docs/references/routing.md +358 -75
- package/package.json +18 -13
- package/dist/shared-dir-CNXFRZgP.mjs +0 -9
- package/dist/static-DnbgGIoy.d.mts +0 -61
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
What a route parameter arrives as, and — under `mode: 'static'` — how the
|
|
4
4
|
build learns which values to render, and what answers the ones it did not.
|
|
5
5
|
Under `mode: 'server'` a value comes with the request and needs no list.
|
|
6
|
+
A `[...name]` directory's parameter arrives as an array of segments
|
|
7
|
+
([Rest parameters](#rest-parameters)), under `mode: 'server'` only.
|
|
6
8
|
|
|
7
9
|
## Parameters with a schema
|
|
8
10
|
|
|
@@ -69,94 +71,195 @@ be a lie, and a not-found receives strings for the same reason. A layout that
|
|
|
69
71
|
wants the parsed value beside the page's parses it itself, or declares the
|
|
70
72
|
schema and lets the pages below it receive the result.
|
|
71
73
|
|
|
74
|
+
## Rest parameters
|
|
75
|
+
|
|
76
|
+
Server mode only. The parameter of a `[...name]` directory
|
|
77
|
+
([Rest parameters](routing.md#rest-parameters)) arrives as the segments it
|
|
78
|
+
took, one or more, each decoded — `readonly string[]`, where a `[name]`
|
|
79
|
+
gives a string:
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
// src/routes/docs/[...path]/page.tsx
|
|
83
|
+
import type { PageProps } from '@k8ordo/framework';
|
|
84
|
+
|
|
85
|
+
export default function DocPage({ params }: PageProps<'/docs/:path+'>) {
|
|
86
|
+
return <h1>{params.path.join(' / ')}</h1>; // /docs/guide/intro → guide / intro
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
A `paramsSchema` receives that array and validates it as any other value: a
|
|
91
|
+
refusal is a pathname the directory does not answer, and what the schema
|
|
92
|
+
returns is what the page receives and what a link takes.
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
// src/routes/docs/[...path]/page.tsx
|
|
96
|
+
import type { PageProps } from '@k8ordo/framework';
|
|
97
|
+
import * as z from 'zod/mini';
|
|
98
|
+
|
|
99
|
+
const SLUG = /^[a-z0-9-]+$/u;
|
|
100
|
+
|
|
101
|
+
export const paramsSchema = z.object({
|
|
102
|
+
path: z.array(z.string().check(z.regex(SLUG))).check(z.maxLength(4)),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
export default function DocPage({ params }: PageProps<'/docs/:path+'>) {
|
|
106
|
+
return <h1>{params.path.join(' / ')}</h1>;
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`/docs/Guide` and `/docs/a/b/c/d/e` are then pathnames nothing answers here,
|
|
111
|
+
and go on to the nearest `not-found.tsx`. The layout in the directory, a
|
|
112
|
+
`guard.ts` and the `not-found.tsx` above receive the array as the pathname
|
|
113
|
+
carried it, as they receive every parameter.
|
|
114
|
+
|
|
115
|
+
`mode: 'static'` refuses the directory itself, so none of the sections below
|
|
116
|
+
— `paths.ts`, `fallback.tsx` — applies to one.
|
|
117
|
+
|
|
72
118
|
## Routes with parameters
|
|
73
119
|
|
|
74
120
|
Static mode only. A build into files cannot invent parameter values, so it
|
|
75
|
-
asks for them
|
|
121
|
+
asks the parameter's own directory for them — a `paths.ts`, one more route
|
|
122
|
+
file:
|
|
76
123
|
|
|
77
124
|
```ts
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
125
|
+
// src/routes/products/[id]/paths.ts
|
|
126
|
+
import type { Paths } from '@k8ordo/framework';
|
|
127
|
+
|
|
128
|
+
import { listProducts } from '../../../lib/catalog.server';
|
|
129
|
+
|
|
130
|
+
const paths: Paths<'/products/:id'> = async () =>
|
|
131
|
+
(await listProducts()).map((product) => product.id);
|
|
132
|
+
|
|
133
|
+
export default paths;
|
|
85
134
|
```
|
|
86
135
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
136
|
+
Its default export is a function returning the values the directory's
|
|
137
|
+
parameter takes: an array, or a promise of one. `Paths<Pattern>` is its
|
|
138
|
+
type — exported from `@k8ordo/framework`, a type only — where the pattern
|
|
139
|
+
is the directory's own, ending in that parameter; the generated table checks
|
|
140
|
+
each file against it. **A value is what a link to the page takes**: the
|
|
141
|
+
`paramsSchema` output where the page's stack declares one — a number for the
|
|
142
|
+
`id` above, so the catalog's ids go in as they are — and anything with one
|
|
143
|
+
spelling (a string, a number, a bigint or a boolean) where none does.
|
|
144
|
+
|
|
145
|
+
**It runs where the pages run.** The build asks from the built RSC bundle,
|
|
146
|
+
and `vite dev` through the RSC environment's module runner: the module graph
|
|
147
|
+
the pages are in. So a `paths.ts` imports the application's modules by their
|
|
148
|
+
aliases, a `server-only` one included, and shares their instances with the
|
|
149
|
+
pages — a catalog it read and cached is the one the pages then read.
|
|
150
|
+
|
|
151
|
+
**It covers everything below its directory.** The `page.tsx` beside it, and
|
|
152
|
+
every page, `route.ts` and `redirect.ts` in the directories below, are
|
|
153
|
+
written once per value: with `blog/[slug]/paths.ts`, so are
|
|
154
|
+
`blog/[slug]/og.png/route.ts` (`/blog/:slug/og.png`) and
|
|
155
|
+
`blog/[slug]/article.md/route.ts`. No pattern is expanded by hand.
|
|
156
|
+
|
|
157
|
+
**It receives the params above it**, and is called once per combination of
|
|
158
|
+
their values:
|
|
90
159
|
|
|
91
160
|
```ts
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return ['ja', 'en'].map((locale) =>
|
|
99
|
-
segments
|
|
100
|
-
.map((segment) => (segment === ':locale' ? locale : segment))
|
|
101
|
-
.join('/'),
|
|
102
|
-
);
|
|
103
|
-
}),
|
|
104
|
-
});
|
|
161
|
+
// src/routes/[locale]/paths.ts
|
|
162
|
+
import type { Paths } from '@k8ordo/framework';
|
|
163
|
+
|
|
164
|
+
const paths: Paths<'/:locale'> = () => ['ja', 'en'];
|
|
165
|
+
|
|
166
|
+
export default paths;
|
|
105
167
|
```
|
|
106
168
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
169
|
+
```ts
|
|
170
|
+
// src/routes/[locale]/posts/[id]/paths.ts
|
|
171
|
+
import type { Paths } from '@k8ordo/framework';
|
|
172
|
+
|
|
173
|
+
import { postsIn } from '../../../../lib/posts.server';
|
|
110
174
|
|
|
175
|
+
const paths: Paths<'/:locale/posts/:id'> = async ({ locale }) =>
|
|
176
|
+
(await postsIn(locale)).map((post) => post.id);
|
|
177
|
+
|
|
178
|
+
export default paths;
|
|
111
179
|
```
|
|
112
|
-
|
|
180
|
+
|
|
181
|
+
**The params arrive as the layouts above read them.** Each value above is
|
|
182
|
+
spelled as the build writes it, then run through the `paramsSchema` exports
|
|
183
|
+
of the layouts in the directories above this `paths.ts`'s, outer first. The
|
|
184
|
+
page beside it and a layout in its own directory take no part: they may read
|
|
185
|
+
the value this file is being asked for, which nobody has yet. Their type is
|
|
186
|
+
exactly what those schemas produce, and the string for a parameter none of
|
|
187
|
+
them reads: `locale` is the locale `[locale]/layout.tsx`'s schema accepted.
|
|
188
|
+
When two `paths.ts` share a pattern under different layouts, as sibling route
|
|
189
|
+
groups can, the type is what both of them receive: a `year` one reads as a
|
|
190
|
+
number and the other leaves alone is `number | string`.
|
|
191
|
+
A directory needs no page of its own for its values to be read: with
|
|
192
|
+
`[year]/layout.tsx` reading `year` through
|
|
193
|
+
`z.object({ year: z.coerce.number() })` and no page at `[year]/`,
|
|
194
|
+
`[year]/paths.ts` may return `'2024'`, and `[year]/[slug]/paths.ts`
|
|
195
|
+
receives `year` as the number `2024`.
|
|
196
|
+
|
|
197
|
+
Values above that one of those schemas refuses are never handed over: the
|
|
198
|
+
`paths.ts` below is not asked under them, and the build refuses, as it does
|
|
199
|
+
for a shell standing there:
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
the paths.ts files stand where a params schema refuses the values above them, so they were not asked: /last/:slug ([year]/[slug]/paths.ts)
|
|
113
203
|
```
|
|
114
204
|
|
|
115
|
-
|
|
116
|
-
|
|
205
|
+
A `paths.ts` below a parameter whose directory has none cannot be asked,
|
|
206
|
+
and the build refuses:
|
|
117
207
|
|
|
118
|
-
|
|
119
|
-
|
|
208
|
+
```
|
|
209
|
+
[locale]/posts/[id]/paths.ts is asked for its values once per value of the parameters above it, and /:locale/posts still holds one — give that parameter's directory a paths.ts too
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**The build spells a value as `href` does** — `String(value)`, escaped for
|
|
213
|
+
the URL — so `café` and `a b` are returned as a visitor reads them, and the
|
|
214
|
+
file is written under the unescaped name. A string must not be empty, and a
|
|
215
|
+
value spelled twice is written once:
|
|
120
216
|
|
|
121
217
|
```
|
|
122
|
-
|
|
218
|
+
tags/[tag]/paths.ts has to return an array of the values of :tag, each a non-empty string, a number, a bigint or a boolean
|
|
123
219
|
```
|
|
124
220
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
221
|
+
The spelling is the one the page's `paramsSchema` reads back, as for a
|
|
222
|
+
link; a value it refuses stops the build (below).
|
|
223
|
+
|
|
224
|
+
A value that is `..` names a file outside the output, and `!fallback` is the
|
|
225
|
+
segment the build keeps for shells:
|
|
130
226
|
|
|
131
227
|
```
|
|
132
|
-
|
|
228
|
+
a pathname to write leaves the output: /products/..
|
|
229
|
+
a paths.ts returned !fallback, which the build keeps for shells: /posts/!fallback
|
|
133
230
|
```
|
|
134
231
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
escapes do not decode, or that decodes to a `..` segment, fails the build —
|
|
140
|
-
neither names a file inside the output:
|
|
232
|
+
A parameter with no `paths.ts` in its directory stays open, and an open
|
|
233
|
+
route **fails the build** — unless its page has a `fallback.tsx` beside it,
|
|
234
|
+
whose shell answers the values the build did not write
|
|
235
|
+
([Values the build did not write](#values-the-build-did-not-write)):
|
|
141
236
|
|
|
142
237
|
```
|
|
143
|
-
the
|
|
144
|
-
the "paths" option supplied a pathname that leaves the output: /products/..%2F..
|
|
238
|
+
static build needs the values of /tags/:tag — a paths.ts in each parameter's directory returns them, and a fallback.tsx beside a page answers the ones the build does not write
|
|
145
239
|
```
|
|
146
240
|
|
|
147
|
-
|
|
241
|
+
Shipping a site quietly missing half its pages is worse than not shipping one.
|
|
242
|
+
Parameterless routes need no declaration; they are taken from the table.
|
|
243
|
+
|
|
244
|
+
A returned value that a `paramsSchema` along its route's stack refuses
|
|
148
245
|
fails the build too — it would otherwise be written as a 404 page under a
|
|
149
246
|
URL the site claims to have — and so does one whose page says `notFound()`:
|
|
150
247
|
|
|
151
248
|
```
|
|
152
|
-
|
|
153
|
-
|
|
249
|
+
a paths.ts returned values a params schema refused: /products/shoes
|
|
250
|
+
a paths.ts returned values whose page called notFound(): /products/3
|
|
154
251
|
```
|
|
155
252
|
|
|
156
253
|
Neither is written to `dist/client/`. A build that meets both names them in
|
|
157
254
|
one error, with any page that failed to render, so fixing one does not reveal
|
|
158
255
|
the next.
|
|
159
256
|
|
|
257
|
+
`paths.ts` belongs in a `[param]` directory and nowhere else
|
|
258
|
+
([What the build refuses](routing.md#what-the-build-refuses)).
|
|
259
|
+
|
|
260
|
+
Under `mode: 'server'` a `paths.ts` is never read and nothing of it is
|
|
261
|
+
built in, so the same `routes/` works in both modes.
|
|
262
|
+
|
|
160
263
|
## Values the build did not write
|
|
161
264
|
|
|
162
265
|
Static mode only. A page whose values outgrow the build — a post published
|
|
@@ -165,19 +268,21 @@ after the site was deployed, an id in a link nobody listed — keeps a
|
|
|
165
268
|
|
|
166
269
|
```
|
|
167
270
|
src/routes/posts/[id]/
|
|
168
|
-
|
|
271
|
+
paths.ts the ids the build writes
|
|
272
|
+
page.tsx each of them, rendered at build time
|
|
169
273
|
fallback.tsx every other id: the shell, its post drawn in the browser
|
|
170
274
|
```
|
|
171
275
|
|
|
172
|
-
The build writes the page for each id `paths`
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
276
|
+
The build writes the page for each id `paths.ts` returns, and once more a
|
|
277
|
+
**shell**: the layouts above rendered as HTML, with the `fallback.tsx` in
|
|
278
|
+
the page's place, at `posts/!fallback/`. The host answers any other id with
|
|
279
|
+
it, through the rewrites the build writes beside the pages
|
|
176
280
|
([Rewrites to a shell](deploy.md#rewrites-to-a-shell)), and the browser,
|
|
177
|
-
which has the id in its URL, reads the post itself
|
|
281
|
+
which has the id in its URL, reads the post itself. Without the `paths.ts`
|
|
282
|
+
the build writes no post at all, and the shell answers every id.
|
|
178
283
|
|
|
179
284
|
```tsx
|
|
180
|
-
// src/routes/posts/[id]/page.tsx — the ids paths
|
|
285
|
+
// src/routes/posts/[id]/page.tsx — the ids paths.ts returns
|
|
181
286
|
import { notFound } from '@k8ordo/framework';
|
|
182
287
|
import type { PageProps } from '@k8ordo/framework';
|
|
183
288
|
|
|
@@ -275,20 +380,20 @@ export const readPost = (id: number): Promise<Post | undefined> => {
|
|
|
275
380
|
```
|
|
276
381
|
|
|
277
382
|
```ts
|
|
278
|
-
//
|
|
279
|
-
framework
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
383
|
+
// src/routes/posts/[id]/paths.ts
|
|
384
|
+
import type { Paths } from '@k8ordo/framework';
|
|
385
|
+
|
|
386
|
+
import { listPosts } from '../../../lib/posts.server';
|
|
387
|
+
|
|
388
|
+
const paths: Paths<'/posts/:id'> = async () =>
|
|
389
|
+
(await listPosts()).map((post) => post.id);
|
|
390
|
+
|
|
391
|
+
export default paths;
|
|
287
392
|
```
|
|
288
393
|
|
|
289
|
-
`
|
|
290
|
-
|
|
291
|
-
|
|
394
|
+
`paths.ts` reads the ids through `posts.server.ts`, the module the page
|
|
395
|
+
reads a post through: it runs in the server environment, where a module
|
|
396
|
+
that imports `server-only` loads. No parameter stands above `[id]`, so the
|
|
292
397
|
shell stands at the pattern itself, `/posts/:id`.
|
|
293
398
|
|
|
294
399
|
### What a `fallback.tsx` is handed
|
|
@@ -361,42 +466,39 @@ the shell for /posts/:id called notFound() while it rendered, and a shell has no
|
|
|
361
466
|
### Where a shell stands
|
|
362
467
|
|
|
363
468
|
A shell stands at a **location**: a pathname whose remaining `:name`
|
|
364
|
-
segments are left to the browser.
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
469
|
+
segments are left to the browser. Which parameters a location fills is
|
|
470
|
+
decided by the `paths.ts` files above the `fallback.tsx`: a parameter whose
|
|
471
|
+
directory has one is filled, once per value, and a parameter without one is
|
|
472
|
+
left open. With no parameter above, the location is the pattern itself —
|
|
473
|
+
`/posts/:id`, one shell for every id. With one above that lists its values,
|
|
474
|
+
there is a shell per value:
|
|
368
475
|
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
},
|
|
476
|
+
```
|
|
477
|
+
src/routes/[locale]/
|
|
478
|
+
paths.ts ja, en
|
|
479
|
+
layout.tsx
|
|
480
|
+
posts/[id]/
|
|
481
|
+
page.tsx
|
|
482
|
+
fallback.tsx shells at /ja/posts/:id and /en/posts/:id
|
|
377
483
|
```
|
|
378
484
|
|
|
379
485
|
Each location is its own shell, rendered for its own URL — the location
|
|
380
486
|
with `!fallback` for each parameter left open, `/ja/posts/!fallback`, a
|
|
381
|
-
segment no route directory can be named — and written there.
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
the rest. A location belongs to the first pattern in the table's order it
|
|
387
|
-
fits — the pattern whose URLs a host's rule for it catches.
|
|
487
|
+
segment no route directory can be named — and written there. The filled
|
|
488
|
+
values are the upper values the site has: no shell stands at
|
|
489
|
+
`/:locale/posts/:id`, which would answer `/fr/posts/1` too. A `paths.ts` in
|
|
490
|
+
`posts/[id]/` as well changes no location: the ids it returns are written as
|
|
491
|
+
pages under each locale, and the same two shells answer the rest.
|
|
388
492
|
|
|
389
493
|
**A parameter a layout above receives has to be filled.** A layout above
|
|
390
494
|
the `fallback.tsx` is written into the shell once, as HTML, for every value
|
|
391
495
|
the shell answers, so each parameter it receives is one the shell has to
|
|
392
496
|
know. With `src/routes/[locale]/layout.tsx`, that layout receives `locale`,
|
|
393
497
|
so `/:locale/posts/:id` cannot be a location — `/ja/posts/:id` and
|
|
394
|
-
`/en/posts/:id` can — and the build says
|
|
395
|
-
none, and which one left it out:
|
|
498
|
+
`/en/posts/:id` can — and without a `[locale]/paths.ts` the build says so:
|
|
396
499
|
|
|
397
500
|
```
|
|
398
|
-
|
|
399
|
-
the "paths" option supplied shell locations that leave out a parameter a layout above their fallback.tsx receives: /:locale/posts/:id (:locale, received by [locale]/layout.tsx)
|
|
501
|
+
these shells leave out a parameter a layout above their fallback.tsx receives, so its directory needs a paths.ts: /:locale/posts/:id (:locale, received by [locale]/layout.tsx)
|
|
400
502
|
```
|
|
401
503
|
|
|
402
504
|
The parameters a shell may leave are the ones no layout above the
|
|
@@ -409,10 +511,11 @@ the layouts above do, over the parameters the location fills. A schema whose
|
|
|
409
511
|
work has to reach the shell belongs on a layout — `@k8ordo/i18n`'s, which
|
|
410
512
|
sets the locale the shell's messages are rendered in, on
|
|
411
513
|
`[locale]/layout.tsx` (`export const { paramsSchema } = locales;`). A layout
|
|
412
|
-
schema that refuses a
|
|
514
|
+
schema that refuses a value a `paths.ts` above the shell returned stops the
|
|
515
|
+
build:
|
|
413
516
|
|
|
414
517
|
```
|
|
415
|
-
the
|
|
518
|
+
the shells stand where a params schema refuses the values above them: /xx/posts/:id
|
|
416
519
|
```
|
|
417
520
|
|
|
418
521
|
**Layouts render with the shell's pathname.** A layout above a shell
|
|
@@ -432,16 +535,19 @@ which reads the visitor's URL. React hoists a `<title>`, `<meta>` or
|
|
|
432
535
|
`<link>` from either. A parameter no layout receives can still be one a
|
|
433
536
|
layout derives something from: a root layout that takes `<html lang>` from
|
|
434
537
|
the first segment of `pathname` reads `!fallback` there at the bare
|
|
435
|
-
`/:locale/posts/:id`, and every value gets its default language.
|
|
436
|
-
|
|
538
|
+
`/:locale/posts/:id`, and every value gets its default language. Give that
|
|
539
|
+
parameter's directory a `paths.ts`, and the shells stand below its values.
|
|
437
540
|
|
|
438
541
|
### Routes below a fallback's parameter
|
|
439
542
|
|
|
440
543
|
A `fallback.tsx` answers its own page's pattern and nothing below it.
|
|
441
544
|
`posts/[id]/comments/page.tsx` is `/posts/:id/comments`, a pattern of its
|
|
442
|
-
own: it
|
|
443
|
-
unless it keeps a `fallback.tsx` of its own
|
|
444
|
-
|
|
545
|
+
own: it is written for the ids `posts/[id]/paths.ts` returns, and for no
|
|
546
|
+
other — unless it keeps a `fallback.tsx` of its own, whose shell stands at
|
|
547
|
+
`/posts/:id/comments`. With no `paths.ts` in `posts/[id]/` and no
|
|
548
|
+
`fallback.tsx` of its own, it stops the build, as any open route does. A
|
|
549
|
+
`redirect.ts` or `route.ts` below the parameter cannot have a
|
|
550
|
+
`fallback.tsx`, so it answers only the values returned.
|
|
445
551
|
|
|
446
552
|
### What it costs
|
|
447
553
|
|
|
@@ -451,8 +557,8 @@ below the parameter cannot have one, so it answers only the values listed.
|
|
|
451
557
|
`fallback.tsx`.
|
|
452
558
|
- **Its HTML is the shell's.** No per-value `<title>`, no Open Graph tags:
|
|
453
559
|
a crawler that runs no JavaScript and a link preview both read the
|
|
454
|
-
placeholder. A value that matters to them
|
|
455
|
-
what
|
|
560
|
+
placeholder. A value that matters to them is one a `paths.ts` returns,
|
|
561
|
+
and a rebuild is what writes it.
|
|
456
562
|
- **An unknown value answers `200`.** The host rewrites by shape, so
|
|
457
563
|
`/posts/999` gets the shell too, and the not-found it shows in place is a
|
|
458
564
|
soft 404 to a crawler. Give `not-found.tsx` a
|
|
@@ -466,14 +572,8 @@ below the parameter cannot have one, so it answers only the values listed.
|
|
|
466
572
|
|
|
467
573
|
### What else stops the build
|
|
468
574
|
|
|
469
|
-
Every refusal of `paths` is said before anything
|
|
470
|
-
|
|
471
|
-
a pathname holding the segment the build keeps for shells, escaped or not:
|
|
472
|
-
|
|
473
|
-
```
|
|
474
|
-
the "paths" option supplied shell locations whose parameter names are not their pattern's: /en/posts/:slug (/:locale/posts/:id)
|
|
475
|
-
the "paths" option supplied pathnames with a segment named !fallback, which the build keeps for shells: /posts/!fallback
|
|
476
|
-
```
|
|
575
|
+
Every refusal of what the `paths.ts` files returned is said before anything
|
|
576
|
+
is rendered, with the others above.
|
|
477
577
|
|
|
478
578
|
A shell's rule catches every URL of its location's shape that no file
|
|
479
579
|
answers, so a location must not catch URLs that a pattern declared before
|
|
@@ -483,8 +583,8 @@ catches infinitely many of them, or the two overlap in one URL the build
|
|
|
483
583
|
did not write:
|
|
484
584
|
|
|
485
585
|
```
|
|
486
|
-
the shell for /:lang/:id ([lang]/[id]/fallback.tsx) would also answer URLs /docs/:section (docs/[section]/page.tsx) is declared first for — give docs/[section]/page.tsx a fallback.tsx too, or
|
|
487
|
-
the shell for /ja/posts/:id ([locale]/posts/[id]/fallback.tsx) would also answer /ja/posts/new, which [locale]/posts/new/page.tsx is declared first for and the build did not write —
|
|
586
|
+
the shell for /:lang/:id ([lang]/[id]/fallback.tsx) would also answer URLs /docs/:section (docs/[section]/page.tsx) is declared first for — give docs/[section]/page.tsx a fallback.tsx too, or put the shell where it cannot match, with a paths.ts above it
|
|
587
|
+
the shell for /ja/posts/:id ([locale]/posts/[id]/fallback.tsx) would also answer /ja/posts/new, which [locale]/posts/new/page.tsx is declared first for and the build did not write — return its value from that parameter's paths.ts, or put the shell where it cannot match, with a paths.ts above it
|
|
488
588
|
```
|
|
489
589
|
|
|
490
590
|
A URL the build did write is not one of them — its file answers before any
|
|
@@ -499,33 +599,41 @@ renders is named by its location, as a page is:
|
|
|
499
599
|
|
|
500
600
|
```
|
|
501
601
|
the shell for /ja/posts/:id ([locale]/posts/[id]/fallback.tsx) was answered by another route, which took "!fallback" as a value
|
|
502
|
-
the shell for /en/posts/:id ([locale]/posts/[id]/fallback.tsx) was answered by en/[section]/[slug]/fallback.tsx, which the table tries first —
|
|
602
|
+
the shell for /en/posts/:id ([locale]/posts/[id]/fallback.tsx) was answered by en/[section]/[slug]/fallback.tsx, which the table tries first — put the shell where that pattern cannot match, with a paths.ts above it
|
|
503
603
|
static build could not render /ja/posts/:id — see the error above
|
|
504
604
|
```
|
|
505
605
|
|
|
506
606
|
The grammar's refusals — a `fallback.tsx` with no `page.tsx` beside it, or
|
|
507
|
-
beside a `layout.tsx`, or with nothing to leave to the browser
|
|
607
|
+
beside a `layout.tsx`, or with nothing to leave to the browser, and a
|
|
608
|
+
`paths.ts` outside a `[param]` directory — are in
|
|
508
609
|
[What the build refuses](routing.md#what-the-build-refuses).
|
|
509
610
|
|
|
510
611
|
### Under `vite dev`, and under server mode
|
|
511
612
|
|
|
512
|
-
`vite dev` answers a value
|
|
513
|
-
|
|
613
|
+
`vite dev` answers a value as the build's host will, so what works locally
|
|
614
|
+
is what is deployed. A value a `paths.ts` returns is rendered by its
|
|
615
|
+
`page.tsx`. A value none returns is answered with the shell where a
|
|
616
|
+
`fallback.tsx` stands beside the page, and otherwise with the not-found: a
|
|
617
|
+
document is rendered as `not-found.tsx` under a 404, and a payload request
|
|
618
|
+
gets a plain 404, so the browser loads the document; an application with no
|
|
619
|
+
`not-found.tsx` gets a bare 404. It says which, once per pattern or
|
|
514
620
|
`fallback.tsx`:
|
|
515
621
|
|
|
516
622
|
```
|
|
517
|
-
k8ordo: /posts/3
|
|
623
|
+
k8ordo: no paths.ts returns /posts/3, so vite dev answers it with the not-found, as the build's host will — return its value from the paths.ts of /posts/:id to render it
|
|
624
|
+
k8ordo: no paths.ts returns /posts/3, so vite dev answers it with posts/[id]/fallback.tsx's shell, as the build's host will
|
|
518
625
|
```
|
|
519
626
|
|
|
520
|
-
It
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
627
|
+
It asks the `paths.ts` files once and keeps the answer until a file under
|
|
628
|
+
`routes/` changes, and asks again when a request names a value it does not
|
|
629
|
+
hold — so a value the data has gained since is rendered without a restart.
|
|
630
|
+
A URL no pattern with a parameter could match never waits for them. What
|
|
631
|
+
the build would refuse is logged as a warning,
|
|
632
|
+
`k8ordo: the build will refuse this: …`, and a `paths.ts` that throws
|
|
633
|
+
leaves every value to its page:
|
|
634
|
+
`k8ordo: a paths.ts failed, so vite dev renders every value with page.tsx: …`.
|
|
527
635
|
|
|
528
636
|
Under `mode: 'server'` every value is rendered by its page, per request, and
|
|
529
|
-
a `fallback.tsx` is
|
|
530
|
-
modes needs no change to the files. The grammar's rules
|
|
531
|
-
modes.
|
|
637
|
+
neither a `fallback.tsx` nor a `paths.ts` is read — nothing of them is built
|
|
638
|
+
in — so switching modes needs no change to the files. The grammar's rules
|
|
639
|
+
for them hold in both modes.
|