@k8ordo/framework 2.0.0 → 3.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 +25 -12
- package/dist/generated.d.mts +2 -1
- package/dist/headers-BxB_jJVk.mjs +73 -0
- package/dist/index.d.mts +2 -1
- package/dist/paths-type-DtsL8JuC.d.mts +19 -0
- package/dist/runtime/app-router.mjs +20 -7
- 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/entry.rsc.d.mts +27 -1
- package/dist/runtime/entry.rsc.mjs +66 -9
- package/dist/runtime/entry.ssr.d.mts +6 -1
- package/dist/runtime/entry.ssr.mjs +8 -3
- 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/serve.mjs +5 -3
- package/dist/{static-DnbgGIoy.d.mts → static-c-nX9Juk.d.mts} +11 -17
- package/dist/{static-file-BAjwBMMl.mjs → static-file-BEk_xO5y.mjs} +157 -24
- package/dist/{static-host-B-1fAfAw.mjs → static-host-CyAmsL_7.mjs} +1 -1
- package/dist/vercel.d.mts +1 -1
- package/dist/vercel.mjs +30 -15
- package/dist/vite.d.mts +2 -2
- package/dist/vite.mjs +231 -111
- package/docs/GUIDE.md +26 -27
- package/docs/llms.txt +37 -28
- package/docs/references/deploy.md +69 -9
- package/docs/references/errors.md +39 -2
- package/docs/references/params.md +166 -127
- package/docs/references/routing.md +192 -49
- package/package.json +9 -9
- package/dist/shared-dir-CNXFRZgP.mjs +0 -9
package/docs/GUIDE.md
CHANGED
|
@@ -24,19 +24,20 @@ called for each route at build time instead of once per request.
|
|
|
24
24
|
|
|
25
25
|
Switching takes more than changing `mode`. Towards `mode: 'server'`:
|
|
26
26
|
|
|
27
|
-
- drop `
|
|
28
|
-
|
|
27
|
+
- drop `site` and `csp`, which it refuses — the policy becomes a header a
|
|
28
|
+
`guard.ts` writes, and no `sitemap.xml` is written,
|
|
29
29
|
- run the build with `node dist/server.js`, or hand its request handler to
|
|
30
30
|
a host of your own ([Running and deploying](references/deploy.md)).
|
|
31
31
|
|
|
32
|
-
A `fallback.tsx` may stay: server mode renders every value
|
|
33
|
-
and
|
|
34
|
-
fails either build.
|
|
32
|
+
A `fallback.tsx` and a `paths.ts` may stay: server mode renders every value
|
|
33
|
+
with its page and reads neither. Their placement is still checked, so a
|
|
34
|
+
misplaced one fails either build.
|
|
35
35
|
|
|
36
36
|
Towards `mode: 'static'`:
|
|
37
37
|
|
|
38
|
-
-
|
|
39
|
-
values the build cannot know, put a `fallback.tsx` beside the
|
|
38
|
+
- give every parameter's directory a `paths.ts` that returns its values —
|
|
39
|
+
and, for values the build cannot know, put a `fallback.tsx` beside the
|
|
40
|
+
page
|
|
40
41
|
([Values the build did not write](references/params.md#values-the-build-did-not-write)),
|
|
41
42
|
- remove what static mode refuses (below), and every read of the `request`
|
|
42
43
|
prop.
|
|
@@ -44,8 +45,8 @@ Towards `mode: 'static'`:
|
|
|
44
45
|
| | `mode: 'static'` | `mode: 'server'` |
|
|
45
46
|
| ------------------------------- | ------------------------------------------------ | --------------------------------------- |
|
|
46
47
|
| What ships | `dist/client/`, files any static host serves | `dist/`, run with `node dist/server.js` |
|
|
47
|
-
| A route with parameters | its values
|
|
48
|
-
| A value `paths`
|
|
48
|
+
| A route with parameters | its values returned by a `paths.ts` | any value, arriving with the request |
|
|
49
|
+
| A value no `paths.ts` returns | `404.html`, or a `fallback.tsx`'s shell | rendered by its page |
|
|
49
50
|
| A URL nothing answers | the host serves `404.html` | the application answers with a real 404 |
|
|
50
51
|
| `redirect.ts` | written as a page that sends the visitor on | answered with `307` / `308` |
|
|
51
52
|
| `route.ts` | written as the file its `GET` answers | answers every method it exports |
|
|
@@ -205,18 +206,19 @@ the same origin rather than linking them from another one.
|
|
|
205
206
|
### `vite dev` under static mode
|
|
206
207
|
|
|
207
208
|
`vite dev` runs the handler per request in either mode, and writes no files.
|
|
208
|
-
Under `mode: 'static'` that makes it not quite the build: a
|
|
209
|
-
`
|
|
210
|
-
|
|
211
|
-
visitor on, an unknown URL gets the handler's 404 rather than the host's
|
|
209
|
+
Under `mode: 'static'` that makes it not quite the build: a `redirect.ts`
|
|
210
|
+
answers with a `307` (`308` when `permanent`) rather than a page that sends
|
|
211
|
+
the visitor on, an unknown URL gets the handler's 404 rather than the host's
|
|
212
212
|
`404.html`, and a page whose Server Component throws answers a `500`
|
|
213
213
|
carrying the thrown message, where the build would stop.
|
|
214
214
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
`
|
|
219
|
-
value
|
|
215
|
+
A parameter's value is answered as the build's host will answer it. One a
|
|
216
|
+
`paths.ts` returns renders with its page. One none returns gets the shell
|
|
217
|
+
where a `fallback.tsx` stands beside the page, and the not-found otherwise,
|
|
218
|
+
and `vite dev` says so once per pattern. It asks the `paths.ts` files again
|
|
219
|
+
when a request names a value it does not hold, so a value the data has
|
|
220
|
+
gained since renders without a restart
|
|
221
|
+
([Parameters](references/params.md#under-vite-dev-and-under-server-mode)).
|
|
220
222
|
|
|
221
223
|
`vite preview` after a static build serves it as a static host does: the
|
|
222
224
|
files in `dist/client/`, the rewrites in its `_redirects`, and `404.html`
|
|
@@ -276,17 +278,14 @@ read the config, with React's plugin's own error
|
|
|
276
278
|
what runs in the browser is compiled; Server Components, and the HTML a
|
|
277
279
|
client component renders on the server, are left as written.
|
|
278
280
|
|
|
279
|
-
|
|
281
|
+
Two more describe files, so only `mode: 'static'` takes them — passing
|
|
280
282
|
them with `mode: 'server'` is a type error:
|
|
281
283
|
|
|
282
|
-
- `paths` — the pathnames of routes with parameters, and where a
|
|
283
|
-
`fallback.tsx`'s shell stands
|
|
284
|
-
([Parameters](references/params.md#routes-with-parameters)).
|
|
285
284
|
- `site` — the origin the site is served from, `https://example.com`. With
|
|
286
285
|
it the build also writes `sitemap.xml`, listing every page it rendered;
|
|
287
286
|
without it there is no sitemap, because a sitemap of relative URLs is not
|
|
288
|
-
one. A `route.ts` that writes `sitemap.xml`
|
|
289
|
-
|
|
287
|
+
one. A `route.ts` that writes `sitemap.xml` is the application's own
|
|
288
|
+
list, and the build leaves the file to it
|
|
290
289
|
([Routing](references/routing.md#under-static-mode)).
|
|
291
290
|
- `csp` — the Content-Security-Policy each page carries
|
|
292
291
|
([Content Security Policy](references/csp.md#static-mode-hashes-in-a-meta)).
|
|
@@ -300,9 +299,9 @@ Each topic has a reference of its own. Read the one the task needs:
|
|
|
300
299
|
before the first paint goes, `loading.tsx`, `route.ts`, the generated
|
|
301
300
|
`.k8ordo/` files, titles, and fetching the next page ahead.
|
|
302
301
|
- [Parameters](references/params.md): typing parameters with `paramsSchema`,
|
|
303
|
-
what a refused value becomes, and, under static mode,
|
|
304
|
-
|
|
305
|
-
`fallback.tsx`.
|
|
302
|
+
what a refused value becomes, and, under static mode, returning a
|
|
303
|
+
parameter's values from the `paths.ts` in its directory and answering the
|
|
304
|
+
values it does not return with a `fallback.tsx`.
|
|
306
305
|
- [Errors and redirects](references/errors.md): `error.tsx`, what fails a
|
|
307
306
|
static build, `notFound()` and `not-found.tsx`, and `redirect.ts`.
|
|
308
307
|
- [Execution boundaries](references/boundaries.md): `'use client'`,
|
package/docs/llms.txt
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
> `framework({ mode: 'static' })` renders every route at build time into
|
|
6
6
|
> files a static host serves, with no server, and
|
|
7
7
|
> `framework({ mode: 'server' })` renders per request on a server. Switching
|
|
8
|
-
> is changing `mode` (and dropping `
|
|
9
|
-
>
|
|
8
|
+
> is changing `mode` (and dropping `site` and `csp`, which server mode
|
|
9
|
+
> refuses); nothing else in the application
|
|
10
10
|
> changes. Pick `server` when the application needs the request — Server
|
|
11
11
|
> Actions, `guard.ts`, the `request` prop, cookies, a page that exports
|
|
12
12
|
> `search`, parameter values with no list rendered on the server (static
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
> and `static` otherwise; static mode refuses all of those by name, in the
|
|
15
15
|
> build and in `vite dev` (`this application wants mode: 'server'`).
|
|
16
16
|
> `src/routes/` is the pathname space and holds nothing else
|
|
17
|
-
> (page/layout/not-found/error/loading/fallback/redirect/guard/route
|
|
17
|
+
> (page/layout/not-found/error/loading/fallback/paths/redirect/guard/route
|
|
18
|
+
> files,
|
|
18
19
|
> `[param]` and `(group)` directories; `_` is an ordinary character in
|
|
19
20
|
> a segment and a name starting with `.` is not read, so `/.well-known` cannot
|
|
20
21
|
> be a route; components live outside it in `src/components/` and every
|
|
@@ -29,8 +30,10 @@
|
|
|
29
30
|
> method it exports; static: written as the file its `GET` answers). Under
|
|
30
31
|
> server mode a Server Action ends with `redirect()`, a `guard.ts` runs before
|
|
31
32
|
> whatever answers below it, `cookies()` reads and writes cookies, and a page
|
|
32
|
-
> receives `request`.
|
|
33
|
-
>
|
|
33
|
+
> receives `request`. Under static mode a parameter's values come from a
|
|
34
|
+
> `paths.ts` in its directory (a function returning them, typed `Paths`,
|
|
35
|
+
> run with the pages' own modules, applied to every route below it) —
|
|
36
|
+
> beside a `fallback.tsx`, the values it does not return get a shell: the
|
|
34
37
|
> layouts written as HTML, the page drawn in the browser from the URL, and a
|
|
35
38
|
> `_redirects` (or `vercel()`'s routes) through which a host reaches it —
|
|
36
39
|
> writes `404.html` and `sitemap.xml`, and puts a Content-Security-Policy in
|
|
@@ -74,20 +77,27 @@ Start with GUIDE.md, then follow the reference most relevant to the task.
|
|
|
74
77
|
writes them before `tsc` without a build, titles,
|
|
75
78
|
and fetching the next page ahead (`data-k8ordo-prefetch`; under static
|
|
76
79
|
mode also the links on screen for a coarse pointer, every page kept for
|
|
77
|
-
going back and forward, and `client-files.json` linked with a payload)
|
|
80
|
+
going back and forward, and `client-files.json` linked with a payload),
|
|
81
|
+
MDX (the application's own compiler plugin, `enforce: 'pre'`; the CSS
|
|
82
|
+
an `.mdx` file imports reaches the pages rendering it, with no query),
|
|
83
|
+
and counting page views (`navigatesuccess`, not `usePathname()`).
|
|
78
84
|
- [Parameters](references/params.md): `paramsSchema` — a refused value is a
|
|
79
|
-
pathname the pattern does not answer — and, under static mode,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
the
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
`
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
`
|
|
85
|
+
pathname the pattern does not answer — and, under static mode, `paths.ts`:
|
|
86
|
+
the values of its directory's parameter (`Paths<Pattern>`), given the
|
|
87
|
+
params above it, for every page, `route.ts` and `redirect.ts` below it,
|
|
88
|
+
and what fails the build; and `fallback.tsx` for the values it does not
|
|
89
|
+
return — the shell it renders (no props, the layouts' schemas only, the
|
|
90
|
+
shell's `pathname`), where a shell stands (below the values of the
|
|
91
|
+
`paths.ts` files above it, which a layout receiving a parameter forces to
|
|
92
|
+
exist), reading the value in the browser with `useMatch`, `notFound()`
|
|
93
|
+
shown in place, routes below its parameter, what it costs, and how
|
|
94
|
+
`vite dev` answers a value no `paths.ts` returns.
|
|
95
|
+
- [Errors and redirects](references/errors.md): `error.tsx` and reporting
|
|
96
|
+
from it (what no `error.tsx` catches — the root layout's own components —
|
|
97
|
+
and why there is no `global-error.tsx`), a Server Component that throws
|
|
98
|
+
stopping a static build, `notFound()` and `not-found.tsx` (a document
|
|
99
|
+
waits for its page under server mode; under a `fallback.tsx`, shown in
|
|
100
|
+
place), and `redirect.ts` in each mode.
|
|
91
101
|
- [Execution boundaries](references/boundaries.md): `'use client'`,
|
|
92
102
|
`use(browser())` for a component that needs a browser (and `useMatch` /
|
|
93
103
|
`usePathname` waiting for it on their own under a `fallback.tsx`),
|
|
@@ -110,7 +120,9 @@ Start with GUIDE.md, then follow the reference most relevant to the task.
|
|
|
110
120
|
`client-files.json`, `sitemap.xml`, `_redirects`), the rewrites that reach a shell on Netlify,
|
|
111
121
|
Cloudflare Workers static assets (`html_handling`, the 2,000/100 rule
|
|
112
122
|
limits) and Pages, Vercel and any other host, and `serve` and
|
|
113
|
-
`vite preview` serving a static build as a static host;
|
|
123
|
+
`vite preview` serving a static build as a static host; `headers`, the
|
|
124
|
+
headers every response carries in either mode (`vite dev`,
|
|
125
|
+
`vite preview`, `serve`, the handler, Vercel's routes, `_headers`);
|
|
114
126
|
under server mode, a `dist/` that runs on its own with
|
|
115
127
|
`node dist/server.js` (`PORT`, `HOST`, every dependency bundled in, and
|
|
116
128
|
`resolve.external` for one that cannot be), `serve` (compression, `ETag`,
|
|
@@ -127,16 +139,13 @@ Start with GUIDE.md, then follow the reference most relevant to the task.
|
|
|
127
139
|
`usePendingPathname`, `useMatch`, `matchPath`, `normalizePathname`,
|
|
128
140
|
`withBase`, and the types `PageProps`, `LayoutProps`, `RouteContext`,
|
|
129
141
|
`ErrorProps`, `BoundLinks`, `BoundParams`, `MatchablePattern`,
|
|
130
|
-
`MatchOptions`, `NavigateToOptions` and the `Registered*` types
|
|
131
|
-
|
|
142
|
+
`MatchOptions`, `NavigateToOptions` and the `Registered*` types; and one
|
|
143
|
+
type of its own, `Paths<Pattern>`, what a `paths.ts` exports by default.
|
|
144
|
+
Not `useParams` or `useRoute`: a page receives `params` as a prop.
|
|
132
145
|
- `@k8ordo/framework/vite` — `framework(options)` returns the Vite plugins;
|
|
133
146
|
`options.mode` (`'static' | 'server'`) is required, `options.routesDir`
|
|
134
147
|
moves the route directory (default `src/routes`). Only with
|
|
135
|
-
`mode: 'static'`: `options.
|
|
136
|
-
with parameters (a parameterised route left uncovered fails the build,
|
|
137
|
-
unless its page has a `fallback.tsx`), and for such a page also shell
|
|
138
|
-
locations, pathnames that still hold the parameters left to the browser
|
|
139
|
-
(`/ja/posts/:id`), `options.site` (the origin) makes the build also write
|
|
148
|
+
`mode: 'static'`: `options.site` (the origin) makes the build also write
|
|
140
149
|
`sitemap.xml`, and
|
|
141
150
|
`options.csp` (directives → sources, `ContentSecurityPolicy`) is the
|
|
142
151
|
Content-Security-Policy written into each page's `<meta>`, first in
|
|
@@ -207,11 +216,11 @@ Start with GUIDE.md, then follow the reference most relevant to the task.
|
|
|
207
216
|
- `k8ordo generate` — the package's one command (its `bin`), run in the
|
|
208
217
|
application's directory: resolves the Vite config there as `vite build`
|
|
209
218
|
does and writes `.k8ordo/` as the build does when it begins, then stops —
|
|
210
|
-
no environment built, no page rendered, `paths`
|
|
219
|
+
no environment built, no page rendered, no `paths.ts` read — so CI
|
|
211
220
|
runs it before `tsc` without the data a build reads. A `routes/` with
|
|
212
221
|
the problems the build names under
|
|
213
222
|
`routes/ is not a valid pathname space:` fails it the same way (exit
|
|
214
223
|
code 1), with nothing written. What `mode: 'static'` refuses on top of
|
|
215
224
|
those — a `guard.ts`, a `route.ts` answering more than `GET`, a page
|
|
216
|
-
reading `search`, an `export *`, a Server Action, whatever `paths`
|
|
225
|
+
reading `search`, an `export *`, a Server Action, whatever a `paths.ts`
|
|
217
226
|
returns — it does not check, so its success is not the build's.
|
|
@@ -23,7 +23,7 @@ dist/
|
|
|
23
23
|
index.html
|
|
24
24
|
index.rsc
|
|
25
25
|
404.html not-found.tsx, rendered
|
|
26
|
-
client-files.json what each page
|
|
26
|
+
client-files.json what each page loads beyond its payload, for a navigation to link ahead
|
|
27
27
|
sitemap.xml every page above, when `site` is set
|
|
28
28
|
_redirects how a host reaches the shells, when there are any
|
|
29
29
|
assets/… the client bundle
|
|
@@ -92,8 +92,8 @@ rewrite: the host answers a URL no file answers with the shell's file,
|
|
|
92
92
|
under `200`, the URL left as the visitor asked for it. Whenever it writes a
|
|
93
93
|
shell, the build writes the rules into `dist/client/_redirects`, in the
|
|
94
94
|
format Netlify and Cloudflare both read. For
|
|
95
|
-
`[locale]/posts/[id]/fallback.tsx`, with `paths`
|
|
96
|
-
and
|
|
95
|
+
`[locale]/posts/[id]/fallback.tsx`, with `[locale]/paths.ts` returning `en`
|
|
96
|
+
and `ja`, `[locale]/posts/[id]/paths.ts` the ids `1` and `2`, and a
|
|
97
97
|
`[locale]/posts/first/redirect.ts` beside them:
|
|
98
98
|
|
|
99
99
|
```
|
|
@@ -537,6 +537,10 @@ expression for the pathname, with `dest`, `status`, `headers`, `continue`,
|
|
|
537
537
|
assets/ sent immutable
|
|
538
538
|
```
|
|
539
539
|
|
|
540
|
+
The headers `framework()` declared
|
|
541
|
+
([Headers on every response](#headers-on-every-response)) are a route ahead
|
|
542
|
+
of `beforeFiles`, which may write the same name over for the paths it names.
|
|
543
|
+
|
|
540
544
|
`beforeFiles` is tried before any file, so it is where headers for every
|
|
541
545
|
answer go, and a redirect or a rewrite that has to win over a file that is
|
|
542
546
|
there. `beforeNotFound` is tried once neither a file nor a shell answered,
|
|
@@ -616,8 +620,8 @@ export default defineConfig({
|
|
|
616
620
|
matching goes on with `dest` as the pathname: `beforeNotFound` sees
|
|
617
621
|
`/posts/nope/article.md`, not `/posts/nope`. Here a `route.ts` at
|
|
618
622
|
`routes/posts/[slug]/article.md/` wrote each post's markdown beside its
|
|
619
|
-
page, and a client asking for markdown is answered with it.
|
|
620
|
-
|
|
623
|
+
page, and a client asking for markdown is answered with it. Both are
|
|
624
|
+
written for the slugs `posts/[slug]/paths.ts` returns, so no post is
|
|
621
625
|
written without the other.
|
|
622
626
|
- `has` matches the header's text against `value`, a regular expression,
|
|
623
627
|
and negotiates nothing: `.*text/markdown.*` takes
|
|
@@ -636,7 +640,8 @@ What to keep in mind:
|
|
|
636
640
|
query: `^/posts/` does not match `/posts/first`, and `^/posts/.+$` does.
|
|
637
641
|
- **Only Vercel applies them.** `vite dev`, `vite preview` and `serve`
|
|
638
642
|
answer as if they were not there — no header, no redirect, nothing decided
|
|
639
|
-
by `Accept`
|
|
643
|
+
by `Accept` (the headers every response carries go in `framework()`'s
|
|
644
|
+
`headers`, which all of them send) — since an imitation of Vercel's routing that differed from it
|
|
640
645
|
would pass locally and fail once deployed. A URL only a route of yours
|
|
641
646
|
answers is a 404 there.
|
|
642
647
|
- **No `Cache-Control` in a route every path takes.** It reaches every file
|
|
@@ -659,6 +664,61 @@ What to keep in mind:
|
|
|
659
664
|
vercel() takes beforeFiles and beforeNotFound under mode: 'static' only — under mode: 'server' the handler answers every URL no file names
|
|
660
665
|
```
|
|
661
666
|
|
|
667
|
+
## Headers on every response
|
|
668
|
+
|
|
669
|
+
Either mode. `framework()` takes the headers every response carries —
|
|
670
|
+
whatever answered: a page, a file of the build, a `404`, a redirect:
|
|
671
|
+
|
|
672
|
+
```ts
|
|
673
|
+
// vite.config.ts
|
|
674
|
+
export default defineConfig({
|
|
675
|
+
plugins: [
|
|
676
|
+
framework({
|
|
677
|
+
mode: 'static',
|
|
678
|
+
headers: {
|
|
679
|
+
'X-Content-Type-Options': 'nosniff',
|
|
680
|
+
'Referrer-Policy': 'strict-origin-when-cross-origin',
|
|
681
|
+
},
|
|
682
|
+
}),
|
|
683
|
+
],
|
|
684
|
+
});
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
Declared once, they are sent wherever the application runs:
|
|
688
|
+
|
|
689
|
+
| Where | How |
|
|
690
|
+
| -------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
691
|
+
| `vite dev`, `vite preview` | set before anything answers |
|
|
692
|
+
| `serve`, `node dist/server.js` | set before anything answers, read from the build |
|
|
693
|
+
| the request handler, under server mode | added to its own answers, so a runtime that calls the handler itself sends them too |
|
|
694
|
+
| Vercel, with `vercel()` | a route ahead of every other, in either mode |
|
|
695
|
+
| Netlify, Cloudflare, under static mode | `dist/client/_headers`, a rule for `/*`, your own `public/_headers` kept after it |
|
|
696
|
+
|
|
697
|
+
A value that differs between `vite dev` and the build — a
|
|
698
|
+
`Content-Security-Policy` that allows `'unsafe-eval'` only in development —
|
|
699
|
+
is the config's to decide: `defineConfig(({ command }) => …)` says which of
|
|
700
|
+
the two is running.
|
|
701
|
+
|
|
702
|
+
- **An answer's own header wins.** Under server mode a header a `guard.ts`
|
|
703
|
+
or a `route.ts` set under the same name is left as it was set: declare a
|
|
704
|
+
`Content-Security-Policy` for the files, and the pages keep the one their
|
|
705
|
+
guard writes with a `nonce()`. Vercel is the one place not to rely on
|
|
706
|
+
that — which of a route's header and a function's it sends is Vercel's to
|
|
707
|
+
decide — so do not declare a name there that a guard also writes.
|
|
708
|
+
- **No `Cache-Control`.** It would reach every file, those under `assets/`
|
|
709
|
+
among them, and every page.
|
|
710
|
+
- **Every path, or the host's own means.** A header for some paths only is
|
|
711
|
+
written where the host reads it: a route of `vercel()`'s
|
|
712
|
+
([Routes of your own](#routes-of-your-own)), a rule in `public/_headers`.
|
|
713
|
+
On Netlify and Cloudflare a response is sent the headers of every rule
|
|
714
|
+
that matches it, so a name both `headers` and your `public/_headers` give
|
|
715
|
+
is sent with both values.
|
|
716
|
+
- A name or a value HTTP could not send — a space in a name, a line break
|
|
717
|
+
in a value — is refused when the config loads.
|
|
718
|
+
- A server-mode `dist/` whose files a host of your own serves sends those
|
|
719
|
+
files however that host does: the handler adds the headers to what it
|
|
720
|
+
answers, and a file never passes through it.
|
|
721
|
+
|
|
662
722
|
## A tab opened before a deploy
|
|
663
723
|
|
|
664
724
|
A tab keeps running the script it loaded, while every payload it fetches
|
|
@@ -709,9 +769,9 @@ the way:
|
|
|
709
769
|
it with a `404`, and the client runtime leaves it to the browser.
|
|
710
770
|
|
|
711
771
|
Under `mode: 'static'` the pages are written into `dist/client/` at their
|
|
712
|
-
pathnames in the table, so the host serves that directory at `/docs/`;
|
|
713
|
-
`paths`
|
|
714
|
-
each page at its URL, base included. `_redirects` is written at the root of
|
|
772
|
+
pathnames in the table, so the host serves that directory at `/docs/`; a
|
|
773
|
+
`paths.ts` returns a parameter's values, which hold no base, and
|
|
774
|
+
`sitemap.xml` lists each page at its URL, base included. `_redirects` is written at the root of
|
|
715
775
|
`dist/client/` too, with the base in every line
|
|
716
776
|
(`/docs/posts/:p1 /docs/posts/!fallback/ 200`), but a host reads it only at
|
|
717
777
|
the root of what it publishes: move it there. Under `mode: 'server'`, `serve` reads
|
|
@@ -57,6 +57,43 @@ above it, and the file is written; with none, it stops the build the same
|
|
|
57
57
|
way. `error.tsx` under this mode is for what fails in the browser: a client
|
|
58
58
|
component, after hydration.
|
|
59
59
|
|
|
60
|
+
### Reporting, and what no `error.tsx` catches
|
|
61
|
+
|
|
62
|
+
An `error.tsx` is handed the `error` beside `reset`, so that is where a
|
|
63
|
+
failure it caught is reported from:
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
'use client';
|
|
67
|
+
|
|
68
|
+
import type { ErrorProps } from '@k8ordo/framework';
|
|
69
|
+
import { useEffect } from 'react';
|
|
70
|
+
|
|
71
|
+
export default function RouteError({ error, reset }: ErrorProps) {
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
void fetch('/reports', { method: 'POST', body: String(error) });
|
|
74
|
+
}, [error]);
|
|
75
|
+
return (
|
|
76
|
+
<button onClick={reset} type="button">
|
|
77
|
+
try again
|
|
78
|
+
</button>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The root `error.tsx` sits inside the root layout, so it catches everything
|
|
84
|
+
below that layout and nothing of the layout itself: a client component the
|
|
85
|
+
layout renders — a header's menu, a theme switch — that throws has no
|
|
86
|
+
`error.tsx` above it. The framework then does what it does for a page with
|
|
87
|
+
none: after a client navigation it loads the document again, and on the
|
|
88
|
+
document's first render it lets the error through, React takes the tree
|
|
89
|
+
down, and the browser's `error` event carries it
|
|
90
|
+
(`window.addEventListener('error', …)` is where to report it). There is no
|
|
91
|
+
`global-error.tsx`: what could replace the layout would have to render
|
|
92
|
+
`<html>` itself, with none of the layout's providers. Put an error boundary
|
|
93
|
+
of your own inside the layout instead, around the parts that can fail — a
|
|
94
|
+
dozen lines of a class component with `getDerivedStateFromError`, which is
|
|
95
|
+
what an `error.tsx` is — and the rest of the frame stays up.
|
|
96
|
+
|
|
60
97
|
## A page that is not there
|
|
61
98
|
|
|
62
99
|
A params schema decides what a URL's params look like; whether the thing they
|
|
@@ -102,8 +139,8 @@ its response has started, `notFound()` is an error like any other, and the
|
|
|
102
139
|
nearest `error.tsx` answers it.
|
|
103
140
|
|
|
104
141
|
**Under `mode: 'static'` a build waits for the whole page**, so `notFound()`
|
|
105
|
-
counts from anywhere in it. A
|
|
106
|
-
|
|
142
|
+
counts from anywhere in it. A value a `paths.ts` returned whose page says
|
|
143
|
+
it fails the build, naming the pathname — it would otherwise be written
|
|
107
144
|
as a 404 page under a URL the site claims to have (see
|
|
108
145
|
[Routes with parameters](params.md#routes-with-parameters)). The 404 itself
|
|
109
146
|
is the host's to send: `not-found.tsx` is written as `404.html`
|