@k8ordo/framework 1.4.4 → 2.3.1
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 +1 -1
- package/dist/generated.d.mts +23 -2
- package/dist/runtime/app-router.d.mts +10 -10
- package/dist/runtime/app-router.mjs +119 -83
- package/dist/runtime/browser-payloads.mjs +2 -1
- package/dist/runtime/client-files.d.mts +11 -0
- package/dist/runtime/client-files.mjs +42 -0
- package/dist/runtime/client-ready.d.mts +3 -2
- package/dist/runtime/document-root.mjs +1 -1
- package/dist/runtime/entry.browser.d.mts +1 -1
- package/dist/runtime/entry.browser.mjs +8 -12
- package/dist/runtime/entry.rsc.mjs +148 -102
- package/dist/runtime/entry.ssr.d.mts +21 -1
- package/dist/runtime/entry.ssr.mjs +10 -13
- package/dist/runtime/head-scripts.d.mts +18 -0
- package/dist/runtime/head-scripts.mjs +159 -0
- package/dist/runtime/hydrating-pathname.d.mts +16 -0
- package/dist/runtime/hydrating-pathname.mjs +26 -0
- package/dist/runtime/mount.d.mts +16 -11
- package/dist/runtime/mount.mjs +29 -18
- package/dist/runtime/payload.d.mts +22 -23
- package/dist/runtime/payload.mjs +11 -16
- package/dist/runtime/prefetch.d.mts +60 -25
- package/dist/runtime/prefetch.mjs +166 -38
- package/dist/runtime/recover.d.mts +2 -0
- package/dist/runtime/recover.mjs +11 -7
- package/dist/runtime/redirect.d.mts +20 -14
- package/dist/runtime/redirect.mjs +42 -15
- package/dist/runtime/request-scope.d.mts +1 -1
- package/dist/runtime/request-scope.mjs +11 -23
- package/dist/runtime/server.d.mts +6 -0
- package/dist/runtime/server.mjs +3 -0
- package/dist/runtime/stylesheets.d.mts +13 -0
- package/dist/runtime/stylesheets.mjs +15 -0
- package/dist/serve.d.mts +1 -0
- package/dist/serve.mjs +5 -11
- package/dist/static-file-BAjwBMMl.mjs +1274 -0
- package/dist/{static-host-C6D_11Gp.mjs → static-host-B-1fAfAw.mjs} +49 -74
- package/dist/vercel.d.mts +0 -1
- package/dist/vercel.mjs +20 -20
- package/dist/vite.mjs +228 -1518
- package/docs/GUIDE.md +3 -2
- package/docs/llms.txt +8 -4
- package/docs/references/csp.md +11 -9
- package/docs/references/deploy.md +17 -20
- package/docs/references/errors.md +0 -34
- package/docs/references/params.md +5 -5
- package/docs/references/routing.md +94 -31
- package/package.json +6 -6
- package/dist/runtime/redirect-file.d.mts +0 -20
- package/dist/runtime/redirect-file.mjs +0 -42
- package/dist/runtime/tree-pathname.d.mts +0 -2
- package/dist/runtime/tree-pathname.mjs +0 -11
- package/dist/server.d.mts +0 -110
- package/dist/server.mjs +0 -97
package/docs/GUIDE.md
CHANGED
|
@@ -296,8 +296,9 @@ them with `mode: 'server'` is a type error:
|
|
|
296
296
|
Each topic has a reference of its own. Read the one the task needs:
|
|
297
297
|
|
|
298
298
|
- [Routing](references/routing.md): the `routes/` grammar and what the build
|
|
299
|
-
refuses, how a page answers and streams,
|
|
300
|
-
|
|
299
|
+
refuses, how a page answers and streams, where a script that has to run
|
|
300
|
+
before the first paint goes, `loading.tsx`, `route.ts`, the generated
|
|
301
|
+
`.k8ordo/` files, titles, and fetching the next page ahead.
|
|
301
302
|
- [Parameters](references/params.md): typing parameters with `paramsSchema`,
|
|
302
303
|
what a refused value becomes, and, under static mode, supplying the
|
|
303
304
|
pathnames with `paths` and answering the values it does not list with a
|
package/docs/llms.txt
CHANGED
|
@@ -64,13 +64,17 @@ Start with GUIDE.md, then follow the reference most relevant to the task.
|
|
|
64
64
|
every page loads comes in at most two files — the entry's and the frame's,
|
|
65
65
|
which sets the client build's `codeSplitting` — and the browser renders
|
|
66
66
|
once they have loaded; Server Components' stylesheets
|
|
67
|
-
come before client components',
|
|
67
|
+
come before client components', a stylesheet once loaded stays, and an
|
|
68
|
+
inline classic script in `<head>` is moved ahead of every stylesheet, so
|
|
69
|
+
a script that has to run before the first paint goes there),
|
|
68
70
|
`loading.tsx`, `route.ts` (methods and `405` under server
|
|
69
71
|
mode, a file under static mode), the generated `.k8ordo/` files (the
|
|
70
72
|
route table, and the `Register`s: the table's, and `@k8ordo/i18n`'s when
|
|
71
73
|
`src/i18n.ts` exports `locales` by name) and `k8ordo generate`, which
|
|
72
74
|
writes them before `tsc` without a build, titles,
|
|
73
|
-
and fetching the next page ahead (`data-k8ordo-prefetch
|
|
75
|
+
and fetching the next page ahead (`data-k8ordo-prefetch`; under static
|
|
76
|
+
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).
|
|
74
78
|
- [Parameters](references/params.md): `paramsSchema` — a refused value is a
|
|
75
79
|
pathname the pattern does not answer — and, under static mode, the `paths`
|
|
76
80
|
option: supplying pathnames, expanding a parameter every page shares, and
|
|
@@ -103,7 +107,7 @@ Start with GUIDE.md, then follow the reference most relevant to the task.
|
|
|
103
107
|
mode, and `connect-src` for the data a `fallback.tsx`'s shell fetches.
|
|
104
108
|
- [Running and deploying](references/deploy.md): a static build's
|
|
105
109
|
`dist/client/` (HTML, `index.rsc` payloads, shells, `404.html`,
|
|
106
|
-
`sitemap.xml`, `_redirects`), the rewrites that reach a shell on Netlify,
|
|
110
|
+
`client-files.json`, `sitemap.xml`, `_redirects`), the rewrites that reach a shell on Netlify,
|
|
107
111
|
Cloudflare Workers static assets (`html_handling`, the 2,000/100 rule
|
|
108
112
|
limits) and Pages, Vercel and any other host, and `serve` and
|
|
109
113
|
`vite preview` serving a static build as a static host;
|
|
@@ -136,7 +140,7 @@ Start with GUIDE.md, then follow the reference most relevant to the task.
|
|
|
136
140
|
`sitemap.xml`, and
|
|
137
141
|
`options.csp` (directives → sources, `ContentSecurityPolicy`) is the
|
|
138
142
|
Content-Security-Policy written into each page's `<meta>`, first in
|
|
139
|
-
`<head>`, with the hashes of the framework's own inline scripts on that
|
|
143
|
+
`<head>` after the `<meta charSet>`, with the hashes of the framework's own inline scripts on that
|
|
140
144
|
page added to `script-src` (or `default-src` made into it) and
|
|
141
145
|
`script-src-elem`; a policy with `'strict-dynamic'`, `frame-ancestors`,
|
|
142
146
|
`report-uri`, `report-to` or `sandbox` is refused. `FrameworkOptions` is
|
package/docs/references/csp.md
CHANGED
|
@@ -36,11 +36,11 @@ export default function guard() {
|
|
|
36
36
|
|
|
37
37
|
```tsx
|
|
38
38
|
// src/routes/layout.tsx
|
|
39
|
-
import {
|
|
39
|
+
import { ColorSchemeScript } from '@k8ordo/color-scheme';
|
|
40
40
|
import { nonce } from '@k8ordo/framework/server';
|
|
41
41
|
|
|
42
|
-
// …inside <
|
|
43
|
-
<
|
|
42
|
+
// …inside <head>
|
|
43
|
+
<ColorSchemeScript nonce={nonce()} />;
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
The framework's module script carries the nonce as well, so under
|
|
@@ -78,10 +78,12 @@ Static mode only. A file cannot carry a nonce — everyone reads the same
|
|
|
78
78
|
one — so the build names what the framework signed by hash, and leaves no
|
|
79
79
|
nonce in what it writes. Give the plugin the policy as `csp`, directives and
|
|
80
80
|
their sources (`ContentSecurityPolicy`), and each page gets it in a
|
|
81
|
-
`<meta http-equiv="Content-Security-Policy">` first in its `<head
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
`<meta http-equiv="Content-Security-Policy">` first in its `<head>` after
|
|
82
|
+
the `<meta charSet>` (a browser looks for the encoding only in the first
|
|
83
|
+
1024 bytes, which a policy naming many hashes outgrows), with the hashes of
|
|
84
|
+
that page's framework scripts added wherever a script element is decided —
|
|
85
|
+
`script-src` (made from `default-src` when only that was given) and
|
|
86
|
+
`script-src-elem` when given:
|
|
85
87
|
|
|
86
88
|
```ts
|
|
87
89
|
// vite.config.ts
|
|
@@ -111,8 +113,8 @@ every `style` attribute as well.
|
|
|
111
113
|
|
|
112
114
|
An inline script of the application's is allowed by its hash in that policy,
|
|
113
115
|
as `colorSchemeScriptHash()` gives `@k8ordo/color-scheme`'s (pass it the
|
|
114
|
-
`
|
|
115
|
-
page — one that reached it from content — is refused. The framework's module
|
|
116
|
+
props `ColorSchemeScript` is given, `nonce` aside); any other inline script
|
|
117
|
+
on the page — one that reached it from content — is refused. The framework's module
|
|
116
118
|
script is allowed by where it comes from (`'self'`), since nothing in a file
|
|
117
119
|
can sign it, which is why the build refuses a policy with `'strict-dynamic'`.
|
|
118
120
|
It refuses `frame-ancestors`, `report-uri` and `sandbox` too, which a
|
|
@@ -23,6 +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's client components load, for a navigation to link ahead
|
|
26
27
|
sitemap.xml every page above, when `site` is set
|
|
27
28
|
_redirects how a host reaches the shells, when there are any
|
|
28
29
|
assets/… the client bundle
|
|
@@ -72,11 +73,14 @@ any 404 is. Its `pathname` is such a URL, and where a parameter sits above
|
|
|
72
73
|
so `params.<name>` there is not a value the application named. Treat it as you
|
|
73
74
|
must treat any parameter under `mode: 'server'`, where `/:locale/*` matches
|
|
74
75
|
`/fr/anything` too: validate it, and read what the visitor actually typed from
|
|
75
|
-
`usePathname()` in a client component. The browser
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
`usePathname()` in a client component. The browser hydrates this file as it
|
|
77
|
+
was written, keeping every element in it. While it hydrates, what a component
|
|
78
|
+
reads from the URL as it renders — `usePathname()`, and `@k8ordo/i18n`'s
|
|
79
|
+
messages, which read the locale segment — is the pathname the file was
|
|
80
|
+
rendered for, so it agrees with what is written there. Once the file is
|
|
81
|
+
hydrated, the page is rendered again where the visitor is, and a client
|
|
82
|
+
component reads their URL from then on: an effect that runs on the first
|
|
83
|
+
commit sees the build's pathname first, then the visitor's. A visitor
|
|
80
84
|
without JavaScript keeps whatever the build's render produced.
|
|
81
85
|
|
|
82
86
|
## Rewrites to a shell
|
|
@@ -209,12 +213,10 @@ way `auto-trailing-slash` does, with nothing to set.
|
|
|
209
213
|
### Vercel
|
|
210
214
|
|
|
211
215
|
Vercel never reads `_redirects`; `vercel()` writes the same rewrites as
|
|
212
|
-
routes ([Deploying to Vercel](#deploying-to-vercel)).
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
k8ordo: this build runs on Vercel, which does not read _redirects — add vercel() from @k8ordo/framework/vercel, or the shells are never served
|
|
217
|
-
```
|
|
216
|
+
routes ([Deploying to Vercel](#deploying-to-vercel)). Without it the shells
|
|
217
|
+
are never served there. With it the build still writes `_redirects`, for
|
|
218
|
+
`serve` and `vite preview`, and says none of the warnings above: they are
|
|
219
|
+
about how Cloudflare reads the file.
|
|
218
220
|
|
|
219
221
|
### Other hosts
|
|
220
222
|
|
|
@@ -336,8 +338,10 @@ const server = await serve({ port: 3000 });
|
|
|
336
338
|
`serve` takes three options (`ServeOptions`): `dist`, the build output
|
|
337
339
|
holding `client/` and `rsc/` (default `dist`, resolved against the working
|
|
338
340
|
directory); `port` (default `3000`); and `host` (default `localhost` —
|
|
339
|
-
inside a container, `'0.0.0.0'`).
|
|
340
|
-
|
|
341
|
+
inside a container, `'0.0.0.0'`). `server.url` names the address it listens
|
|
342
|
+
on, so under the default it is `http://[::1]:3000` wherever `localhost`
|
|
343
|
+
gave Node `::1`. Stopping it on a signal is up to the server that calls it:
|
|
344
|
+
`await server.close()`.
|
|
341
345
|
|
|
342
346
|
For a server build, `serve` hands out the client build's files as they are
|
|
343
347
|
and passes everything else to the request handler: HTML for a page, its RSC
|
|
@@ -643,13 +647,6 @@ What to keep in mind:
|
|
|
643
647
|
`caseSensitive: true`, while the routes `vercel()` writes itself are
|
|
644
648
|
case-sensitive, as the route table is. A route without it answers
|
|
645
649
|
`/POSTS/first` as well.
|
|
646
|
-
- **`has` names a header in lowercase**, as Vercel compares it. `vercel()`
|
|
647
|
-
refuses another spelling when it is called:
|
|
648
|
-
|
|
649
|
-
```text
|
|
650
|
-
vercel() route ^/posts/([a-z0-9-]+)$ has the header key "Accept" — write it lowercase ("accept"), as Vercel compares it
|
|
651
|
-
```
|
|
652
|
-
|
|
653
650
|
- **Nothing else is checked.** The routes are written as given — under a
|
|
654
651
|
`base` their `src` and `dest` carry it — and their patterns are Vercel's
|
|
655
652
|
(PCRE), which JavaScript's `RegExp` would misjudge, so a mistake shows once
|
|
@@ -57,40 +57,6 @@ 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
|
-
The build also checks every HTML file it writes — each page, `404.html` and
|
|
61
|
-
each shell — against the client components its payload names: each one's
|
|
62
|
-
stylesheets have to be linked in `<head>` (`<link rel="stylesheet">`), and
|
|
63
|
-
its scripts preloaded there (`<link rel="modulepreload">`) or loaded by a
|
|
64
|
-
`<script>`. Without them, what the browser needs for those components is
|
|
65
|
-
asked for only once the page's script runs: a component the page renders
|
|
66
|
-
shows unstyled until then, and hydration waits a round trip longer. A file
|
|
67
|
-
that misses one stops the build once every file is written. The error
|
|
68
|
-
counts the HTML files, the files they miss and the components that need
|
|
69
|
-
them, asks for a report, then names each missing file once, those most
|
|
70
|
-
pages miss first and 20 at most: how many pages miss it, a few of them
|
|
71
|
-
(`404.html` for the not-found, a shell by its location), and a component
|
|
72
|
-
that needs it, by its export's name (`default` for a default export):
|
|
73
|
-
|
|
74
|
-
```
|
|
75
|
-
static build wrote HTML that does not link everything the client components its payload names need: 2 HTML files miss 3 files of 2 components
|
|
76
|
-
This is a bug in @k8ordo/framework, not in this application: report it at https://github.com/k35o/k8ordo/issues with this message (@k8ordo/framework 1.2.2, react 19.3.1, react-dom 19.3.1)
|
|
77
|
-
/assets/Icon-MOWHoEeM.js — 1 page (/), for default
|
|
78
|
-
/assets/not-found-C2TfACgz.css — 1 page (404.html), for NotFound
|
|
79
|
-
/assets/not-found-xxQ43iW3.js — 1 page (404.html), for NotFound
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
The framework has React write every one of those links as it renders the
|
|
83
|
-
page, whatever its components hold or render, so a file the error names is
|
|
84
|
-
a bug in k8ordo or in the React that wrote the HTML, not something the
|
|
85
|
-
application got wrong or can fix. Report it with the error as printed. If
|
|
86
|
-
the build started stopping right after an upgrade, go back to the previous
|
|
87
|
-
version of what you upgraded — `@k8ordo/framework`, or `react` and
|
|
88
|
-
`react-dom`, which decide where the links are written — until it is fixed.
|
|
89
|
-
The check does not cover the stylesheets of what a client component
|
|
90
|
-
imports dynamically (`React.lazy`, `import()`), nor a Server Component's
|
|
91
|
-
stylesheets, and it runs only in a static build: `vite dev` and server
|
|
92
|
-
mode render per request.
|
|
93
|
-
|
|
94
60
|
## A page that is not there
|
|
95
61
|
|
|
96
62
|
A params schema decides what a URL's params look like; whether the thing they
|
|
@@ -302,11 +302,11 @@ value from the URL in the browser.
|
|
|
302
302
|
|
|
303
303
|
### Reading the value in the browser
|
|
304
304
|
|
|
305
|
-
The browser
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
visitor's URL from its first render.
|
|
305
|
+
The browser hydrates a shell as it was rendered for `/posts/!fallback`,
|
|
306
|
+
keeping every element the build wrote, as it does `404.html`, and renders it
|
|
307
|
+
again where the visitor is once it is hydrated. What the `fallback.tsx`
|
|
308
|
+
renders was left to the browser by the build, so a client component inside
|
|
309
|
+
it reads the visitor's URL from its first render.
|
|
310
310
|
|
|
311
311
|
Below a `fallback.tsx`, `useMatch()` and `usePathname()` wait for the
|
|
312
312
|
browser on their own: in the build's render they suspend, as
|
|
@@ -163,6 +163,41 @@ ahead, applies to every page after it in the tab. Keep the selectors of the
|
|
|
163
163
|
CSS a page or a client component imports to its own elements — a CSS
|
|
164
164
|
Module's classes — and import what every page needs in the root layout.
|
|
165
165
|
|
|
166
|
+
**A script in `<head>` runs before the stylesheets.** React writes what it
|
|
167
|
+
hoists into `<head>` — every stylesheet among it — ahead of what the root
|
|
168
|
+
layout put there, and a script after a stylesheet waits for it to load,
|
|
169
|
+
while the browser may paint the page without what the script sets. So the
|
|
170
|
+
framework moves each inline classic script of `<head>` — no `src`, no
|
|
171
|
+
`type` — ahead of the first stylesheet there, in the order the layout wrote
|
|
172
|
+
them, in either mode and under `vite dev`. It is the place for a script that
|
|
173
|
+
has to run before the first paint, such as `@k8ordo/color-scheme`'s:
|
|
174
|
+
|
|
175
|
+
```tsx
|
|
176
|
+
// src/routes/layout.tsx
|
|
177
|
+
import { ColorSchemeScript } from '@k8ordo/color-scheme';
|
|
178
|
+
import type { LayoutProps } from '@k8ordo/framework';
|
|
179
|
+
|
|
180
|
+
export default function RootLayout({ children }: LayoutProps<'/'>) {
|
|
181
|
+
return (
|
|
182
|
+
<html lang="en" suppressHydrationWarning>
|
|
183
|
+
<head>
|
|
184
|
+
<meta charSet="utf-8" />
|
|
185
|
+
<ColorSchemeScript />
|
|
186
|
+
</head>
|
|
187
|
+
<body>{children}</body>
|
|
188
|
+
</html>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Such a script runs before any of the page's CSS has loaded: it can set a
|
|
194
|
+
class or an attribute on `<html>`, but a style it computes reads none of
|
|
195
|
+
that CSS. A script with a `src` or a `type` stays where React wrote it, and
|
|
196
|
+
so does one inside a `<noscript>` or a `<template>`, and every script in
|
|
197
|
+
`<body>`. Under `mode: 'static'` the policy's `<meta>` stays first in
|
|
198
|
+
`<head>`, so the policy covers the scripts moved after it
|
|
199
|
+
([Content Security Policy](csp.md#static-mode-hashes-in-a-meta)).
|
|
200
|
+
|
|
166
201
|
## What the build refuses
|
|
167
202
|
|
|
168
203
|
Every problem is reported, not just the first, and each names the file:
|
|
@@ -355,24 +390,20 @@ name. What it writes is not a page, so `sitemap.xml` leaves it out.
|
|
|
355
390
|
|
|
356
391
|
Nor can a `route.ts` write a file the build writes itself — `sitemap.xml`
|
|
357
392
|
when `site` is given, `404.html` beside a `not-found.tsx`, `_redirects` when
|
|
358
|
-
there are shells, a page's `index.html` or `index.rsc`
|
|
359
|
-
replace the other.
|
|
360
|
-
|
|
361
|
-
It stops before it renders anything, naming both:
|
|
393
|
+
there are shells, `client-files.json`, a page's `index.html` or `index.rsc`
|
|
394
|
+
— since one would replace the other. It stops before it renders anything,
|
|
395
|
+
naming every such `route.ts` in one error, each beside what is in its way:
|
|
362
396
|
|
|
363
397
|
```
|
|
364
|
-
static build writes a
|
|
398
|
+
static build writes a route.ts as the file its GET answers, and these cannot be written — remove the route.ts, or what else is written there:
|
|
365
399
|
sitemap.xml: src/routes/sitemap.xml/route.ts, and the "site" option writes it
|
|
366
400
|
```
|
|
367
401
|
|
|
368
402
|
For a sitemap of your own, keep the `route.ts` and drop `site`; the requests
|
|
369
403
|
the build hands every `route.ts` then carry no origin of the site's, so write
|
|
370
|
-
its absolute URLs from one of your own.
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
which the build adds to its own. `vite dev` does not stop: it warns of what
|
|
374
|
-
the build will refuse, for a `route.ts` whose URL has no params; the
|
|
375
|
-
pathnames `paths` gives one with params only the build sees.
|
|
404
|
+
its absolute URLs from one of your own. Rules of your own for a host go in
|
|
405
|
+
`public/_redirects`, which the build adds to its own. `vite dev` does not
|
|
406
|
+
stop: only the build writes the files.
|
|
376
407
|
|
|
377
408
|
Name the type in the `Response`. A string body with none is sent as
|
|
378
409
|
`text/plain;charset=UTF-8` — the `Response` sets it — so a `sitemap.xml`
|
|
@@ -571,14 +602,22 @@ loads the client components that page renders, as a navigation would, and
|
|
|
571
602
|
with them their stylesheets, which apply to the page on screen from then on
|
|
572
603
|
([How a page is sent](#how-a-page-is-sent)).
|
|
573
604
|
|
|
605
|
+
A touch screen has no hover, and a tap's press and click come together,
|
|
606
|
+
leaving nothing to fetch ahead in. So under `mode: 'static'`, where the
|
|
607
|
+
primary pointer is coarse (`(pointer: coarse)`), the runtime fetches the
|
|
608
|
+
links on screen instead: each link as it comes into view, one at a time in
|
|
609
|
+
the order they appeared, at low fetch priority, passing over a link that
|
|
610
|
+
left the screen before its turn. Under `mode: 'server'` it does not — every
|
|
611
|
+
link a visitor scrolls past would be a render on the server.
|
|
612
|
+
|
|
574
613
|
Only a link a click would load in place is fetched: the same origin and below
|
|
575
614
|
Vite's `base`, no `download`, no `target` other than `_self`, and not the
|
|
576
615
|
page on screen, where only the search or the fragment would change. To stop
|
|
577
|
-
it for a link — one whose page is expensive to render,
|
|
578
|
-
or any element around
|
|
579
|
-
(`data-k8ordo-prefetch={false}` in JSX
|
|
580
|
-
|
|
581
|
-
region that opted out.
|
|
616
|
+
it for a link — one whose page is expensive to render, or a long list a
|
|
617
|
+
visitor scrolls through on a phone — mark the link, or any element around
|
|
618
|
+
it, `data-k8ordo-prefetch="false"` (`data-k8ordo-prefetch={false}` in JSX
|
|
619
|
+
renders the same). The nearest element carrying the attribute decides, so
|
|
620
|
+
`"true"` opts a link back in inside a region that opted out.
|
|
582
621
|
|
|
583
622
|
```tsx
|
|
584
623
|
<nav data-k8ordo-prefetch={false}>
|
|
@@ -589,18 +628,42 @@ region that opted out.
|
|
|
589
628
|
</nav>
|
|
590
629
|
```
|
|
591
630
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
a
|
|
601
|
-
it —
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
631
|
+
Under `mode: 'server'` a page is rendered per request, so what was fetched
|
|
632
|
+
is used by the next navigation to that page, once, and only if it starts
|
|
633
|
+
within 30 seconds of the fetch starting. After that — or once a navigation
|
|
634
|
+
has used it — the page is fetched afresh, as it would have been with nothing
|
|
635
|
+
prefetched, so a page hovered and left alone never shows up later as it was
|
|
636
|
+
then. A Server Action's answer drops everything prefetched, since the action
|
|
637
|
+
may have changed what those pages show.
|
|
638
|
+
|
|
639
|
+
Under `mode: 'static'` a page is a file, the same until the next deploy, so
|
|
640
|
+
it is kept: every page fetched — ahead, or by a navigation that found none —
|
|
641
|
+
and the page the document arrived as are handed to every navigation to
|
|
642
|
+
them, going back and forward included, without asking the host again. The
|
|
643
|
+
tab keeps the 50 pages it used most recently. A page left while it was
|
|
644
|
+
still arriving goes on arriving, so going back to it shows it whole. Under
|
|
645
|
+
`vite dev` pages are rendered per request whatever the mode, and are kept
|
|
646
|
+
as under `mode: 'server'`.
|
|
647
|
+
|
|
648
|
+
In either mode a fetch that failed is dropped at once, so the navigation
|
|
649
|
+
asks again. A prefetch dropped before any navigation used it is cancelled
|
|
650
|
+
if it is still on its way, and one a navigation took is cancelled with that
|
|
651
|
+
navigation when another overtakes it, unless a later navigation is waiting
|
|
652
|
+
for it too — the same as a fetch the navigation had started itself.
|
|
653
|
+
|
|
654
|
+
Under `mode: 'static'` the build also writes `client-files.json`: for each
|
|
655
|
+
page, the scripts and stylesheets its client components need, less those
|
|
656
|
+
every page loads. The runtime reads it at low priority once the document
|
|
657
|
+
runs, and whenever it asks for a page's payload — a prefetch or a
|
|
658
|
+
navigation — it links that page's files at the same moment
|
|
659
|
+
(`<link rel="modulepreload">` for a script, `<link rel="preload" as="style">`
|
|
660
|
+
for a stylesheet) instead of waiting for the payload to name them, a round
|
|
661
|
+
trip later. A stylesheet still applies only once the client component that
|
|
662
|
+
needs it loads. A page the list leaves out — a shell's value, or a host that
|
|
663
|
+
lost the file — loads as it would without one.
|
|
664
|
+
|
|
665
|
+
Under `mode: 'server'` a prefetch is a render, as a navigation is — the
|
|
666
|
+
reason to mark a link to an expensive page. The platform's Speculation
|
|
667
|
+
Rules are not used: they are Chromium's alone, not Baseline. Nor is there a
|
|
668
|
+
check for a visitor saving data: the Network Information API is not
|
|
669
|
+
Baseline either.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k8ordo/framework",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "The k8ordo framework: routes/ compiled into React Server Components, run with or without a server.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"k8ordo",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"default": "./dist/vite.mjs"
|
|
43
43
|
},
|
|
44
44
|
"./server": {
|
|
45
|
-
"types": "./dist/server.d.mts",
|
|
46
|
-
"default": "./dist/server.mjs"
|
|
45
|
+
"types": "./dist/runtime/server.d.mts",
|
|
46
|
+
"default": "./dist/runtime/server.mjs"
|
|
47
47
|
},
|
|
48
48
|
"./serve": {
|
|
49
49
|
"types": "./dist/serve.d.mts",
|
|
@@ -75,8 +75,8 @@
|
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@arethetypeswrong/cli": "0.18.5",
|
|
78
|
-
"@k8ordo/framework-engine": "^0.1.
|
|
79
|
-
"@k8ordo/router": "^
|
|
78
|
+
"@k8ordo/framework-engine": "^0.1.2",
|
|
79
|
+
"@k8ordo/router": "^2.3.1",
|
|
80
80
|
"@types/compressible": "2.0.3",
|
|
81
81
|
"@types/fresh": "0.5.3",
|
|
82
82
|
"@types/mime-types": "3.0.1",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"vitest": "5.0.5"
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
|
-
"@k8ordo/router": "^
|
|
95
|
+
"@k8ordo/router": "^2.3.1",
|
|
96
96
|
"oxc-transform-react": "^0.152.0",
|
|
97
97
|
"react": ">=19.3.0",
|
|
98
98
|
"react-dom": ">=19.3.0",
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/** What a `redirect.ts` route file default-exports. */
|
|
2
|
-
export type RedirectTarget = string | {
|
|
3
|
-
readonly to: string;
|
|
4
|
-
readonly permanent?: boolean;
|
|
5
|
-
};
|
|
6
|
-
type ResolvedRedirect = {
|
|
7
|
-
readonly to: string;
|
|
8
|
-
readonly permanent: boolean;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Where a `redirect.ts` sends a pathname the table matched to its pattern,
|
|
12
|
-
* with the matched params filled into the target, so `/:locale/legacy` can
|
|
13
|
-
* send to `/:locale/new`; `null` for a pattern no redirect declares. Which
|
|
14
|
-
* pattern answers is the table's to say — the redirect holds its place there
|
|
15
|
-
* — so this only reads the params again: the router hands them decoded, and a
|
|
16
|
-
* target moves a segment as the URL spelled it. The pathname is normalized as
|
|
17
|
-
* the table normalizes it, so `/old/` is `/old` here too.
|
|
18
|
-
*/
|
|
19
|
-
export declare const resolveRedirects: (declared: Readonly<Record<string, RedirectTarget>>) => ((pattern: string, pathname: string) => ResolvedRedirect | null);
|
|
20
|
-
export {};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { normalizePathname } from "@k8ordo/router";
|
|
2
|
-
// src/runtime/redirect-file.ts
|
|
3
|
-
const resolveTarget = (target, segments) => {
|
|
4
|
-
const { to, permanent } = typeof target === "string" ? {
|
|
5
|
-
to: target,
|
|
6
|
-
permanent: false
|
|
7
|
-
} : target;
|
|
8
|
-
return {
|
|
9
|
-
to: to.split("/").map((segment) => {
|
|
10
|
-
if (!segment.startsWith(":")) return segment;
|
|
11
|
-
const value = segments[segment.slice(1)];
|
|
12
|
-
if (value === void 0) throw new TypeError(`redirect target "${to}" needs a value for "${segment}"`);
|
|
13
|
-
return value;
|
|
14
|
-
}).join("/"),
|
|
15
|
-
permanent: permanent ?? false
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Where a `redirect.ts` sends a pathname the table matched to its pattern,
|
|
20
|
-
* with the matched params filled into the target, so `/:locale/legacy` can
|
|
21
|
-
* send to `/:locale/new`; `null` for a pattern no redirect declares. Which
|
|
22
|
-
* pattern answers is the table's to say — the redirect holds its place there
|
|
23
|
-
* — so this only reads the params again: the router hands them decoded, and a
|
|
24
|
-
* target moves a segment as the URL spelled it. The pathname is normalized as
|
|
25
|
-
* the table normalizes it, so `/old/` is `/old` here too.
|
|
26
|
-
*/
|
|
27
|
-
const resolveRedirects = (declared) => {
|
|
28
|
-
const matchers = new Map(Object.entries(declared).map(([pattern, target]) => [pattern, {
|
|
29
|
-
matcher: new URLPattern({ pathname: pattern }),
|
|
30
|
-
target
|
|
31
|
-
}]));
|
|
32
|
-
return (pattern, pathname) => {
|
|
33
|
-
const declaredHere = matchers.get(pattern);
|
|
34
|
-
if (declaredHere === void 0) return null;
|
|
35
|
-
const result = declaredHere.matcher.exec({ pathname: normalizePathname(pathname) });
|
|
36
|
-
if (result === null) return null;
|
|
37
|
-
const segments = {};
|
|
38
|
-
for (const [name, value] of Object.entries(result.pathname.groups)) if (!/^\d+$/u.test(name) && value !== void 0) segments[name] = value;
|
|
39
|
-
return resolveTarget(declaredHere.target, segments);
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
export { resolveRedirects };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { createContext } from "react";
|
|
3
|
-
// src/runtime/tree-pathname.ts
|
|
4
|
-
/**
|
|
5
|
-
* `@k8ordo/router`'s context for the pathname each tree was applied for,
|
|
6
|
-
* which `<Router>` provides and `@k8ordo/state` reads to keep a page state's
|
|
7
|
-
* values with the tree on screen. `AppRouter` provides it the same way.
|
|
8
|
-
*/
|
|
9
|
-
const KEY = Symbol.for("@k8ordo/router/tree-pathname");
|
|
10
|
-
const TreePathname = globalThis[KEY] ??= createContext(null);
|
|
11
|
-
export { TreePathname };
|
package/dist/server.d.mts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { ParamsOf } from "@k8ordo/router";
|
|
2
|
-
/**
|
|
3
|
-
* How a cookie is kept. The defaults are the ones a session wants: sent on
|
|
4
|
-
* every path, never readable from a page's script, only over HTTPS, and not
|
|
5
|
-
* on another site's POST.
|
|
6
|
-
*/
|
|
7
|
-
type CookieOptions = {
|
|
8
|
-
/** Default `/`. */
|
|
9
|
-
readonly path?: string;
|
|
10
|
-
readonly domain?: string;
|
|
11
|
-
/** Seconds until it expires; `0` expires it now. */
|
|
12
|
-
readonly maxAge?: number;
|
|
13
|
-
readonly expires?: Date;
|
|
14
|
-
/** Default `true`: a page's script cannot read it. */
|
|
15
|
-
readonly httpOnly?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Default `true`: sent only over HTTPS. On plain HTTP to this machine —
|
|
18
|
-
* `localhost`, `127.0.0.1` or `[::1]` — the default is `false`, because
|
|
19
|
-
* Safari drops a `Secure` cookie there. Say `false` for plain HTTP
|
|
20
|
-
* anywhere else.
|
|
21
|
-
*/
|
|
22
|
-
readonly secure?: boolean;
|
|
23
|
-
/** Default `'lax'`. `'none'` needs `secure`, and defaults to it. */
|
|
24
|
-
readonly sameSite?: 'strict' | 'lax' | 'none';
|
|
25
|
-
};
|
|
26
|
-
/** Where a cookie lives, which is what deleting one has to name again. */
|
|
27
|
-
type CookieScope = Pick<CookieOptions, 'path' | 'domain'>;
|
|
28
|
-
/**
|
|
29
|
-
* The request's cookies, and what this answer does to them. A read sees the
|
|
30
|
-
* writes made earlier in the same request; the browser sees them as
|
|
31
|
-
* `Set-Cookie` on the answer.
|
|
32
|
-
*/
|
|
33
|
-
type Cookies = {
|
|
34
|
-
readonly get: (name: string) => string | undefined;
|
|
35
|
-
readonly has: (name: string) => boolean;
|
|
36
|
-
readonly set: (name: string, value: string, options?: CookieOptions) => void;
|
|
37
|
-
readonly delete: (name: string, scope?: CookieScope) => void;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* What a `guard.ts` receives: the request, and the params of the pattern its
|
|
41
|
-
* directory puts it under, as the strings the pathname carried — a guard runs
|
|
42
|
-
* above the page and every layout, where no schema has typed them.
|
|
43
|
-
*/
|
|
44
|
-
type GuardContext<P extends string = string> = {
|
|
45
|
-
readonly request: Request;
|
|
46
|
-
readonly params: ParamsOf<P>;
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* What a `guard.ts` default-exports. A `Response` ends the request there — a
|
|
50
|
-
* redirect, a `401` — and returning nothing lets it through to what answers
|
|
51
|
-
* below. There is no `next()` to run the page and rewrite its answer: a page
|
|
52
|
-
* streams, and its headers leave before its body is written.
|
|
53
|
-
*/
|
|
54
|
-
type Guard<P extends string = string> = (context: GuardContext<P>) => Response | void | Promise<Response | void>;
|
|
55
|
-
/** What a `redirect.ts` route file default-exports. */
|
|
56
|
-
type RedirectTarget = string | {
|
|
57
|
-
readonly to: string;
|
|
58
|
-
readonly permanent?: boolean;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Ends a Server Action by sending the visitor somewhere else. Thrown, so an
|
|
62
|
-
* action reads the way it did before the redirect was added — the lines
|
|
63
|
-
* after it never run. A form posted without JavaScript is answered with a
|
|
64
|
-
* `303` to `to`; one posted by the client runtime is answered with a
|
|
65
|
-
* payload that tells the browser to navigate there.
|
|
66
|
-
*/
|
|
67
|
-
export declare const redirect: (to: string) => never;
|
|
68
|
-
/**
|
|
69
|
-
* What a page may read of the request under mode: 'server': the headers
|
|
70
|
-
* and the cookies, read-only. Nothing that would let a page write to the
|
|
71
|
-
* response — status, `Set-Cookie` — because a page is a render, and a render
|
|
72
|
-
* that answered the request would be the second handler.
|
|
73
|
-
*/
|
|
74
|
-
type RouteRequest = {
|
|
75
|
-
readonly headers: Headers;
|
|
76
|
-
readonly cookies: ReadonlyMap<string, string>;
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* The headers the final response will carry, whatever answers the request.
|
|
80
|
-
* Set from a `guard.ts` that lets the request through — a
|
|
81
|
-
* `Content-Security-Policy`, say — or from one that ends it, or from a
|
|
82
|
-
* Server Action: they are added to the answer. A header the answer already
|
|
83
|
-
* carries is replaced.
|
|
84
|
-
*/
|
|
85
|
-
export declare const responseHeaders: () => Headers;
|
|
86
|
-
/**
|
|
87
|
-
* The request's cookies, to read and to write: what the request carried,
|
|
88
|
-
* with what this answer set or deleted since, and every write said as a
|
|
89
|
-
* `Set-Cookie` on the answer. From a `guard.ts`, a `route.ts` or a Server
|
|
90
|
-
* Action; a page
|
|
91
|
-
* reads `request.cookies` from its props.
|
|
92
|
-
*/
|
|
93
|
-
export declare const cookies: () => Cookies;
|
|
94
|
-
/**
|
|
95
|
-
* The headers the request arrived with — for a Server Action, which is
|
|
96
|
-
* handed its arguments rather than the request. Read them; they are the
|
|
97
|
-
* request's own.
|
|
98
|
-
*/
|
|
99
|
-
export declare const requestHeaders: () => Headers;
|
|
100
|
-
/**
|
|
101
|
-
* The nonce this answer's inline scripts carry: the framework's own — the
|
|
102
|
-
* payload written into the HTML, React's — and any the application signs
|
|
103
|
-
* with it, as `<ColorSchemeProvider nonce={nonce()}>`. A new one per
|
|
104
|
-
* request. Readable wherever the request is in progress, the render
|
|
105
|
-
* included: signing a script is not writing the response. A guard names it
|
|
106
|
-
* in the `Content-Security-Policy` it writes; a build into files turns what
|
|
107
|
-
* carries it into hashes.
|
|
108
|
-
*/
|
|
109
|
-
export declare const nonce: () => string;
|
|
110
|
-
export type { CookieOptions, CookieScope, Cookies, Guard, GuardContext, RedirectTarget, RouteRequest };
|