@k8ordo/framework 1.2.0 → 1.2.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/runtime/app-router.mjs +1 -1
- package/dist/runtime/client-ready.d.mts +12 -8
- package/dist/runtime/client-ready.mjs +25 -14
- package/dist/runtime/entry.browser.mjs +1 -1
- package/dist/runtime/entry.rsc.mjs +2 -2
- package/dist/runtime/entry.ssr.d.mts +1 -1
- package/dist/runtime/entry.ssr.mjs +27 -10
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ dependencies in either mode: the build bundles what the application runs.
|
|
|
35
35
|
|
|
36
36
|
| Package | Version | Required | Needed for |
|
|
37
37
|
| --------------------- | -------- | -------- | ------------------------------------------ |
|
|
38
|
-
| `@k8ordo/router` | ^1.2.
|
|
38
|
+
| `@k8ordo/router` | ^1.2.1 | yes | routing, re-exported by the framework |
|
|
39
39
|
| `react` | ≥19.3.0 | yes | rendering |
|
|
40
40
|
| `react-dom` | ≥19.3.0 | yes | rendering |
|
|
41
41
|
| `vite` | ≥8.0.0 | yes | the build (`framework()` is a Vite plugin) |
|
|
@@ -43,7 +43,7 @@ const canRender = (payload) => payload.client === documentClient;
|
|
|
43
43
|
* except under a `<Suspense>`, whose fallback stands in for it as a
|
|
44
44
|
* transition leaves it.
|
|
45
45
|
*/
|
|
46
|
-
const WHEN_APPLIED = {
|
|
46
|
+
const WHEN_APPLIED = { rows: "leave" };
|
|
47
47
|
/**
|
|
48
48
|
* How many trees navigations have applied — the router's, and `vite dev`'s
|
|
49
49
|
* reload of the page on screen. A Server Action's answer is not counted:
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
//#region src/runtime/client-ready.d.ts
|
|
2
2
|
export type ClientReadyOptions = {
|
|
3
3
|
/**
|
|
4
|
-
* What to do with a row still on its way
|
|
5
|
-
*
|
|
6
|
-
* leaves it — a page streaming what it put under a boundary of its own
|
|
4
|
+
* What to do with a row still on its way: `'wait'` for it; `'leave'` one
|
|
5
|
+
* inside a `<Suspense>` to that boundary's fallback, as a transition
|
|
6
|
+
* leaves it — a page streaming what it put under a boundary of its own —
|
|
7
|
+
* and wait for the rest; or `'follow'` every one — settle without it, and
|
|
8
|
+
* walk it once it arrives, as an HTML render streaming it does.
|
|
7
9
|
*/
|
|
8
|
-
readonly
|
|
10
|
+
readonly rows: 'wait' | 'leave' | 'follow';
|
|
9
11
|
};
|
|
10
12
|
/**
|
|
11
13
|
* Settles once the client components a payload's trees name have loaded.
|
|
@@ -19,9 +21,11 @@ export type ClientReadyOptions = {
|
|
|
19
21
|
* holding elements), arrays and plain objects, each once, since a payload
|
|
20
22
|
* shares and nests them. A row still on its way (a lazy node: what a page
|
|
21
23
|
* sends once its data is in) is waited for and walked too, except as
|
|
22
|
-
* `
|
|
23
|
-
*
|
|
24
|
-
*
|
|
24
|
+
* `rows` says. A row followed is still walked once it arrives, the promise
|
|
25
|
+
* already settled, and a client component it names is read once it has
|
|
26
|
+
* loaded, as one waited for is. What fails — a row the server could not
|
|
27
|
+
* render, a module that would not load — ends the wait there, for the
|
|
28
|
+
* render to meet where an error boundary takes it.
|
|
25
29
|
*/
|
|
26
|
-
export declare const whenClientReady: (trees: readonly unknown[], {
|
|
30
|
+
export declare const whenClientReady: (trees: readonly unknown[], { rows }: ClientReadyOptions) => Promise<void>;
|
|
27
31
|
//#endregion
|
|
@@ -35,23 +35,39 @@ const whenSettled = (thenable) => new Promise((resolve) => {
|
|
|
35
35
|
* holding elements), arrays and plain objects, each once, since a payload
|
|
36
36
|
* shares and nests them. A row still on its way (a lazy node: what a page
|
|
37
37
|
* sends once its data is in) is waited for and walked too, except as
|
|
38
|
-
* `
|
|
39
|
-
*
|
|
40
|
-
*
|
|
38
|
+
* `rows` says. A row followed is still walked once it arrives, the promise
|
|
39
|
+
* already settled, and a client component it names is read once it has
|
|
40
|
+
* loaded, as one waited for is. What fails — a row the server could not
|
|
41
|
+
* render, a module that would not load — ends the wait there, for the
|
|
42
|
+
* render to meet where an error boundary takes it.
|
|
41
43
|
*/
|
|
42
|
-
const whenClientReady = async (trees, {
|
|
44
|
+
const whenClientReady = async (trees, { rows }) => {
|
|
43
45
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
44
46
|
let waiting = [];
|
|
47
|
+
const settle = async () => {
|
|
48
|
+
while (waiting.length > 0) {
|
|
49
|
+
const round = waiting;
|
|
50
|
+
waiting = [];
|
|
51
|
+
await Promise.all(round.map(({ until }) => whenSettled(until)));
|
|
52
|
+
for (const { again } of round) again();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
45
55
|
const read = (lazy, inside, isType) => {
|
|
46
56
|
let value;
|
|
47
57
|
try {
|
|
48
58
|
value = lazy._init(lazy._payload);
|
|
49
59
|
} catch (thrown) {
|
|
50
|
-
if (isThenable(thrown)
|
|
60
|
+
if (!isThenable(thrown)) return;
|
|
61
|
+
const again = () => {
|
|
62
|
+
read(lazy, inside, isType);
|
|
63
|
+
};
|
|
64
|
+
if (isType || rows === "wait" || rows === "leave" && !inside) waiting.push({
|
|
51
65
|
until: thrown,
|
|
52
|
-
again
|
|
53
|
-
|
|
54
|
-
|
|
66
|
+
again
|
|
67
|
+
});
|
|
68
|
+
else if (rows === "follow") whenSettled(thrown).then(() => {
|
|
69
|
+
again();
|
|
70
|
+
return settle();
|
|
55
71
|
});
|
|
56
72
|
return;
|
|
57
73
|
}
|
|
@@ -78,12 +94,7 @@ const whenClientReady = async (trees, { inSuspense }) => {
|
|
|
78
94
|
if (isPlain(value)) for (const prop of Object.values(value)) visit(prop, inside);
|
|
79
95
|
};
|
|
80
96
|
for (const tree of trees) visit(tree, false);
|
|
81
|
-
|
|
82
|
-
const round = waiting;
|
|
83
|
-
waiting = [];
|
|
84
|
-
await Promise.all(round.map(({ until }) => whenSettled(until)));
|
|
85
|
-
for (const { again } of round) again();
|
|
86
|
-
}
|
|
97
|
+
await settle();
|
|
87
98
|
};
|
|
88
99
|
//#endregion
|
|
89
100
|
export { whenClientReady };
|
|
@@ -13,7 +13,7 @@ const start = async () => {
|
|
|
13
13
|
const payload = await createFromReadableStream(rscStream);
|
|
14
14
|
setDocumentClient(payload.client);
|
|
15
15
|
await whenRevealed();
|
|
16
|
-
await whenClientReady([payload.tree, payload.notFound], {
|
|
16
|
+
await whenClientReady([payload.tree, payload.notFound], { rows: "wait" });
|
|
17
17
|
mount(document, /* @__PURE__ */ jsx(AppRouter, {
|
|
18
18
|
notFound: payload.notFound,
|
|
19
19
|
pathname: payload.pathname,
|
|
@@ -351,7 +351,7 @@ const respond = async (request) => {
|
|
|
351
351
|
if (import.meta.env.K8ORDO_MODE === "static") {
|
|
352
352
|
let body;
|
|
353
353
|
try {
|
|
354
|
-
const html = await enter(() => ssr.renderHtml(rendered.stream, signingNonce(), showsPage));
|
|
354
|
+
const html = await enter(() => ssr.renderHtml(rendered.stream, signingNonce(), showsPage, action.formState !== void 0));
|
|
355
355
|
body = await new Response(html).arrayBuffer();
|
|
356
356
|
} catch (error) {
|
|
357
357
|
return renderFailed(rendered.failures[0] ?? error);
|
|
@@ -368,7 +368,7 @@ const respond = async (request) => {
|
|
|
368
368
|
}
|
|
369
369
|
});
|
|
370
370
|
}
|
|
371
|
-
const html = await enter(() => ssr.renderHtml(rendered.stream, signingNonce(), showsPage));
|
|
371
|
+
const html = await enter(() => ssr.renderHtml(rendered.stream, signingNonce(), showsPage, action.formState !== void 0));
|
|
372
372
|
return new Response(html, {
|
|
373
373
|
status,
|
|
374
374
|
headers: { "content-type": HTML_TYPE }
|
|
@@ -12,5 +12,5 @@ export declare const clientEntry: string;
|
|
|
12
12
|
* one round trip. It is also what lets a prerendered `404.html` come alive —
|
|
13
13
|
* there is no payload file at a URL the application does not have.
|
|
14
14
|
*/
|
|
15
|
-
export declare function renderHtml(rscStream: ReadableStream<Uint8Array>, nonce: string, showsPage: boolean): Promise<ReadableStream>;
|
|
15
|
+
export declare function renderHtml(rscStream: ReadableStream<Uint8Array>, nonce: string, showsPage: boolean, carriesFormState: boolean): Promise<ReadableStream>;
|
|
16
16
|
//#endregion
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { whenClientReady } from "./client-ready.mjs";
|
|
1
2
|
import { AppRouter } from "./app-router.mjs";
|
|
2
3
|
import { noticeCancel } from "./cancel.mjs";
|
|
3
4
|
import { PageShownContext } from "./page-shown.mjs";
|
|
5
|
+
import { use } from "react";
|
|
4
6
|
import { jsx } from "react/jsx-runtime";
|
|
5
7
|
import { createFromReadableStream, getClientEntryUrl } from "@vitejs/plugin-rsc/ssr";
|
|
6
8
|
import { renderToReadableStream } from "react-dom/server.edge";
|
|
@@ -19,23 +21,38 @@ const clientEntry = getClientEntryUrl();
|
|
|
19
21
|
* one round trip. It is also what lets a prerendered `404.html` come alive —
|
|
20
22
|
* there is no payload file at a URL the application does not have.
|
|
21
23
|
*/
|
|
22
|
-
async function renderHtml(rscStream, nonce, showsPage) {
|
|
23
|
-
const [
|
|
24
|
-
|
|
24
|
+
async function renderHtml(rscStream, nonce, showsPage, carriesFormState) {
|
|
25
|
+
const [forRender, forHydration] = rscStream.tee();
|
|
26
|
+
let forHtml = forRender;
|
|
27
|
+
let formState;
|
|
28
|
+
if (carriesFormState) {
|
|
29
|
+
const [forState, rest] = forRender.tee();
|
|
30
|
+
forHtml = rest;
|
|
31
|
+
({formState} = await createFromReadableStream(forState, { nonce }));
|
|
32
|
+
}
|
|
33
|
+
let payload;
|
|
34
|
+
let ready;
|
|
35
|
+
function Root() {
|
|
36
|
+
payload ??= createFromReadableStream(forHtml, { nonce });
|
|
37
|
+
const { notFound, pathname, search, tree } = use(payload);
|
|
38
|
+
ready ??= whenClientReady([tree, notFound], { rows: import.meta.env.K8ORDO_MODE === "static" ? "wait" : "follow" });
|
|
39
|
+
use(ready);
|
|
40
|
+
return /* @__PURE__ */ jsx(AppRouter, {
|
|
41
|
+
notFound,
|
|
42
|
+
pathname,
|
|
43
|
+
search,
|
|
44
|
+
tree
|
|
45
|
+
});
|
|
46
|
+
}
|
|
25
47
|
const shown = Promise.withResolvers();
|
|
26
48
|
let readerLeft = false;
|
|
27
49
|
const htmlStream = await renderToReadableStream(/* @__PURE__ */ jsx(PageShownContext, {
|
|
28
50
|
value: () => shown.resolve(void 0),
|
|
29
|
-
children: /* @__PURE__ */ jsx(
|
|
30
|
-
notFound: payload.notFound,
|
|
31
|
-
pathname: payload.pathname,
|
|
32
|
-
search: payload.search,
|
|
33
|
-
tree: payload.tree
|
|
34
|
-
})
|
|
51
|
+
children: /* @__PURE__ */ jsx(Root, {})
|
|
35
52
|
}), {
|
|
36
53
|
bootstrapModules: [clientEntry],
|
|
37
54
|
nonce,
|
|
38
|
-
formState
|
|
55
|
+
formState,
|
|
39
56
|
progressiveChunkSize: Number.POSITIVE_INFINITY,
|
|
40
57
|
onError: (error) => {
|
|
41
58
|
if (!readerLeft) console.error(error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k8ordo/framework",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.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",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@arethetypeswrong/cli": "0.18.5",
|
|
78
78
|
"@k8ordo/framework-engine": "^0.1.1",
|
|
79
|
-
"@k8ordo/router": "^1.2.
|
|
79
|
+
"@k8ordo/router": "^1.2.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": "^1.2.
|
|
95
|
+
"@k8ordo/router": "^1.2.1",
|
|
96
96
|
"oxc-transform-react": "^0.152.0",
|
|
97
97
|
"react": ">=19.3.0",
|
|
98
98
|
"react-dom": ">=19.3.0",
|