foldkit-ssr 0.10.0 → 0.12.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 +693 -61
- package/dist/{client-XnpTQZHw.d.ts → client-BEHlUHBv.d.ts} +10 -7
- package/dist/client-BEHlUHBv.d.ts.map +1 -0
- package/dist/client.d.ts +6 -5
- package/dist/client.js +66 -18
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/context.js.map +1 -1
- package/dist/diagnostics.d.ts +2 -2
- package/dist/diagnostics.js +14 -1
- package/dist/diagnostics.js.map +1 -1
- package/dist/handoff.d.ts +23 -0
- package/dist/handoff.d.ts.map +1 -0
- package/dist/handoff.js +15 -0
- package/dist/handoff.js.map +1 -0
- package/dist/index.d.ts +108 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +386 -51
- package/dist/index.js.map +1 -1
- package/dist/keep.d.ts +5 -1
- package/dist/keep.d.ts.map +1 -1
- package/dist/keep.js +55 -11
- package/dist/keep.js.map +1 -1
- package/dist/{listen-DaUPRKVR.d.ts → listen-7HzKBhqU.d.ts} +11 -2
- package/dist/{listen-DaUPRKVR.d.ts.map → listen-7HzKBhqU.d.ts.map} +1 -1
- package/dist/listen.d.ts +2 -2
- package/dist/listen.js +17 -7
- package/dist/listen.js.map +1 -1
- package/dist/loader.d.ts +13 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +156 -0
- package/dist/loader.js.map +1 -0
- package/dist/marks-CX15BwOw.d.ts +39 -0
- package/dist/marks-CX15BwOw.d.ts.map +1 -0
- package/dist/marks.d.ts +2 -0
- package/dist/marks.js +41 -0
- package/dist/marks.js.map +1 -0
- package/dist/pageCache-DO0pOgnc.d.ts +80 -0
- package/dist/pageCache-DO0pOgnc.d.ts.map +1 -0
- package/dist/pageCache.d.ts +2 -0
- package/dist/pageCache.js +112 -0
- package/dist/pageCache.js.map +1 -0
- package/dist/{requestContext-D9nsbGSJ.d.ts → requestContext-DmwmQeci.d.ts} +12 -2
- package/dist/requestContext-DmwmQeci.d.ts.map +1 -0
- package/dist/requestContext.d.ts +2 -2
- package/dist/requestContext.js +30 -13
- package/dist/requestContext.js.map +1 -1
- package/dist/{resumable-BPN_qQHU.d.ts → resumable-BV9_OKxr.d.ts} +7 -10
- package/dist/resumable-BV9_OKxr.d.ts.map +1 -0
- package/dist/resumable.d.ts +2 -1
- package/dist/resumable.js +16 -19
- package/dist/resumable.js.map +1 -1
- package/dist/runtimeChunk.d.ts +13 -0
- package/dist/runtimeChunk.d.ts.map +1 -0
- package/dist/runtimeChunk.js +36 -0
- package/dist/runtimeChunk.js.map +1 -0
- package/dist/runtimeUrl.d.ts +10 -0
- package/dist/runtimeUrl.d.ts.map +1 -0
- package/dist/runtimeUrl.js +13 -0
- package/dist/runtimeUrl.js.map +1 -0
- package/dist/{shared-DbupL3vO.d.ts → shared-mQ8CXr-r.d.ts} +69 -22
- package/dist/shared-mQ8CXr-r.d.ts.map +1 -0
- package/dist/shared.d.ts +3 -2
- package/dist/shared.js +40 -18
- package/dist/shared.js.map +1 -1
- package/dist/vite.d.ts +3 -2
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +2 -1
- package/dist/vite.js.map +1 -1
- package/package.json +11 -6
- package/dist/client-XnpTQZHw.d.ts.map +0 -1
- package/dist/requestContext-D9nsbGSJ.d.ts.map +0 -1
- package/dist/resumable-BPN_qQHU.d.ts.map +0 -1
- package/dist/shared-DbupL3vO.d.ts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { o as listen } from "./listen-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { o as listen } from "./listen-7HzKBhqU.js";
|
|
2
|
+
import { m as view, p as builder } from "./resumable-BV9_OKxr.js";
|
|
3
|
+
import { A as resume, D as plan, F as staticRegion, L as unbound, N as serving, b as bindings, d as ResumePlan, l as ResumableConfig } from "./shared-mQ8CXr-r.js";
|
|
4
4
|
import { Effect, Schema } from "effect";
|
|
5
5
|
import { Diagnostic as Diagnostic$1, Diagnostics as Diagnostics$1, ReportDiagnostic, ReportDiagnostic as ReportDiagnostic$1 } from "foldkit-surface";
|
|
6
6
|
/**
|
|
@@ -12,6 +12,10 @@ import { Diagnostic as Diagnostic$1, Diagnostics as Diagnostics$1, ReportDiagnos
|
|
|
12
12
|
* by Foldkit's own refusal, and the reason is reported (`options.diagnostics`). A server page is never
|
|
13
13
|
* rendered again on the client. A page with no server render at all, no
|
|
14
14
|
* stamped root, is rendered on the client as usual.
|
|
15
|
+
*
|
|
16
|
+
* Run by `foldkit-ssr/loader`, it starts now, whatever the plan's `start`
|
|
17
|
+
* (the loader followed it), and answers each event the loader held from the
|
|
18
|
+
* markers, once. A page that does not resume releases them to the browser.
|
|
15
19
|
*/
|
|
16
20
|
declare const hydrate: <Model, Fields extends Schema.Struct.Fields, Message = any>(config: ResumableConfig<Model, Message>, plan: ResumePlan<Model, Fields>, options: {
|
|
17
21
|
readonly buildId: string;
|
|
@@ -64,8 +68,6 @@ declare const hydrate: <Model, Fields extends Schema.Struct.Fields, Message = an
|
|
|
64
68
|
*/
|
|
65
69
|
readonly diagnostics?: ReportDiagnostic | undefined;
|
|
66
70
|
}) => void;
|
|
67
|
-
/** The longest a served page stays in view while a fresh application waits for `until`. */
|
|
68
|
-
declare const UNTIL_LIMIT_MS = 3000;
|
|
69
71
|
/** The resumable track: bindings the server's markup names, so a page can answer before it boots. */
|
|
70
72
|
declare const Resume: {
|
|
71
73
|
builder: typeof builder;
|
|
@@ -79,7 +81,8 @@ declare const SSR: {
|
|
|
79
81
|
resume: typeof resume;
|
|
80
82
|
hydrate: typeof hydrate;
|
|
81
83
|
static: typeof staticRegion;
|
|
84
|
+
unbound: typeof unbound;
|
|
82
85
|
serving: typeof serving;
|
|
83
86
|
};
|
|
84
|
-
export { SSR as a, Resume as i, Diagnostics$1 as n,
|
|
85
|
-
//# sourceMappingURL=client-
|
|
87
|
+
export { SSR as a, Resume as i, Diagnostics$1 as n, ReportDiagnostic$1 as r, Diagnostic$1 as t };
|
|
88
|
+
//# sourceMappingURL=client-BEHlUHBv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-BEHlUHBv.d.ts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;;;;;;;;;;;;;;;cA0FM,UAAW,OAAO,eAAe,OAAO,OAAO,QAAQ,eAAa,QAChE,gBAAgB,OAAO,UAAQ,MACjC,WAAW,OAAO,SAAO;WAEpB;;;;;;;WAOA,SAAS,MAAM;;;;;;;WAOf;;;;;;;;WAQA,UAAU,OAAO;;;;;;;;WAQjB,UAAU;;;;;;;;;;WAUV,YAAY,OAAO,UAAU,OAAO,OAAO;;;;;;;;WAQ3C,cAAc;;;cAmad;;;;;;;cAGA"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
5
|
-
|
|
1
|
+
import { a as UNTIL_LIMIT_MS, i as RESUME_ATTRIBUTE, n as FOLDKIT_APP_ATTRIBUTE, r as KEEP_ATTRIBUTE, t as BINDING_ATTRIBUTE } from "./marks-CX15BwOw.js";
|
|
2
|
+
import { n as DecodedBinding } from "./listen-7HzKBhqU.js";
|
|
3
|
+
import { c as ResumableBuilder, i as FALLBACK_FIELD, l as SLOT_ATTRIBUTE } from "./resumable-BV9_OKxr.js";
|
|
4
|
+
import { G as BundleUnloaded, J as HeadNotMoved, K as CachedPageDiffers, Q as StaticRegionMissing, V as UnnamedHandler, X as PageFailed, Y as PageContained, Z as SsrDiagnostic, a as Meta, d as ResumePlan, f as ResumeRefused, g as Start, i as META_ATTRIBUTE, l as ResumableConfig, m as STATIC_ATTRIBUTE, q as HandlerUnnamed, r as Loadable, s as PlanSurface, u as ResumePart, w as metaMarkup } from "./shared-mQ8CXr-r.js";
|
|
5
|
+
import { a as SSR, i as Resume, n as Diagnostics, r as ReportDiagnostic, t as Diagnostic } from "./client-BEHlUHBv.js";
|
|
6
|
+
export { BINDING_ATTRIBUTE, type BundleUnloaded, type CachedPageDiffers, type DecodedBinding, type Diagnostic, Diagnostics, FALLBACK_FIELD, FOLDKIT_APP_ATTRIBUTE, type HandlerUnnamed, type HeadNotMoved, KEEP_ATTRIBUTE, type Loadable, META_ATTRIBUTE, type Meta, type PageContained, type PageFailed, type PlanSurface, RESUME_ATTRIBUTE, type ReportDiagnostic, type ResumableBuilder, type ResumableConfig, Resume, type ResumePart, type ResumePlan, ResumeRefused, SLOT_ATTRIBUTE, SSR, STATIC_ATTRIBUTE, type SsrDiagnostic, type Start, type StaticRegionMissing, UNTIL_LIMIT_MS, type UnnamedHandler, metaMarkup };
|
package/dist/client.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { withContext } from "./context.js";
|
|
2
|
-
import { bundleUnloaded, noBuildId, otherBuild, pageContained, reportingTo } from "./diagnostics.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { bundleUnloaded, headNotMoved, noBuildId, otherBuild, pageContained, reportingTo } from "./diagnostics.js";
|
|
3
|
+
import { claim } from "./handoff.js";
|
|
4
|
+
import { BINDING_ATTRIBUTE, FOLDKIT_APP_ATTRIBUTE, KEEP_ATTRIBUTE, RESUME_ATTRIBUTE, UNTIL_LIMIT_MS } from "./marks.js";
|
|
5
|
+
import { FALLBACK_DEPTH_FIELD, FALLBACK_FIELD, SLOT_ATTRIBUTE, builder, view } from "./resumable.js";
|
|
6
|
+
import { listen, listening } from "./listen.js";
|
|
5
7
|
import { hold, keptFields, restore, typedMessages } from "./keep.js";
|
|
6
|
-
import {
|
|
8
|
+
import { HEAD_MARKER, META_ATTRIBUTE, ResumeRefused, STATIC_ATTRIBUTE, arrival, bindings, bindingsAndEvents, metaEntry, metaMarkup, plan, resume, routeOf, serving, startingFrom, staticRegion, unbound } from "./shared.js";
|
|
7
9
|
import { Effect, Option, Result, Schema, Stream } from "effect";
|
|
8
10
|
import { hydrate, makeApplication, run } from "foldkit/runtime";
|
|
9
11
|
import * as Render from "foldkit/render";
|
|
@@ -32,11 +34,20 @@ const BUILD_ATTRIBUTE = "data-foldkit-build";
|
|
|
32
34
|
* by Foldkit's own refusal, and the reason is reported (`options.diagnostics`). A server page is never
|
|
33
35
|
* rendered again on the client. A page with no server render at all, no
|
|
34
36
|
* stamped root, is rendered on the client as usual.
|
|
37
|
+
*
|
|
38
|
+
* Run by `foldkit-ssr/loader`, it starts now, whatever the plan's `start`
|
|
39
|
+
* (the loader followed it), and answers each event the loader held from the
|
|
40
|
+
* markers, once. A page that does not resume releases them to the browser.
|
|
35
41
|
*/
|
|
36
42
|
const hydrate$1 = (config, plan, options) => {
|
|
37
43
|
const report = (diagnostic) => {
|
|
38
44
|
Effect.runFork(reportingTo(options.diagnostics)(Diagnostics$1.report(diagnostic)));
|
|
39
45
|
};
|
|
46
|
+
const loader = Option.fromNullishOr(claim());
|
|
47
|
+
const release = () => Option.match(loader, {
|
|
48
|
+
onNone: () => {},
|
|
49
|
+
onSome: (it) => it.release()
|
|
50
|
+
});
|
|
40
51
|
const planMeta = plan.meta;
|
|
41
52
|
if (planMeta !== void 0) config = {
|
|
42
53
|
...config,
|
|
@@ -46,10 +57,14 @@ const hydrate$1 = (config, plan, options) => {
|
|
|
46
57
|
}
|
|
47
58
|
};
|
|
48
59
|
const root = document.querySelector(`[${FOLDKIT_APP_ATTRIBUTE}]`);
|
|
49
|
-
if (root !== null)
|
|
60
|
+
if (root !== null) {
|
|
61
|
+
if (dropUnmovedHead(root)) report(headNotMoved);
|
|
62
|
+
keepStyles(root);
|
|
63
|
+
}
|
|
50
64
|
const declined = options.when !== void 0 && !options.when(document);
|
|
51
65
|
const stale = options.fresh !== void 0 && !options.fresh(plan.version);
|
|
52
66
|
if (root === null) {
|
|
67
|
+
release();
|
|
53
68
|
run(makeApplication(config));
|
|
54
69
|
return;
|
|
55
70
|
}
|
|
@@ -59,6 +74,7 @@ const hydrate$1 = (config, plan, options) => {
|
|
|
59
74
|
});
|
|
60
75
|
const contain = () => hydrate(program({ model: plan.baseline }), { buildId: "" });
|
|
61
76
|
if (declined || stale) {
|
|
77
|
+
release();
|
|
62
78
|
if (options.otherwise !== "render") contain();
|
|
63
79
|
else if (options.until === void 0) run(makeApplication({
|
|
64
80
|
...config,
|
|
@@ -69,24 +85,27 @@ const hydrate$1 = (config, plan, options) => {
|
|
|
69
85
|
}
|
|
70
86
|
if (typeof options.buildId !== "string") {
|
|
71
87
|
report(noBuildId);
|
|
88
|
+
release();
|
|
72
89
|
contain();
|
|
73
90
|
return;
|
|
74
91
|
}
|
|
75
92
|
const served = root.getAttribute(BUILD_ATTRIBUTE);
|
|
76
93
|
if (served !== options.buildId) {
|
|
77
94
|
report(otherBuild(Option.fromNullOr(served), options.buildId));
|
|
95
|
+
release();
|
|
78
96
|
hydrate(program({ model: plan.baseline }), { buildId: options.buildId });
|
|
79
97
|
return;
|
|
80
98
|
}
|
|
81
99
|
const resumed = resume(plan, document, { route: routeOf(window.location.href) });
|
|
82
100
|
if (Result.isFailure(resumed)) {
|
|
83
101
|
report(pageContained(resumed.failure.reason, resumed.failure.message));
|
|
102
|
+
release();
|
|
84
103
|
contain();
|
|
85
104
|
return;
|
|
86
105
|
}
|
|
87
106
|
const adoptFrom = (model) => {
|
|
88
107
|
const arrived = arrival(config, document, window.location.href);
|
|
89
|
-
const
|
|
108
|
+
const bootCommands = (started) => plan.boot?.(started) ?? [];
|
|
90
109
|
const resuming = {
|
|
91
110
|
mode: "resume",
|
|
92
111
|
snapshots: snapshotsOf(root),
|
|
@@ -112,13 +131,13 @@ const hydrate$1 = (config, plan, options) => {
|
|
|
112
131
|
const startOf = () => Option.match(arrived, {
|
|
113
132
|
onNone: () => ({
|
|
114
133
|
model,
|
|
115
|
-
commands
|
|
134
|
+
commands: bootCommands(model)
|
|
116
135
|
}),
|
|
117
136
|
onSome: (message) => {
|
|
118
137
|
const step = apply(model, message);
|
|
119
138
|
return {
|
|
120
139
|
model: step.model,
|
|
121
|
-
commands: [...
|
|
140
|
+
commands: [...bootCommands(step.model), ...step.commands ?? []]
|
|
122
141
|
};
|
|
123
142
|
}
|
|
124
143
|
});
|
|
@@ -137,26 +156,32 @@ const hydrate$1 = (config, plan, options) => {
|
|
|
137
156
|
}), { buildId: options.buildId });
|
|
138
157
|
};
|
|
139
158
|
const pending = (config.lazy ?? []).filter((bundle) => !bundle.isLoaded());
|
|
140
|
-
const start = Option.isSome(arrived) ? "now" : plan.start;
|
|
159
|
+
const start = Option.isSome(arrived) || Option.isSome(loader) ? "now" : plan.start;
|
|
141
160
|
const eager = start === "now" && pending.length === 0;
|
|
142
|
-
if (eager && root.querySelector(`[data-foldkit-plus-keep]`) === null) {
|
|
161
|
+
if (eager && Option.isNone(loader) && root.querySelector(`[data-foldkit-plus-keep]`) === null) {
|
|
143
162
|
boot();
|
|
144
163
|
return;
|
|
145
164
|
}
|
|
146
165
|
const decoded = bindingsAndEvents(plan, document, root, model);
|
|
147
166
|
if (Result.isFailure(decoded)) {
|
|
148
167
|
report(pageContained(decoded.failure.reason, decoded.failure.message));
|
|
168
|
+
release();
|
|
149
169
|
contain();
|
|
150
170
|
return;
|
|
151
171
|
}
|
|
152
172
|
const kept = keptFields(root, decoded.success.bindings);
|
|
153
173
|
if (Result.isFailure(kept)) {
|
|
154
174
|
report(pageContained("Invalid", kept.failure));
|
|
175
|
+
release();
|
|
155
176
|
contain();
|
|
156
177
|
return;
|
|
157
178
|
}
|
|
158
179
|
answered.push(...typedMessages(kept.success));
|
|
159
|
-
|
|
180
|
+
const held = Option.match(loader, {
|
|
181
|
+
onNone: () => [],
|
|
182
|
+
onSome: (it) => it.take()
|
|
183
|
+
});
|
|
184
|
+
if (eager && answered.length === 0 && held.length === 0) {
|
|
160
185
|
boot();
|
|
161
186
|
return;
|
|
162
187
|
}
|
|
@@ -164,11 +189,20 @@ const hydrate$1 = (config, plan, options) => {
|
|
|
164
189
|
deferBoot(root, decoded.success, typed, {
|
|
165
190
|
boot,
|
|
166
191
|
answered
|
|
167
|
-
}, pending, report, kept.success);
|
|
192
|
+
}, pending, report, kept.success, held);
|
|
168
193
|
};
|
|
169
194
|
const prepare = options.prepare;
|
|
170
|
-
|
|
171
|
-
|
|
195
|
+
let startingModel;
|
|
196
|
+
try {
|
|
197
|
+
startingModel = plan.restore === void 0 ? resumed.success : plan.restore(resumed.success);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
report(pageContained("Invalid", error instanceof Error ? error.message : String(error)));
|
|
200
|
+
release();
|
|
201
|
+
contain();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (prepare === void 0) adoptFrom(startingModel);
|
|
205
|
+
else Effect.runPromise(prepare(startingModel)).then(adoptFrom);
|
|
172
206
|
};
|
|
173
207
|
/**
|
|
174
208
|
* Takes out of the served page what the server wrote for this script to read
|
|
@@ -191,6 +225,20 @@ const unmark = (root) => {
|
|
|
191
225
|
}
|
|
192
226
|
};
|
|
193
227
|
/**
|
|
228
|
+
* Removes head markup `SSR.headed` should have moved out of the root (a plan's
|
|
229
|
+
* `meta`), saying whether there was any: the view does not draw it, and the
|
|
230
|
+
* plan's meta entry writes the head once the page runs.
|
|
231
|
+
*/
|
|
232
|
+
const dropUnmovedHead = (root) => {
|
|
233
|
+
const nodes = Array.from(root.childNodes);
|
|
234
|
+
const marks = (value) => (node) => node.nodeType === Node.COMMENT_NODE && node.nodeValue === value;
|
|
235
|
+
const open = nodes.findIndex(marks(HEAD_MARKER));
|
|
236
|
+
if (open === -1) return false;
|
|
237
|
+
const close = nodes.findIndex((node, at) => at > open && marks("/foldkit-plus-head")(node));
|
|
238
|
+
for (const node of nodes.slice(open, close === -1 ? void 0 : close + 1)) node.remove();
|
|
239
|
+
return true;
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
194
242
|
* Moves what a render's `styles` put in the root into the head, before
|
|
195
243
|
* anything adopts the page: the view does not draw it, so hydration would
|
|
196
244
|
* remove it, and a page that never renders again would lose the rules its
|
|
@@ -203,8 +251,6 @@ const keepStyles = (root) => {
|
|
|
203
251
|
else next.remove();
|
|
204
252
|
marker.remove();
|
|
205
253
|
};
|
|
206
|
-
/** The longest a served page stays in view while a fresh application waits for `until`. */
|
|
207
|
-
const UNTIL_LIMIT_MS = 3e3;
|
|
208
254
|
/**
|
|
209
255
|
* Runs the application afresh out of view, beside the served page, and puts
|
|
210
256
|
* it in the page's place once a Model it drew satisfies `until`, or after
|
|
@@ -260,11 +306,11 @@ const HANDOVER = Object.freeze({ _tag: "foldkit-ssr/Handover" });
|
|
|
260
306
|
* Each kept field the person changed is put back, value and selection, as
|
|
261
307
|
* the first render commits, since that render re-asserts the served value.
|
|
262
308
|
*/
|
|
263
|
-
const deferBoot = (root, decoded, start, runtime, pending, report, kept) => {
|
|
309
|
+
const deferBoot = (root, decoded, start, runtime, pending, report, kept, loaded) => {
|
|
264
310
|
const unanswered = [];
|
|
265
311
|
let phase = "waiting";
|
|
266
312
|
let held = [];
|
|
267
|
-
const stop =
|
|
313
|
+
const { stop, answer } = listening(root, {
|
|
268
314
|
bindings: decoded.bindings,
|
|
269
315
|
...decoded.events === void 0 ? {} : { events: decoded.events },
|
|
270
316
|
onAnswer: ({ event, messages, unnamed }) => {
|
|
@@ -317,6 +363,7 @@ const deferBoot = (root, decoded, start, runtime, pending, report, kept) => {
|
|
|
317
363
|
commit();
|
|
318
364
|
});
|
|
319
365
|
};
|
|
366
|
+
for (const { event, path } of loaded) answer(event, path);
|
|
320
367
|
if (start === "now") startNow();
|
|
321
368
|
else if (start === "idle") {
|
|
322
369
|
if (typeof window.requestIdleCallback === "function") window.requestIdleCallback(startNow);
|
|
@@ -336,6 +383,7 @@ const SSR = {
|
|
|
336
383
|
resume,
|
|
337
384
|
hydrate: hydrate$1,
|
|
338
385
|
static: staticRegion,
|
|
386
|
+
unbound,
|
|
339
387
|
serving
|
|
340
388
|
};
|
|
341
389
|
export { BINDING_ATTRIBUTE, Diagnostics, FALLBACK_FIELD, FOLDKIT_APP_ATTRIBUTE, KEEP_ATTRIBUTE, META_ATTRIBUTE, RESUME_ATTRIBUTE, Resume, ResumeRefused, SLOT_ATTRIBUTE, SSR, STATIC_ATTRIBUTE, UNTIL_LIMIT_MS, metaMarkup };
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":["hydrate","Diagnostics","adopt"],"sources":["../src/client.ts"],"sourcesContent":["/**\n * `foldkit-ssr/client`: what a browser page needs to take a server render\n * over, and nothing that renders one. It never imports\n * `foldkit/experimental/server`, whose renderer and HTML parser a hydrating\n * page would otherwise carry; `foldkit-ssr` is this and the server side.\n */\nimport { Effect, Option, Result, Schema, Stream } from 'effect'\nimport { hydrate as adopt, makeApplication, run } from 'foldkit/runtime'\nimport * as Render from 'foldkit/render'\nimport { Diagnostics, type ReportDiagnostic } from 'foldkit-surface'\nimport { withContext, type RenderContext } from './context.js'\nimport {\n bundleUnloaded,\n noBuildId,\n otherBuild,\n pageContained,\n reportingTo,\n type SsrDiagnostic,\n} from './diagnostics.js'\nimport { hold, keptFields, restore, typedMessages, type Held, type KeptField } from './keep.js'\nimport { listen, type DecodedBinding } from './listen.js'\nimport {\n BINDING_ATTRIBUTE,\n FALLBACK_DEPTH_FIELD,\n FALLBACK_FIELD,\n KEEP_ATTRIBUTE,\n SLOT_ATTRIBUTE,\n builder,\n view,\n} from './resumable.js'\nimport {\n FOLDKIT_APP_ATTRIBUTE,\n RESUME_ATTRIBUTE,\n STATIC_ATTRIBUTE,\n STYLES_MARKER,\n arrival,\n bindings,\n bindingsAndEvents,\n metaEntry,\n plan,\n resume,\n routeOf,\n serving,\n startingFrom,\n staticRegion,\n type Loadable,\n type ResumableConfig,\n type ResumePlan,\n type Start,\n} from './shared.js'\n\n/** Foldkit's root stamp, defined beside the envelope that rides on the same root. */\nexport { FOLDKIT_APP_ATTRIBUTE } from './shared.js'\n\n/** Each static region's markup in the page, read before hydration touches it. */\nconst snapshotsOf = (root: Element): ReadonlyMap<string, string> =>\n new Map(\n Array.from(root.querySelectorAll(`[${STATIC_ATTRIBUTE}]`), element => [\n element.getAttribute(STATIC_ATTRIBUTE) ?? '',\n element.innerHTML,\n ]),\n )\n\n/**\n * The build attribute on Foldkit's hydration root. Foldkit does not export it,\n * as it does the app and Flags attributes; a test pins it to what Foldkit's\n * server stamps.\n */\nconst BUILD_ATTRIBUTE = 'data-foldkit-build'\n\n/**\n * Starts the browser from the page's resumed Model, without running `init`.\n *\n * In the order Foldkit checks a page: the build id first, before the payload\n * is read, then the envelope and its route. A page from another build is\n * refused by Foldkit itself. A page that cannot resume is refused and contained\n * by Foldkit's own refusal, and the reason is reported (`options.diagnostics`). A server page is never\n * rendered again on the client. A page with no server render at all, no\n * stamped root, is rendered on the client as usual.\n */\nconst hydrate = <Model, Fields extends Schema.Struct.Fields, Message = any>(\n config: ResumableConfig<Model, Message>,\n plan: ResumePlan<Model, Fields>,\n options: {\n readonly buildId: string\n /**\n * Whether this page is taken over: asked before anything is adopted, so\n * a page showing another reader's data never becomes live facts. Omitted\n * adopts as before. Must not throw: a throwing predicate propagates out\n * of `hydrate` with no runtime booted and nothing contained.\n */\n readonly when?: ((page: Document) => boolean) | undefined\n /**\n * What a declined or stale page does: `render` runs the application\n * afresh where the rendered page is, replacing its markup in place (the\n * config's container with no served page). Omitted contains the page the\n * way a resume failure does.\n */\n readonly otherwise?: 'render' | undefined\n /**\n * With `otherwise: 'render'`, when the fresh application is ready to be\n * seen: until a Model it has drawn satisfies this, it draws out of view\n * and the served page stays, so a page is not swapped for its loading\n * state and back. Omitted, the fresh application replaces the page at\n * once. The served page stays no longer than `UNTIL_LIMIT_MS`.\n */\n readonly until?: ((model: Model) => boolean) | undefined\n /**\n * Whether the plan's data version is still current: asked once, with\n * `plan.version`, before anything is adopted. Omitted never asks. A plan\n * with no version still asks, with `undefined` (a check shaped like\n * `version === expected` then marks every such page stale). Must not\n * throw, as `when`.\n */\n readonly fresh?: ((version: unknown) => boolean) | undefined\n /**\n * What only this browser adds to the resumed Model before it is adopted,\n * and the view does not draw: a session minted for this page load (an\n * outbox's `session`). Run once, for a page that resumes; the runtime\n * starts when it succeeds. What the view draws, such as a queue read from\n * storage, arrives after, as a Message: here it would make the first\n * client view differ from the served page. Must not fail, as `when` must\n * not throw.\n */\n readonly prepare?: ((model: Model) => Effect.Effect<Model>) | undefined\n /**\n * Where what the page met goes: a page contained rather than resumed, a\n * static region the server's page lacked, a lazy bundle that did not\n * load. Each is reported before or apart from the runtime, so its\n * resources' reporter is not in effect. Omitted, Effect's log: the\n * browser's console.\n */\n readonly diagnostics?: ReportDiagnostic | undefined\n },\n): void => {\n const report = (diagnostic: SsrDiagnostic): void => {\n Effect.runFork(reportingTo(options.diagnostics)(Diagnostics.report(diagnostic)))\n }\n const planMeta = plan.meta\n if (planMeta !== undefined) {\n config = {\n ...config,\n subscriptions: { ...config.subscriptions, 'foldkit-ssr.meta': metaEntry(planMeta) },\n }\n }\n const root = document.querySelector<HTMLElement>(`[${FOLDKIT_APP_ATTRIBUTE}]`)\n if (root !== null) keepStyles(root)\n // A page that is declined or stale never adopts. `render` draws afresh at\n // the root's place, replacing it; anything else contains the served page.\n // With no served page the application renders afresh regardless.\n const declined = options.when !== undefined && !options.when(document)\n const stale = options.fresh !== undefined && !options.fresh(plan.version)\n if (root === null) {\n run(makeApplication(config as never))\n return\n }\n const program = (start: { readonly model: Model; readonly commands?: ReadonlyArray<unknown> }) =>\n makeApplication({ ...startingFrom(config, start), container: root } as never)\n // Contain the served page the way Foldkit refuses one: adopt the baseline\n // with an empty build id, with nothing copied here.\n const contain = () => adopt(program({ model: plan.baseline }), { buildId: '' })\n if (declined || stale) {\n if (options.otherwise !== 'render') contain()\n else if (options.until === undefined)\n run(makeApplication({ ...config, container: root } as never))\n else renderBeside(config, root, options.until)\n return\n }\n // The type says a string, but `import.meta.env` is `any`: with the variable\n // unset the id arrives undefined, and Foldkit, given none, takes its own\n // compiled id, which matches the page, so the baseline was adopted in silence.\n if (typeof options.buildId !== 'string') {\n report(noBuildId)\n contain()\n return\n }\n const served = root.getAttribute(BUILD_ATTRIBUTE)\n if (served !== options.buildId) {\n report(otherBuild(Option.fromNullOr(served), options.buildId))\n adopt(program({ model: plan.baseline }), { buildId: options.buildId })\n return\n }\n const resumed = resume(plan, document, { route: routeOf(window.location.href) })\n if (Result.isFailure(resumed)) {\n report(pageContained(resumed.failure.reason, resumed.failure.message))\n contain()\n return\n }\n const adoptFrom = (model: Model): void => {\n // A page recorded for its path, opened at a query: the application learns\n // the URL, as from a navigation, and the page starts now, since what it\n // shows is not yet the address.\n const arrived = arrival(config, document, window.location.href)\n const commands = (plan.boot?.(model) as ReadonlyArray<unknown> | undefined) ?? []\n const resuming: RenderContext = {\n mode: 'resume',\n snapshots: snapshotsOf(root),\n reported: new Set(),\n report,\n }\n // The runtime starts from the resumed Model, so its first render is the\n // served markup and Foldkit adopts every node. The Messages the page\n // answered before the live page listened wait in `answered`, and the first\n // Message the runtime processes, whatever it is, runs them through `update`\n // ahead of itself: they reach the Model before anything the live page\n // answers, an event dispatched in the task that boots it included.\n const answered: Array<unknown> = []\n // Each answered Message was decoded through the plan's Message Schema.\n const apply: ResumableConfig<Model>['update'] = config.update\n const update = (current: Model, message: unknown) => {\n const handingOver = message === HANDOVER\n if (answered.length === 0) return handingOver ? { model: current } : apply(current, message)\n const returned: Array<unknown> = []\n for (const next of [...answered.splice(0), ...(handingOver ? [] : [message])]) {\n const step = apply(current, next) as {\n readonly model: Model\n readonly commands?: ReadonlyArray<unknown> | undefined\n }\n current = step.model\n returned.push(...(step.commands ?? []))\n }\n return { model: current, commands: returned }\n }\n // The URL goes into the Model the runtime starts from, not into `answered`:\n // Subscriptions start from that Model before any Message lands, and a URL\n // mirror among them would write the served address back over the real one.\n // The first render then differs from the served page where the URL does, and\n // Foldkit rebuilds that part, as a navigation would redraw it. Applied at\n // boot, once any lazy bundle's `update` has loaded.\n const startOf = () =>\n Option.match(arrived, {\n onNone: () => ({ model, commands }),\n onSome: message => {\n const step = apply(model, message) as {\n readonly model: Model\n readonly commands?: ReadonlyArray<unknown> | undefined\n }\n return { model: step.model, commands: [...commands, ...(step.commands ?? [])] }\n },\n })\n const boot = (entries: Readonly<Record<string, unknown>> = {}) => {\n unmark(root)\n return adopt(\n makeApplication({\n ...withContext(startingFrom({ ...config, update }, startOf()), resuming),\n container: root,\n subscriptions: { ...config.subscriptions, ...entries },\n } as never),\n { buildId: options.buildId },\n )\n }\n const pending = (config.lazy ?? []).filter(bundle => !bundle.isLoaded())\n const start = Option.isSome(arrived) ? 'now' : plan.start\n const eager = start === 'now' && pending.length === 0\n if (eager && root.querySelector(`[${KEEP_ATTRIBUTE}]`) === null) {\n boot()\n return\n }\n const decoded = bindingsAndEvents(plan, document, root, model)\n if (Result.isFailure(decoded)) {\n report(pageContained(decoded.failure.reason, decoded.failure.message))\n contain()\n return\n }\n const kept = keptFields(root, decoded.success.bindings)\n if (Result.isFailure(kept)) {\n report(pageContained('Invalid', kept.failure))\n contain()\n return\n }\n // What was typed before this script ran, first in the queue: everything the\n // page answers from here on happened after it.\n answered.push(...typedMessages(kept.success))\n if (eager && answered.length === 0) {\n boot()\n return\n }\n // Typing is an interaction, whenever it happened: a page that waits for\n // one starts now, so what was typed is answered as soon as the script runs.\n const typed = answered.length > 0 ? 'now' : start\n deferBoot(root, decoded.success, typed, { boot, answered }, pending, report, kept.success)\n }\n const prepare = options.prepare\n if (prepare === undefined) adoptFrom(resumed.success)\n else void Effect.runPromise(prepare(resumed.success)).then(adoptFrom)\n}\n\n/**\n * Takes out of the served page what the server wrote for this script to read\n * and no view draws: the envelope, each binding's and kept field's marker,\n * each placement's slot, and each form's fallback (its `method` and hidden\n * fields). Left in, each is in what Foldkit records of the served page and\n * gone after its first patch, so Foldkit reconciles every such element, and\n * a development build reports that the server's markup and the view\n * disagree. Run as the page boots, so a form submitted before then still\n * posts.\n */\nconst unmark = (root: Element): void => {\n root.removeAttribute(RESUME_ATTRIBUTE)\n for (const element of [root, ...root.querySelectorAll('*')]) {\n for (const name of element.getAttributeNames()) {\n if (name.startsWith(BINDING_ATTRIBUTE) || name === KEEP_ATTRIBUTE || name === SLOT_ATTRIBUTE)\n element.removeAttribute(name)\n }\n }\n for (const field of root.querySelectorAll(`input[type=\"hidden\"][name=\"${FALLBACK_FIELD}\"]`)) {\n const form = field.parentElement\n form?.removeAttribute('method')\n form?.querySelector(`:scope > input[type=\"hidden\"][name=\"${FALLBACK_DEPTH_FIELD}\"]`)?.remove()\n field.remove()\n }\n}\n\n/**\n * Moves what a render's `styles` put in the root into the head, before\n * anything adopts the page: the view does not draw it, so hydration would\n * remove it, and a page that never renders again would lose the rules its\n * classes need. Whatever adopts the page next finds them in the head.\n */\nconst keepStyles = (root: Element): void => {\n const marker = Array.from(root.childNodes).find(\n node => node.nodeType === Node.COMMENT_NODE && node.nodeValue === STYLES_MARKER,\n )\n if (marker === undefined) return\n for (let next = marker.nextSibling; next !== null; next = marker.nextSibling) {\n if (next instanceof Element) document.head.append(next)\n else next.remove()\n }\n marker.remove()\n}\n\n/** The longest a served page stays in view while a fresh application waits for `until`. */\nexport const UNTIL_LIMIT_MS = 3000\n\n/**\n * Runs the application afresh out of view, beside the served page, and puts\n * it in the page's place once a Model it drew satisfies `until`, or after\n * `UNTIL_LIMIT_MS`. It draws in a hidden element, not a detached one, so its\n * Mounts start in the document as they would in place.\n */\nconst renderBeside = <Model, Message>(\n config: ResumableConfig<Model, Message>,\n served: HTMLElement,\n until: (model: Model) => boolean,\n): void => {\n const holder = document.createElement('div')\n holder.hidden = true\n const container = document.createElement('div')\n // The runtime refuses a container without an id; the served page gives its own up.\n container.id = served.id === '' ? 'foldkit-ssr-app' : served.id\n served.removeAttribute('id')\n // Nor does it boot beside a page stamped as a server render, which this one,\n // never adopted, no longer is.\n served.removeAttribute(FOLDKIT_APP_ATTRIBUTE)\n holder.append(container)\n served.after(holder)\n let shown = false\n const show = () => {\n if (shown) return\n shown = true\n clearTimeout(limit)\n holder.replaceWith(...holder.childNodes)\n served.remove()\n }\n const limit = setTimeout(show, UNTIL_LIMIT_MS)\n const view: ResumableConfig<Model, Message>['view'] = (model, h) => {\n const drawn = config.view(model, h)\n // Shown once the drawing this view returns is patched in, which the\n // runtime does in the same task.\n if (!shown && until(model)) queueMicrotask(show)\n return drawn\n }\n run(makeApplication({ ...config, view, container } as never))\n}\n\n/**\n * The Message the handover entry sends so the runtime takes the answered\n * Messages when nothing else has asked it to. The wrapped `update` consumes\n * it; the application never sees it.\n */\nconst HANDOVER: unknown = Object.freeze({ _tag: 'foldkit-ssr/Handover' })\n\n/**\n * Lets the page answer from its bindings until something asks for the\n * runtime, then boots it and hands over to the live page.\n *\n * Every Message the page answers goes to `answered`, which the runtime takes\n * before its first Message. An event only the live page can answer is kept\n * and sent again to where it first went once the live page listens. The page\n * stops listening as soon as the runtime's first render has committed: when\n * `hydrate` returns, which Foldkit does today, or else when a handover\n * Subscription entry starts, after `Render.afterCommit`. When lazy bundles\n * must load first, the boot waits for them and the page keeps answering.\n * Each kept field the person changed is put back, value and selection, as\n * the first render commits, since that render re-asserts the served value.\n */\nconst deferBoot = (\n root: HTMLElement,\n decoded: {\n readonly bindings: ReadonlyArray<DecodedBinding>\n readonly events: ReadonlyArray<string> | undefined\n },\n start: Start,\n runtime: {\n readonly boot: (entries: Readonly<Record<string, unknown>>) => void\n readonly answered: Array<unknown>\n },\n pending: ReadonlyArray<Loadable>,\n report: (diagnostic: SsrDiagnostic) => void,\n kept: ReadonlyArray<KeptField>,\n): void => {\n // Events only the live page can answer, met before it listened.\n const unanswered: Array<{ readonly event: Event; readonly element: Element }> = []\n // `waiting` for an interaction or idle, `loading` bodies, `starting` the\n // runtime until its first render commits, then `live`.\n let phase: 'waiting' | 'loading' | 'starting' | 'live' = 'waiting'\n // The kept fields as the person left them, which the first render resets.\n let held: ReadonlyArray<Held> = []\n const stop = listen(root, {\n bindings: decoded.bindings,\n ...(decoded.events === undefined ? {} : { events: decoded.events }),\n onAnswer: ({ event, messages, unnamed }) => {\n // An answer the markers could not complete is left to the live page.\n if (unnamed !== undefined) {\n startNow()\n // Once the live page listens, this event reaches it in the rest of\n // its own dispatch; until then it is kept for the handover.\n if (phase !== 'live' && event.target instanceof Element) {\n unanswered.push({ event, element: event.target })\n }\n return\n }\n // Nothing answered it: it goes on to the page, a plain link to the\n // router, as it would have.\n if (messages.length === 0) {\n startNow()\n return\n }\n // Taken by the runtime before anything else. The live page must not\n // answer this one as well.\n runtime.answered.push(...messages)\n event.stopPropagation()\n startNow()\n },\n })\n const handOver = () => {\n if (phase === 'live') return\n phase = 'live'\n // Before the queue runs, so its Messages find the fields holding their values.\n restore(held)\n stop()\n for (const { event, element } of unanswered.splice(0)) {\n const Ctor = event.constructor as new (type: string, init: Event) => Event\n element.dispatchEvent(new Ctor(event.type, event))\n }\n }\n const commit = () => {\n phase = 'starting'\n held = hold(kept)\n runtime.boot({\n 'foldkit-ssr.handover': {\n dependenciesSchema: Schema.Null,\n modelToDependencies: () => null,\n // Foldkit strips the root's stamp just before its first patch, so a\n // stamped root still has a render to wait for.\n dependenciesToStream: () =>\n Stream.fromEffect(\n Effect.as(\n Effect.andThen(\n root.hasAttribute(FOLDKIT_APP_ATTRIBUTE) ? Render.afterCommit : Effect.void,\n Effect.sync(handOver),\n ),\n HANDOVER,\n ),\n ),\n },\n })\n if (!root.hasAttribute(FOLDKIT_APP_ATTRIBUTE)) handOver()\n }\n const startNow = () => {\n if (phase !== 'waiting') return\n phase = 'loading'\n if (pending.length === 0) {\n commit()\n return\n }\n void Promise.all(pending.map(bundle => bundle.load())).then(commit, (error: unknown) => {\n report(bundleUnloaded(error))\n commit()\n })\n }\n if (start === 'now') startNow()\n else if (start === 'idle') {\n if (typeof window.requestIdleCallback === 'function') window.requestIdleCallback(startNow)\n else setTimeout(startNow, 0)\n }\n}\n\n/** The resumable track: bindings the server's markup names, so a page can answer before it boots. */\nexport const Resume = { builder, view, bindings, listen }\n\n/** The browser's part of `SSR`: the same functions, without the server's. */\nexport const SSR = { plan, resume, hydrate, static: staticRegion, serving }\n\nexport {\n META_ATTRIBUTE,\n RESUME_ATTRIBUTE,\n STATIC_ATTRIBUTE,\n ResumeRefused,\n metaMarkup,\n type Loadable,\n type Meta,\n type PlanSurface,\n type ResumableConfig,\n type ResumePart,\n type ResumePlan,\n type Start,\n} from './shared.js'\nexport {\n BINDING_ATTRIBUTE,\n FALLBACK_FIELD,\n KEEP_ATTRIBUTE,\n SLOT_ATTRIBUTE,\n type ResumableBuilder,\n} from './resumable.js'\nexport type { DecodedBinding } from './listen.js'\nexport type { UnnamedHandler } from './context.js'\n/** The diagnostics channel `hydrate` reports into, re-exported so a page needs no other import. */\nexport { Diagnostics, type Diagnostic, type ReportDiagnostic } from 'foldkit-surface'\nexport type {\n BundleUnloaded,\n HandlerUnnamed,\n PageContained,\n PageFailed,\n SsrDiagnostic,\n StaticRegionMissing,\n} from './diagnostics.js'\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuDA,MAAM,eAAe,SACnB,IAAI,IACF,MAAM,KAAK,KAAK,iBAAiB,IAAI,iBAAiB,EAAE,IAAG,YAAW,CACpE,QAAQ,aAAA,0BAA6B,KAAK,IAC1C,QAAQ,SACV,CAAC,CACH;;;;;;AAOF,MAAM,kBAAkB;;;;;;;;;;;AAYxB,MAAMA,aACJ,QACA,MACA,YAmDS;CACT,MAAM,UAAU,eAAoC;EAClD,OAAO,QAAQ,YAAY,QAAQ,WAAW,CAAC,CAACC,cAAY,OAAO,UAAU,CAAC,CAAC;CACjF;CACA,MAAM,WAAW,KAAK;CACtB,IAAI,aAAa,KAAA,GACf,SAAS;EACP,GAAG;EACH,eAAe;GAAE,GAAG,OAAO;GAAe,oBAAoB,UAAU,QAAQ;EAAE;CACpF;CAEF,MAAM,OAAO,SAAS,cAA2B,IAAI,sBAAsB,EAAE;CAC7E,IAAI,SAAS,MAAM,WAAW,IAAI;CAIlC,MAAM,WAAW,QAAQ,SA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QAAa,IAAI,QAAQ,KAAI,WAAU,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,UAAmB;GACtF,OAAO,eAAe,KAAK,CAAC;GAC5B,OAAO;EACT,CAAC;CACH;CACA,IAAI,UAAU,OAAO,SAAS;MACzB,IAAI,UAAU,QAAQ;EACzB,IAAI,OAAO,OAAO,wBAAwB,YAAY,OAAO,oBAAoB,QAAQ;OACpF,WAAW,UAAU,CAAC;CAC7B;AACF;;AAGA,MAAa,SAAS;CAAE;CAAS;CAAM;CAAU;AAAO;;AAGxD,MAAa,MAAM;CAAE;CAAM;CAAQ,SAAA;CAAS,QAAQ;CAAc;AAAQ"}
|
|
1
|
+
{"version":3,"file":"client.js","names":["hydrate","Diagnostics","adopt"],"sources":["../src/client.ts"],"sourcesContent":["/**\n * `foldkit-ssr/client`: what a browser page needs to take a server render\n * over, and nothing that renders one. It never imports\n * `foldkit/experimental/server`, whose renderer and HTML parser a hydrating\n * page would otherwise carry; `foldkit-ssr` is this and the server side.\n */\nimport { Effect, Option, Result, Schema, Stream } from 'effect'\nimport { hydrate as adopt, makeApplication, run } from 'foldkit/runtime'\nimport * as Render from 'foldkit/render'\nimport { Diagnostics, type ReportDiagnostic } from 'foldkit-surface'\nimport { withContext, type RenderContext } from './context.js'\nimport {\n bundleUnloaded,\n headNotMoved,\n noBuildId,\n otherBuild,\n pageContained,\n reportingTo,\n type SsrDiagnostic,\n} from './diagnostics.js'\nimport { claim, type HeldEvent } from './handoff.js'\nimport { UNTIL_LIMIT_MS } from './marks.js'\nimport { hold, keptFields, restore, typedMessages, type Held, type KeptField } from './keep.js'\nimport { listen, listening, type DecodedBinding } from './listen.js'\nimport {\n BINDING_ATTRIBUTE,\n FALLBACK_DEPTH_FIELD,\n FALLBACK_FIELD,\n KEEP_ATTRIBUTE,\n SLOT_ATTRIBUTE,\n builder,\n view,\n} from './resumable.js'\nimport {\n FOLDKIT_APP_ATTRIBUTE,\n RESUME_ATTRIBUTE,\n STATIC_ATTRIBUTE,\n HEAD_END_MARKER,\n HEAD_MARKER,\n STYLES_MARKER,\n arrival,\n bindings,\n bindingsAndEvents,\n metaEntry,\n plan,\n resume,\n routeOf,\n serving,\n startingFrom,\n staticRegion,\n unbound,\n type Loadable,\n type ResumableConfig,\n type ResumePlan,\n type Start,\n} from './shared.js'\n\n/** Foldkit's root stamp, defined beside the envelope that rides on the same root. */\nexport { FOLDKIT_APP_ATTRIBUTE } from './shared.js'\n\n/** Each static region's markup in the page, read before hydration touches it. */\nconst snapshotsOf = (root: Element): ReadonlyMap<string, string> =>\n new Map(\n Array.from(root.querySelectorAll(`[${STATIC_ATTRIBUTE}]`), element => [\n element.getAttribute(STATIC_ATTRIBUTE) ?? '',\n element.innerHTML,\n ]),\n )\n\n/**\n * The build attribute on Foldkit's hydration root. Foldkit does not export it,\n * as it does the app and Flags attributes; a test pins it to what Foldkit's\n * server stamps.\n */\nconst BUILD_ATTRIBUTE = 'data-foldkit-build'\n\n/**\n * Starts the browser from the page's resumed Model, without running `init`.\n *\n * In the order Foldkit checks a page: the build id first, before the payload\n * is read, then the envelope and its route. A page from another build is\n * refused by Foldkit itself. A page that cannot resume is refused and contained\n * by Foldkit's own refusal, and the reason is reported (`options.diagnostics`). A server page is never\n * rendered again on the client. A page with no server render at all, no\n * stamped root, is rendered on the client as usual.\n *\n * Run by `foldkit-ssr/loader`, it starts now, whatever the plan's `start`\n * (the loader followed it), and answers each event the loader held from the\n * markers, once. A page that does not resume releases them to the browser.\n */\nconst hydrate = <Model, Fields extends Schema.Struct.Fields, Message = any>(\n config: ResumableConfig<Model, Message>,\n plan: ResumePlan<Model, Fields>,\n options: {\n readonly buildId: string\n /**\n * Whether this page is taken over: asked before anything is adopted, so\n * a page showing another reader's data never becomes live facts. Omitted\n * adopts as before. Must not throw: a throwing predicate propagates out\n * of `hydrate` with no runtime booted and nothing contained.\n */\n readonly when?: ((page: Document) => boolean) | undefined\n /**\n * What a declined or stale page does: `render` runs the application\n * afresh where the rendered page is, replacing its markup in place (the\n * config's container with no served page). Omitted contains the page the\n * way a resume failure does.\n */\n readonly otherwise?: 'render' | undefined\n /**\n * With `otherwise: 'render'`, when the fresh application is ready to be\n * seen: until a Model it has drawn satisfies this, it draws out of view\n * and the served page stays, so a page is not swapped for its loading\n * state and back. Omitted, the fresh application replaces the page at\n * once. The served page stays no longer than `UNTIL_LIMIT_MS`.\n */\n readonly until?: ((model: Model) => boolean) | undefined\n /**\n * Whether the plan's data version is still current: asked once, with\n * `plan.version`, before anything is adopted. Omitted never asks. A plan\n * with no version still asks, with `undefined` (a check shaped like\n * `version === expected` then marks every such page stale). Must not\n * throw, as `when`.\n */\n readonly fresh?: ((version: unknown) => boolean) | undefined\n /**\n * What only this browser adds to the resumed Model before it is adopted,\n * and the view does not draw: a session minted for this page load (an\n * outbox's `session`). Run once, for a page that resumes; the runtime\n * starts when it succeeds. What the view draws, such as a queue read from\n * storage, arrives after, as a Message: here it would make the first\n * client view differ from the served page. Must not fail, as `when` must\n * not throw.\n */\n readonly prepare?: ((model: Model) => Effect.Effect<Model>) | undefined\n /**\n * Where what the page met goes: a page contained rather than resumed, a\n * static region the server's page lacked, a lazy bundle that did not\n * load. Each is reported before or apart from the runtime, so its\n * resources' reporter is not in effect. Omitted, Effect's log: the\n * browser's console.\n */\n readonly diagnostics?: ReportDiagnostic | undefined\n },\n): void => {\n const report = (diagnostic: SsrDiagnostic): void => {\n Effect.runFork(reportingTo(options.diagnostics)(Diagnostics.report(diagnostic)))\n }\n const loader = Option.fromNullishOr(claim())\n // Every path below that does not resume the page lets the browser have what\n // the loader held: a held submission posts.\n const release = (): void => Option.match(loader, { onNone: () => {}, onSome: it => it.release() })\n const planMeta = plan.meta\n if (planMeta !== undefined) {\n config = {\n ...config,\n subscriptions: { ...config.subscriptions, 'foldkit-ssr.meta': metaEntry(planMeta) },\n }\n }\n const root = document.querySelector<HTMLElement>(`[${FOLDKIT_APP_ATTRIBUTE}]`)\n if (root !== null) {\n if (dropUnmovedHead(root)) report(headNotMoved)\n keepStyles(root)\n }\n // A page that is declined or stale never adopts. `render` draws afresh at\n // the root's place, replacing it; anything else contains the served page.\n // With no served page the application renders afresh regardless.\n const declined = options.when !== undefined && !options.when(document)\n const stale = options.fresh !== undefined && !options.fresh(plan.version)\n if (root === null) {\n release()\n run(makeApplication(config as never))\n return\n }\n const program = (start: { readonly model: Model; readonly commands?: ReadonlyArray<unknown> }) =>\n makeApplication({ ...startingFrom(config, start), container: root } as never)\n // Contain the served page the way Foldkit refuses one: adopt the baseline\n // with an empty build id, with nothing copied here.\n const contain = () => adopt(program({ model: plan.baseline }), { buildId: '' })\n if (declined || stale) {\n release()\n if (options.otherwise !== 'render') contain()\n else if (options.until === undefined)\n run(makeApplication({ ...config, container: root } as never))\n else renderBeside(config, root, options.until)\n return\n }\n // The type says a string, but `import.meta.env` is `any`: with the variable\n // unset the id arrives undefined, and Foldkit, given none, takes its own\n // compiled id, which matches the page, so the baseline was adopted in silence.\n if (typeof options.buildId !== 'string') {\n report(noBuildId)\n release()\n contain()\n return\n }\n const served = root.getAttribute(BUILD_ATTRIBUTE)\n if (served !== options.buildId) {\n report(otherBuild(Option.fromNullOr(served), options.buildId))\n release()\n adopt(program({ model: plan.baseline }), { buildId: options.buildId })\n return\n }\n const resumed = resume(plan, document, { route: routeOf(window.location.href) })\n if (Result.isFailure(resumed)) {\n report(pageContained(resumed.failure.reason, resumed.failure.message))\n release()\n contain()\n return\n }\n const adoptFrom = (model: Model): void => {\n // A page recorded for its path, opened at a query: the application learns\n // the URL, as from a navigation, and the page starts now, since what it\n // shows is not yet the address.\n const arrived = arrival(config, document, window.location.href)\n const bootCommands = (started: Model): ReadonlyArray<unknown> =>\n (plan.boot?.(started) as ReadonlyArray<unknown> | undefined) ?? []\n const resuming: RenderContext = {\n mode: 'resume',\n snapshots: snapshotsOf(root),\n reported: new Set(),\n report,\n }\n // The runtime starts from the resumed Model, so its first render is the\n // served markup and Foldkit adopts every node. The Messages the page\n // answered before the live page listened wait in `answered`, and the first\n // Message the runtime processes, whatever it is, runs them through `update`\n // ahead of itself: they reach the Model before anything the live page\n // answers, an event dispatched in the task that boots it included.\n const answered: Array<unknown> = []\n // Each answered Message was decoded through the plan's Message Schema.\n const apply: ResumableConfig<Model>['update'] = config.update\n const update = (current: Model, message: unknown) => {\n const handingOver = message === HANDOVER\n if (answered.length === 0) return handingOver ? { model: current } : apply(current, message)\n const returned: Array<unknown> = []\n for (const next of [...answered.splice(0), ...(handingOver ? [] : [message])]) {\n const step = apply(current, next) as {\n readonly model: Model\n readonly commands?: ReadonlyArray<unknown> | undefined\n }\n current = step.model\n returned.push(...(step.commands ?? []))\n }\n return { model: current, commands: returned }\n }\n // The URL goes into the Model the runtime starts from, not into `answered`:\n // Subscriptions start from that Model before any Message lands, and a URL\n // mirror among them would write the served address back over the real one.\n // The first render then differs from the served page where the URL does, and\n // Foldkit rebuilds that part, as a navigation would redraw it. Applied at\n // boot, once any lazy bundle's `update` has loaded. The boot Commands are\n // planned from the Model the runtime actually starts with, so one derived\n // from the route or query sees the address the page arrived at.\n const startOf = () =>\n Option.match(arrived, {\n onNone: () => ({ model, commands: bootCommands(model) }),\n onSome: message => {\n const step = apply(model, message) as {\n readonly model: Model\n readonly commands?: ReadonlyArray<unknown> | undefined\n }\n return {\n model: step.model,\n commands: [...bootCommands(step.model), ...(step.commands ?? [])],\n }\n },\n })\n const boot = (entries: Readonly<Record<string, unknown>> = {}) => {\n unmark(root)\n return adopt(\n makeApplication({\n ...withContext(startingFrom({ ...config, update }, startOf()), resuming),\n container: root,\n subscriptions: { ...config.subscriptions, ...entries },\n } as never),\n { buildId: options.buildId },\n )\n }\n const pending = (config.lazy ?? []).filter(bundle => !bundle.isLoaded())\n // A loader ran this chunk when the plan's `start` said to.\n const start = Option.isSome(arrived) || Option.isSome(loader) ? 'now' : plan.start\n const eager = start === 'now' && pending.length === 0\n // With a loader, the page reads its bindings first: the loader may hold\n // events for them.\n if (eager && Option.isNone(loader) && root.querySelector(`[${KEEP_ATTRIBUTE}]`) === null) {\n boot()\n return\n }\n const decoded = bindingsAndEvents(plan, document, root, model)\n if (Result.isFailure(decoded)) {\n report(pageContained(decoded.failure.reason, decoded.failure.message))\n release()\n contain()\n return\n }\n const kept = keptFields(root, decoded.success.bindings)\n if (Result.isFailure(kept)) {\n report(pageContained('Invalid', kept.failure))\n release()\n contain()\n return\n }\n // What was typed before this script ran, first in the queue: everything the\n // page answers from here on happened after it.\n answered.push(...typedMessages(kept.success))\n const held = Option.match(loader, { onNone: () => [], onSome: it => it.take() })\n if (eager && answered.length === 0 && held.length === 0) {\n boot()\n return\n }\n // Typing is an interaction, whenever it happened: a page that waits for\n // one starts now, so what was typed is answered as soon as the script runs.\n const typed = answered.length > 0 ? 'now' : start\n deferBoot(root, decoded.success, typed, { boot, answered }, pending, report, kept.success, held)\n }\n const prepare = options.prepare\n let startingModel: Model\n try {\n startingModel = plan.restore === undefined ? resumed.success : plan.restore(resumed.success)\n } catch (error) {\n report(pageContained('Invalid', error instanceof Error ? error.message : String(error)))\n release()\n contain()\n return\n }\n if (prepare === undefined) adoptFrom(startingModel)\n else void Effect.runPromise(prepare(startingModel)).then(adoptFrom)\n}\n\n/**\n * Takes out of the served page what the server wrote for this script to read\n * and no view draws: the envelope, each binding's and kept field's marker,\n * each placement's slot, and each form's fallback (its `method` and hidden\n * fields). Left in, each is in what Foldkit records of the served page and\n * gone after its first patch, so Foldkit reconciles every such element, and\n * a development build reports that the server's markup and the view\n * disagree. Run as the page boots, so a form submitted before then still\n * posts.\n */\nconst unmark = (root: Element): void => {\n root.removeAttribute(RESUME_ATTRIBUTE)\n for (const element of [root, ...root.querySelectorAll('*')]) {\n for (const name of element.getAttributeNames()) {\n if (name.startsWith(BINDING_ATTRIBUTE) || name === KEEP_ATTRIBUTE || name === SLOT_ATTRIBUTE)\n element.removeAttribute(name)\n }\n }\n for (const field of root.querySelectorAll(`input[type=\"hidden\"][name=\"${FALLBACK_FIELD}\"]`)) {\n const form = field.parentElement\n form?.removeAttribute('method')\n form?.querySelector(`:scope > input[type=\"hidden\"][name=\"${FALLBACK_DEPTH_FIELD}\"]`)?.remove()\n field.remove()\n }\n}\n\n/**\n * Removes head markup `SSR.headed` should have moved out of the root (a plan's\n * `meta`), saying whether there was any: the view does not draw it, and the\n * plan's meta entry writes the head once the page runs.\n */\nconst dropUnmovedHead = (root: Element): boolean => {\n const nodes = Array.from(root.childNodes)\n const marks = (value: string) => (node: ChildNode) =>\n node.nodeType === Node.COMMENT_NODE && node.nodeValue === value\n const open = nodes.findIndex(marks(HEAD_MARKER))\n if (open === -1) return false\n const close = nodes.findIndex((node, at) => at > open && marks(HEAD_END_MARKER)(node))\n for (const node of nodes.slice(open, close === -1 ? undefined : close + 1)) node.remove()\n return true\n}\n\n/**\n * Moves what a render's `styles` put in the root into the head, before\n * anything adopts the page: the view does not draw it, so hydration would\n * remove it, and a page that never renders again would lose the rules its\n * classes need. Whatever adopts the page next finds them in the head.\n */\nconst keepStyles = (root: Element): void => {\n const marker = Array.from(root.childNodes).find(\n node => node.nodeType === Node.COMMENT_NODE && node.nodeValue === STYLES_MARKER,\n )\n if (marker === undefined) return\n for (let next = marker.nextSibling; next !== null; next = marker.nextSibling) {\n if (next instanceof Element) document.head.append(next)\n else next.remove()\n }\n marker.remove()\n}\n\n/** The longest a served page stays in view while a fresh application waits for `until`. */\nexport { UNTIL_LIMIT_MS }\n\n/**\n * Runs the application afresh out of view, beside the served page, and puts\n * it in the page's place once a Model it drew satisfies `until`, or after\n * `UNTIL_LIMIT_MS`. It draws in a hidden element, not a detached one, so its\n * Mounts start in the document as they would in place.\n */\nconst renderBeside = <Model, Message>(\n config: ResumableConfig<Model, Message>,\n served: HTMLElement,\n until: (model: Model) => boolean,\n): void => {\n const holder = document.createElement('div')\n holder.hidden = true\n const container = document.createElement('div')\n // The runtime refuses a container without an id; the served page gives its own up.\n container.id = served.id === '' ? 'foldkit-ssr-app' : served.id\n served.removeAttribute('id')\n // Nor does it boot beside a page stamped as a server render, which this one,\n // never adopted, no longer is.\n served.removeAttribute(FOLDKIT_APP_ATTRIBUTE)\n holder.append(container)\n served.after(holder)\n let shown = false\n const show = () => {\n if (shown) return\n shown = true\n clearTimeout(limit)\n holder.replaceWith(...holder.childNodes)\n served.remove()\n }\n const limit = setTimeout(show, UNTIL_LIMIT_MS)\n const view: ResumableConfig<Model, Message>['view'] = (model, h) => {\n const drawn = config.view(model, h)\n // Shown once the drawing this view returns is patched in, which the\n // runtime does in the same task.\n if (!shown && until(model)) queueMicrotask(show)\n return drawn\n }\n run(makeApplication({ ...config, view, container } as never))\n}\n\n/**\n * The Message the handover entry sends so the runtime takes the answered\n * Messages when nothing else has asked it to. The wrapped `update` consumes\n * it; the application never sees it.\n */\nconst HANDOVER: unknown = Object.freeze({ _tag: 'foldkit-ssr/Handover' })\n\n/**\n * Lets the page answer from its bindings until something asks for the\n * runtime, then boots it and hands over to the live page.\n *\n * Every Message the page answers goes to `answered`, which the runtime takes\n * before its first Message. An event only the live page can answer is kept\n * and sent again to where it first went once the live page listens. The page\n * stops listening as soon as the runtime's first render has committed: when\n * `hydrate` returns, which Foldkit does today, or else when a handover\n * Subscription entry starts, after `Render.afterCommit`. When lazy bundles\n * must load first, the boot waits for them and the page keeps answering.\n * Each kept field the person changed is put back, value and selection, as\n * the first render commits, since that render re-asserts the served value.\n */\nconst deferBoot = (\n root: HTMLElement,\n decoded: {\n readonly bindings: ReadonlyArray<DecodedBinding>\n readonly events: ReadonlyArray<string> | undefined\n },\n start: Start,\n runtime: {\n readonly boot: (entries: Readonly<Record<string, unknown>>) => void\n readonly answered: Array<unknown>\n },\n pending: ReadonlyArray<Loadable>,\n report: (diagnostic: SsrDiagnostic) => void,\n kept: ReadonlyArray<KeptField>,\n loaded: ReadonlyArray<HeldEvent>,\n): void => {\n // Events only the live page can answer, met before it listened.\n const unanswered: Array<{ readonly event: Event; readonly element: Element }> = []\n // `waiting` for an interaction or idle, `loading` bodies, `starting` the\n // runtime until its first render commits, then `live`.\n let phase: 'waiting' | 'loading' | 'starting' | 'live' = 'waiting'\n // The kept fields as the person left them, which the first render resets.\n let held: ReadonlyArray<Held> = []\n const { stop, answer } = listening(root, {\n bindings: decoded.bindings,\n ...(decoded.events === undefined ? {} : { events: decoded.events }),\n onAnswer: ({ event, messages, unnamed }) => {\n // An answer the markers could not complete is left to the live page.\n if (unnamed !== undefined) {\n startNow()\n // Once the live page listens, this event reaches it in the rest of\n // its own dispatch; until then it is kept for the handover.\n if (phase !== 'live' && event.target instanceof Element) {\n unanswered.push({ event, element: event.target })\n }\n return\n }\n // Nothing answered it: it goes on to the page, a plain link to the\n // router, as it would have.\n if (messages.length === 0) {\n startNow()\n return\n }\n // Taken by the runtime before anything else. The live page must not\n // answer this one as well.\n runtime.answered.push(...messages)\n event.stopPropagation()\n startNow()\n },\n })\n const handOver = () => {\n if (phase === 'live') return\n phase = 'live'\n // Before the queue runs, so its Messages find the fields holding their values.\n restore(held)\n stop()\n for (const { event, element } of unanswered.splice(0)) {\n const Ctor = event.constructor as new (type: string, init: Event) => Event\n element.dispatchEvent(new Ctor(event.type, event))\n }\n }\n const commit = () => {\n phase = 'starting'\n held = hold(kept)\n runtime.boot({\n 'foldkit-ssr.handover': {\n dependenciesSchema: Schema.Null,\n modelToDependencies: () => null,\n // Foldkit strips the root's stamp just before its first patch, so a\n // stamped root still has a render to wait for.\n dependenciesToStream: () =>\n Stream.fromEffect(\n Effect.as(\n Effect.andThen(\n root.hasAttribute(FOLDKIT_APP_ATTRIBUTE) ? Render.afterCommit : Effect.void,\n Effect.sync(handOver),\n ),\n HANDOVER,\n ),\n ),\n },\n })\n if (!root.hasAttribute(FOLDKIT_APP_ATTRIBUTE)) handOver()\n }\n const startNow = () => {\n if (phase !== 'waiting') return\n phase = 'loading'\n if (pending.length === 0) {\n commit()\n return\n }\n void Promise.all(pending.map(bundle => bundle.load())).then(commit, (error: unknown) => {\n report(bundleUnloaded(error))\n commit()\n })\n }\n // What the loader held, answered as if the page had listened then.\n for (const { event, path } of loaded) answer(event, path)\n if (start === 'now') startNow()\n else if (start === 'idle') {\n if (typeof window.requestIdleCallback === 'function') window.requestIdleCallback(startNow)\n else setTimeout(startNow, 0)\n }\n}\n\n/** The resumable track: bindings the server's markup names, so a page can answer before it boots. */\nexport const Resume = { builder, view, bindings, listen }\n\n/** The browser's part of `SSR`: the same functions, without the server's. */\nexport const SSR = { plan, resume, hydrate, static: staticRegion, unbound, serving }\n\nexport {\n META_ATTRIBUTE,\n RESUME_ATTRIBUTE,\n STATIC_ATTRIBUTE,\n ResumeRefused,\n metaMarkup,\n type Loadable,\n type Meta,\n type PlanSurface,\n type ResumableConfig,\n type ResumePart,\n type ResumePlan,\n type Start,\n} from './shared.js'\nexport {\n BINDING_ATTRIBUTE,\n FALLBACK_FIELD,\n KEEP_ATTRIBUTE,\n SLOT_ATTRIBUTE,\n type ResumableBuilder,\n} from './resumable.js'\nexport type { DecodedBinding } from './listen.js'\nexport type { UnnamedHandler } from './context.js'\n/** The diagnostics channel `hydrate` reports into, re-exported so a page needs no other import. */\nexport { Diagnostics, type Diagnostic, type ReportDiagnostic } from 'foldkit-surface'\nexport type {\n BundleUnloaded,\n CachedPageDiffers,\n HandlerUnnamed,\n HeadNotMoved,\n PageContained,\n PageFailed,\n SsrDiagnostic,\n StaticRegionMissing,\n} from './diagnostics.js'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6DA,MAAM,eAAe,SACnB,IAAI,IACF,MAAM,KAAK,KAAK,iBAAiB,IAAI,iBAAiB,EAAE,IAAG,YAAW,CACpE,QAAQ,aAAA,0BAA6B,KAAK,IAC1C,QAAQ,SACV,CAAC,CACH;;;;;;AAOF,MAAM,kBAAkB;;;;;;;;;;;;;;;AAgBxB,MAAMA,aACJ,QACA,MACA,YAmDS;CACT,MAAM,UAAU,eAAoC;EAClD,OAAO,QAAQ,YAAY,QAAQ,WAAW,CAAC,CAACC,cAAY,OAAO,UAAU,CAAC,CAAC;CACjF;CACA,MAAM,SAA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,KAAK,aAAA,kBAAkC,GAAG,SAAS;CAC1D;CACA,MAAM,iBAAiB;EACrB,IAAI,UAAU,WAAW;EACzB,QAAQ;EACR,IAAI,QAAQ,WAAW,GAAG;GACxB,OAAO;GACP;EACF;EACA,QAAa,IAAI,QAAQ,KAAI,WAAU,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,UAAmB;GACtF,OAAO,eAAe,KAAK,CAAC;GAC5B,OAAO;EACT,CAAC;CACH;CAEA,KAAK,MAAM,EAAE,OAAO,UAAU,QAAQ,OAAO,OAAO,IAAI;CACxD,IAAI,UAAU,OAAO,SAAS;MACzB,IAAI,UAAU,QAAQ;EACzB,IAAI,OAAO,OAAO,wBAAwB,YAAY,OAAO,oBAAoB,QAAQ;OACpF,WAAW,UAAU,CAAC;CAC7B;AACF;;AAGA,MAAa,SAAS;CAAE;CAAS;CAAM;CAAU;AAAO;;AAGxD,MAAa,MAAM;CAAE;CAAM;CAAQ,SAAA;CAAS,QAAQ;CAAc;CAAS;AAAQ"}
|
package/dist/context.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { B as
|
|
1
|
+
import { B as RenderContext, H as current, R as Binding, U as withContext, V as UnnamedHandler, W as within, z as Region } from "./shared-mQ8CXr-r.js";
|
|
2
2
|
export { Binding, Region, RenderContext, UnnamedHandler, current, withContext, within };
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["/**\n * The render context: what the page's server-owned parts do, set around one\n * synchronous call of the view. `SSR.static` reads it to decide whether a\n * region renders, replays, or adopts the server's markup, and the resumable\n * builder reads it to decide whether to mark the bindings it builds. With no\n * context, as in a client-only render, both behave as ordinary view code.\n *\n * - `collect`: the server's render. Each region runs once and is kept, and\n * each binding is recorded in render order.\n * - `replay`: the server's second render, from the browser's Model. Each\n * region is the one already rendered, so it never reads the browser's Model;\n * bindings are recorded again, to be compared with the first render's.\n * - `resume`: the browser. Each region is the markup the server left in the\n * page, and its render never runs; no binding is marked.\n */\nimport type { Html } from 'foldkit/html'\nimport type { StaticRegionMissing } from './diagnostics.js'\n\nexport type Region = ReadonlyArray<Html | string>\n\n/** An element whose handler for `event` is a function, which the page cannot describe. */\nexport interface UnnamedHandler {\n readonly element: string\n readonly event: string\n}\n\n/**\n * An element's binding as the server's render records it, before encoding:\n * the Foldkit attribute and its DOM event, the element for diagnostics, and\n * the Message it causes. For a Message with a hole, `message` is the Message\n * with the hole filled by a placeholder, and `hole` names the fields the event\n * fills.\n */\nexport interface Binding {\n /** Foldkit's attribute, whose tag says what the handler does beside dispatching. */\n readonly attribute: string\n readonly event: string\n readonly element: string\n readonly message: unknown\n readonly hole?: ReadonlyArray<string> | undefined\n /** How many placement wrappers enclose the hole's fields: `message` is entered that many times. */\n readonly depth?: number | undefined\n readonly options?: unknown\n}\n\nexport type RenderContext =\n | {\n readonly mode: 'collect'\n readonly regions: Map<string, Region>\n readonly duplicates: Set<string>\n readonly bindings: Array<Binding>\n /** Encodes a form's Message for its no-script fallback; absent when the plan has none. */\n readonly fallback: ((message: unknown) => string | undefined) | undefined\n /** Lifts a Message of the view in progress to the application's, through each enclosing placement. */\n wrap: (message: unknown) => unknown\n /** How many placements enclose the view in progress. */\n depth: number\n /** The static region whose render is in progress, if any. */\n region: string | undefined\n /** Handlers met inside a static region, which the server alone renders. */\n readonly inStatic: Array<{\n readonly region: string\n readonly element: string\n readonly event: string\n }>\n /** Each element and event marked `*`: a handler the page cannot name. */\n readonly unnamed: Array<UnnamedHandler>\n /** Why each `KeepTyped` field met cannot be replayed, one line each. */\n readonly unkeepable: Array<string>\n }\n | {\n readonly mode: 'replay'\n readonly regions: ReadonlyMap<string, Region>\n readonly bindings: Array<Binding>\n readonly fallback: ((message: unknown) => string | undefined) | undefined\n wrap: (message: unknown) => unknown\n depth: number\n }\n | {\n readonly mode: 'resume'\n readonly snapshots: ReadonlyMap<string, string>\n /** The regions already reported missing, so each is reported once. */\n readonly reported: Set<string>\n readonly report: (diagnostic: StaticRegionMissing) => void\n }\n\nlet context: RenderContext | undefined\n\n/** The context of the view call in progress, if any. */\nexport const current = (): RenderContext | undefined => context\n\n/**\n * Set on `globalThis` while the server renders a page, under a registered\n * symbol so a view's packages find it from another bundle: a memoized\n * drawing (`foldkit-mixins`' SlotView) is drawn afresh then, since one kept\n * from another pass or request carries that render's markers and none of\n * this one's bindings.\n */\nconst SERVER_RENDER = Symbol.for('foldkit-plus.serverRender')\n\nexport const within = <A>(next: RenderContext, run: () => A): A => {\n const previous = context\n const global = globalThis as Record<symbol, unknown>\n const rendering = global[SERVER_RENDER]\n context = next\n global[SERVER_RENDER] = next.mode === 'collect' || next.mode === 'replay'\n try {\n return run()\n } finally {\n context = previous\n global[SERVER_RENDER] = rendering\n }\n}\n\n/** The config whose view runs inside `next`. */\nexport const withContext = <Config extends { readonly view: (model: any, h: any) => unknown }>(\n config: Config,\n next: RenderContext,\n): Config => ({\n ...config,\n view: (model: unknown, h: unknown) => within(next, () => config.view(model, h)),\n})\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["/**\n * The render context: what the page's server-owned parts do, set around one\n * synchronous call of the view. `SSR.static` reads it to decide whether a\n * region renders, replays, or adopts the server's markup, and the resumable\n * builder reads it to decide whether to mark the bindings it builds. With no\n * context, as in a client-only render, both behave as ordinary view code.\n *\n * - `collect`: the server's render. Each region runs once and is kept, and\n * each binding is recorded in render order.\n * - `replay`: the server's second render, from the browser's Model. Each\n * region is the one already rendered, so it never reads the browser's Model;\n * bindings are recorded again, to be compared with the first render's.\n * - `resume`: the browser. Each region is the markup the server left in the\n * page, and its render never runs; no binding is marked.\n */\nimport type { Html } from 'foldkit/html'\nimport type { StaticRegionMissing } from './diagnostics.js'\n\nexport type Region = ReadonlyArray<Html | string>\n\n/** An element whose handler for `event` is a function, which the page cannot describe. */\nexport interface UnnamedHandler {\n readonly element: string\n readonly event: string\n}\n\n/**\n * An element's binding as the server's render records it, before encoding:\n * the Foldkit attribute and its DOM event, the element for diagnostics, and\n * the Message it causes. For a Message with a hole, `message` is the Message\n * with the hole filled by a placeholder, and `hole` names the fields the event\n * fills.\n */\nexport interface Binding {\n /** Foldkit's attribute, whose tag says what the handler does beside dispatching. */\n readonly attribute: string\n readonly event: string\n readonly element: string\n readonly message: unknown\n readonly hole?: ReadonlyArray<string> | undefined\n /** How many placement wrappers enclose the hole's fields: `message` is entered that many times. */\n readonly depth?: number | undefined\n readonly options?: unknown\n}\n\nexport type RenderContext =\n | {\n readonly mode: 'collect'\n readonly regions: Map<string, Region>\n readonly duplicates: Set<string>\n readonly bindings: Array<Binding>\n /** Encodes a form's Message for its no-script fallback; absent when the plan has none. */\n readonly fallback: ((message: unknown) => string | undefined) | undefined\n /** Lifts a Message of the view in progress to the application's, through each enclosing placement. */\n wrap: (message: unknown) => unknown\n /** How many placements enclose the view in progress. */\n depth: number\n /** The static region whose render is in progress, if any. */\n region: string | undefined\n /** Handlers met inside a static region, which the server alone renders. */\n readonly inStatic: Array<{\n readonly region: string\n readonly element: string\n readonly event: string\n }>\n /** Each element and event marked `*`: a handler the page cannot name. */\n readonly unnamed: Array<UnnamedHandler>\n /** Why each `KeepTyped` field met cannot be replayed, one line each. */\n readonly unkeepable: Array<string>\n /** Each field with a binding that names its typing and no `KeepTyped`. */\n readonly unkept: Array<string>\n }\n | {\n readonly mode: 'replay'\n readonly regions: ReadonlyMap<string, Region>\n readonly bindings: Array<Binding>\n readonly fallback: ((message: unknown) => string | undefined) | undefined\n wrap: (message: unknown) => unknown\n depth: number\n }\n | {\n readonly mode: 'resume'\n readonly snapshots: ReadonlyMap<string, string>\n /** The regions already reported missing, so each is reported once. */\n readonly reported: Set<string>\n readonly report: (diagnostic: StaticRegionMissing) => void\n }\n\nlet context: RenderContext | undefined\n\n/** The context of the view call in progress, if any. */\nexport const current = (): RenderContext | undefined => context\n\n/**\n * Set on `globalThis` while the server renders a page, under a registered\n * symbol so a view's packages find it from another bundle: a memoized\n * drawing (`foldkit-mixins`' SlotView) is drawn afresh then, since one kept\n * from another pass or request carries that render's markers and none of\n * this one's bindings.\n */\nconst SERVER_RENDER = Symbol.for('foldkit-plus.serverRender')\n\nexport const within = <A>(next: RenderContext, run: () => A): A => {\n const previous = context\n const global = globalThis as Record<symbol, unknown>\n const rendering = global[SERVER_RENDER]\n context = next\n global[SERVER_RENDER] = next.mode === 'collect' || next.mode === 'replay'\n try {\n return run()\n } finally {\n context = previous\n global[SERVER_RENDER] = rendering\n }\n}\n\n/** The config whose view runs inside `next`. */\nexport const withContext = <Config extends { readonly view: (model: any, h: any) => unknown }>(\n config: Config,\n next: RenderContext,\n): Config => ({\n ...config,\n view: (model: unknown, h: unknown) => within(next, () => config.view(model, h)),\n})\n"],"mappings":";AAwFA,IAAI;;AAGJ,MAAa,gBAA2C;;;;;;;;AASxD,MAAM,gBAAgB,OAAO,IAAI,2BAA2B;AAE5D,MAAa,UAAa,MAAqB,QAAoB;CACjE,MAAM,WAAW;CACjB,MAAM,SAAS;CACf,MAAM,YAAY,OAAO;CACzB,UAAU;CACV,OAAO,iBAAiB,KAAK,SAAS,aAAa,KAAK,SAAS;CACjE,IAAI;EACF,OAAO,IAAI;CACb,UAAU;EACR,UAAU;EACV,OAAO,iBAAiB;CAC1B;AACF;;AAGA,MAAa,eACX,QACA,UACY;CACZ,GAAG;CACH,OAAO,OAAgB,MAAe,OAAO,YAAY,OAAO,KAAK,OAAO,CAAC,CAAC;AAChF"}
|
package/dist/diagnostics.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
export { BundleUnloaded, HandlerUnnamed, PageContained, PageFailed, SsrDiagnostic, StaticRegionMissing, bundleUnloaded, handlerUnnamed, noBuildId, otherBuild, pageContained, pageFailed, reportingTo, staticRegionMissing };
|
|
1
|
+
import { $ as bundleUnloaded, G as BundleUnloaded, J as HeadNotMoved, K as CachedPageDiffers, Q as StaticRegionMissing, X as PageFailed, Y as PageContained, Z as SsrDiagnostic, at as pageContained, ct as staticRegionMissing, et as cachedPageDiffers, it as otherBuild, nt as headNotMoved, ot as pageFailed, q as HandlerUnnamed, rt as noBuildId, st as reportingTo, tt as handlerUnnamed } from "./shared-mQ8CXr-r.js";
|
|
2
|
+
export { BundleUnloaded, CachedPageDiffers, HandlerUnnamed, HeadNotMoved, PageContained, PageFailed, SsrDiagnostic, StaticRegionMissing, bundleUnloaded, cachedPageDiffers, handlerUnnamed, headNotMoved, noBuildId, otherBuild, pageContained, pageFailed, reportingTo, staticRegionMissing };
|
package/dist/diagnostics.js
CHANGED
|
@@ -8,6 +8,12 @@ import { Diagnostics } from "foldkit-surface";
|
|
|
8
8
|
* Each is reported through `Diagnostics.report`, by default to the log.
|
|
9
9
|
*/
|
|
10
10
|
const source = "foldkit-ssr";
|
|
11
|
+
const headNotMoved = {
|
|
12
|
+
_tag: "HeadNotMoved",
|
|
13
|
+
source,
|
|
14
|
+
level: "error",
|
|
15
|
+
message: "the served page's meta was in its body, not its head, so link previews and crawlers did not see it: wrap the host's document renderer in SSR.headed (`SSR.headed(renderDocument)`)."
|
|
16
|
+
};
|
|
11
17
|
const pageContained = (reason, detail) => ({
|
|
12
18
|
_tag: "PageContained",
|
|
13
19
|
source,
|
|
@@ -54,6 +60,13 @@ const handlerUnnamed = (plan, element, event) => ({
|
|
|
54
60
|
});
|
|
55
61
|
/** `effect` reporting to `report` when one is given, else to the reporter in its context. */
|
|
56
62
|
const reportingTo = (report) => (effect) => report === void 0 ? effect : Effect.provideService(effect, Diagnostics.Reporter, report);
|
|
57
|
-
|
|
63
|
+
const cachedPageDiffers = (url) => ({
|
|
64
|
+
_tag: "CachedPageDiffers",
|
|
65
|
+
source,
|
|
66
|
+
level: "error",
|
|
67
|
+
message: `the page kept for ${url} was drawn otherwise for a request it served, so something the render read is not the URL alone; find what in flags, prepare, headers, status or the view differs between requests`,
|
|
68
|
+
url
|
|
69
|
+
});
|
|
70
|
+
export { bundleUnloaded, cachedPageDiffers, handlerUnnamed, headNotMoved, noBuildId, otherBuild, pageContained, pageFailed, reportingTo, staticRegionMissing };
|
|
58
71
|
|
|
59
72
|
//# sourceMappingURL=diagnostics.js.map
|
package/dist/diagnostics.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.js","names":[],"sources":["../src/diagnostics.ts"],"sourcesContent":["/**\n * What SSR meets and keeps going past: a page the browser contains rather\n * than resumes, a static region or lazy bundle it draws without, a request\n * answered 500, and a handler that keeps a page from answering before boot.\n * Each is reported through `Diagnostics.report`, by default to the log.\n */\nimport { Cause, Effect, Option } from 'effect'\nimport { Diagnostics, type Diagnostic, type ReportDiagnostic } from 'foldkit-surface'\nimport type { ResumeRefused } from './shared.js'\n\nconst source = 'foldkit-ssr'\n\n/** A served page the browser contained instead of resuming: it stays in view, inert, and no runtime starts. */\nexport interface PageContained extends Diagnostic {\n readonly _tag: 'PageContained'\n /**\n * `NoBuildId` when `SSR.hydrate` was given none, `OtherBuild` when the page\n * names another deployment; otherwise why the envelope was refused.\n */\n readonly reason: 'NoBuildId' | 'OtherBuild' | ResumeRefused['reason']\n}\n\n/** A static region the browser asked for that the server's page did not hold, rendered in the browser. */\nexport interface StaticRegionMissing extends Diagnostic {\n readonly _tag: 'StaticRegionMissing'\n readonly region: string\n}\n\n/** A lazy bundle whose bodies did not load; the runtime boots without them. */\nexport interface BundleUnloaded extends Diagnostic {\n readonly _tag: 'BundleUnloaded'\n readonly error: unknown\n}\n\n/** A request answered 500: its `headers` threw, or its page could not be rendered. */\nexport interface PageFailed extends Diagnostic {\n readonly _tag: 'PageFailed'\n readonly url: string\n readonly cause: Cause.Cause<unknown>\n}\n\n/** A handler the page cannot name, so its event waits for the live runtime. Reported once per process. */\nexport interface HandlerUnnamed extends Diagnostic {\n readonly _tag: 'HandlerUnnamed'\n readonly plan: string\n readonly element: string\n readonly event: string\n}\n\n/** Every diagnostic SSR reports. */\nexport type SsrDiagnostic =\n | PageContained\n | StaticRegionMissing\n | BundleUnloaded\n | PageFailed\n | HandlerUnnamed\n\nexport const pageContained = (reason: PageContained['reason'], detail: string): PageContained => ({\n _tag: 'PageContained',\n source,\n level: 'error',\n message: `the page cannot resume, so it is contained: ${detail}`,\n reason,\n})\n\nexport const noBuildId: PageContained = pageContained(\n 'NoBuildId',\n \"SSR.hydrate was given no build id, so it cannot tell this page from another deployment's. Pass the id the server stamped: with @foldkit/vite-plugin, set FOLDKIT_BUILD_ID (or `foldkit({ buildId })`) so that `import.meta.env.FOLDKIT_BUILD_ID` is defined in the client too.\",\n)\n\n/** The page's stamped build id, if it has one, is not the client's `client`. */\nexport const otherBuild = (served: Option.Option<string>, client: string): PageContained =>\n pageContained(\n 'OtherBuild',\n `it was served by ${Option.match(served, {\n onNone: () => 'no known deployment',\n onSome: id => `deployment \"${id}\"`,\n })}, but this client belongs to deployment \"${client}\". If both came from one build, they were given different ids: with @foldkit/vite-plugin, set FOLDKIT_BUILD_ID in the build's environment, or once in vite.config.ts before \\`foldkit()\\` reads it (\\`process.env.FOLDKIT_BUILD_ID ??= randomUUID()\\`). Otherwise serve the page from the running deployment.`,\n )\n\nexport const staticRegionMissing = (region: string): StaticRegionMissing => ({\n _tag: 'StaticRegionMissing',\n source,\n level: 'error',\n message: `the static region \"${region}\" is not in the server's page, so it is rendered in the browser`,\n region,\n})\n\nexport const bundleUnloaded = (error: unknown): BundleUnloaded => ({\n _tag: 'BundleUnloaded',\n source,\n level: 'error',\n message: `a bundle's bodies did not load, and the page boots without them: ${String(error)}`,\n error,\n})\n\nexport const pageFailed = (url: string, cause: Cause.Cause<unknown>): PageFailed => ({\n _tag: 'PageFailed',\n source,\n level: 'error',\n message: `${url} was answered 500: ${Cause.pretty(cause)}`,\n url,\n cause,\n})\n\nexport const handlerUnnamed = (plan: string, element: string, event: string): HandlerUnnamed => ({\n _tag: 'HandlerUnnamed',\n source,\n level: 'warning',\n message: `plan \"${plan}\": ${element} handles ${event} with a function, which the page cannot name, so that event waits for the live runtime. Give the handler a Message, or, for OnInput, OnChange, OnKeyDown or OnKeyUp, the Message's constructor with the field the event fills left out.`,\n plan,\n element,\n event,\n})\n\n/** `effect` reporting to `report` when one is given, else to the reporter in its context. */\nexport const reportingTo =\n (report: ReportDiagnostic | undefined) =>\n <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>\n report === undefined ? effect : Effect.provideService(effect, Diagnostics.Reporter, report)\n"],"mappings":";;;;;;;;;AAUA,MAAM,SAAS;
|
|
1
|
+
{"version":3,"file":"diagnostics.js","names":[],"sources":["../src/diagnostics.ts"],"sourcesContent":["/**\n * What SSR meets and keeps going past: a page the browser contains rather\n * than resumes, a static region or lazy bundle it draws without, a request\n * answered 500, and a handler that keeps a page from answering before boot.\n * Each is reported through `Diagnostics.report`, by default to the log.\n */\nimport { Cause, Effect, Option } from 'effect'\nimport { Diagnostics, type Diagnostic, type ReportDiagnostic } from 'foldkit-surface'\nimport type { ResumeRefused } from './shared.js'\n\nconst source = 'foldkit-ssr'\n\n/** A served page the browser contained instead of resuming: it stays in view, inert, and no runtime starts. */\nexport interface PageContained extends Diagnostic {\n readonly _tag: 'PageContained'\n /**\n * `NoBuildId` when `SSR.hydrate` was given none, `OtherBuild` when the page\n * names another deployment; otherwise why the envelope was refused.\n */\n readonly reason: 'NoBuildId' | 'OtherBuild' | ResumeRefused['reason']\n}\n\n/** A static region the browser asked for that the server's page did not hold, rendered in the browser. */\nexport interface StaticRegionMissing extends Diagnostic {\n readonly _tag: 'StaticRegionMissing'\n readonly region: string\n}\n\n/** A lazy bundle whose bodies did not load; the runtime boots without them. */\nexport interface BundleUnloaded extends Diagnostic {\n readonly _tag: 'BundleUnloaded'\n readonly error: unknown\n}\n\n/** A request answered 500: its `headers` threw, or its page could not be rendered. */\nexport interface PageFailed extends Diagnostic {\n readonly _tag: 'PageFailed'\n readonly url: string\n readonly cause: Cause.Cause<unknown>\n}\n\n/** A handler the page cannot name, so its event waits for the live runtime. Reported once per process. */\nexport interface HandlerUnnamed extends Diagnostic {\n readonly _tag: 'HandlerUnnamed'\n readonly plan: string\n readonly element: string\n readonly event: string\n}\n\n/**\n * A kept page drawn otherwise for the request it served (`SSR.entry`'s\n * `cache.check`): the render read something of the request, or anything\n * else that differs between requests, that the cache could not see. The\n * request was given the page drawn again.\n */\nexport interface CachedPageDiffers extends Diagnostic {\n readonly _tag: 'CachedPageDiffers'\n readonly url: string\n}\n\n/**\n * A served page whose head markup (a plan's `meta`) was still in its body:\n * the host's document renderer is not wrapped in `SSR.headed`, so link\n * previews and crawlers, which read the served head, never saw it.\n * `SSR.hydrate` removed it; the head gets it once the page runs.\n */\nexport interface HeadNotMoved extends Diagnostic {\n readonly _tag: 'HeadNotMoved'\n}\n\n/** Every diagnostic SSR reports. */\nexport type SsrDiagnostic =\n | PageContained\n | StaticRegionMissing\n | BundleUnloaded\n | PageFailed\n | HandlerUnnamed\n | CachedPageDiffers\n | HeadNotMoved\n\nexport const headNotMoved: HeadNotMoved = {\n _tag: 'HeadNotMoved',\n source,\n level: 'error',\n message:\n \"the served page's meta was in its body, not its head, so link previews and crawlers did not see it: wrap the host's document renderer in SSR.headed (`SSR.headed(renderDocument)`).\",\n}\n\nexport const pageContained = (reason: PageContained['reason'], detail: string): PageContained => ({\n _tag: 'PageContained',\n source,\n level: 'error',\n message: `the page cannot resume, so it is contained: ${detail}`,\n reason,\n})\n\nexport const noBuildId: PageContained = pageContained(\n 'NoBuildId',\n \"SSR.hydrate was given no build id, so it cannot tell this page from another deployment's. Pass the id the server stamped: with @foldkit/vite-plugin, set FOLDKIT_BUILD_ID (or `foldkit({ buildId })`) so that `import.meta.env.FOLDKIT_BUILD_ID` is defined in the client too.\",\n)\n\n/** The page's stamped build id, if it has one, is not the client's `client`. */\nexport const otherBuild = (served: Option.Option<string>, client: string): PageContained =>\n pageContained(\n 'OtherBuild',\n `it was served by ${Option.match(served, {\n onNone: () => 'no known deployment',\n onSome: id => `deployment \"${id}\"`,\n })}, but this client belongs to deployment \"${client}\". If both came from one build, they were given different ids: with @foldkit/vite-plugin, set FOLDKIT_BUILD_ID in the build's environment, or once in vite.config.ts before \\`foldkit()\\` reads it (\\`process.env.FOLDKIT_BUILD_ID ??= randomUUID()\\`). Otherwise serve the page from the running deployment.`,\n )\n\nexport const staticRegionMissing = (region: string): StaticRegionMissing => ({\n _tag: 'StaticRegionMissing',\n source,\n level: 'error',\n message: `the static region \"${region}\" is not in the server's page, so it is rendered in the browser`,\n region,\n})\n\nexport const bundleUnloaded = (error: unknown): BundleUnloaded => ({\n _tag: 'BundleUnloaded',\n source,\n level: 'error',\n message: `a bundle's bodies did not load, and the page boots without them: ${String(error)}`,\n error,\n})\n\nexport const pageFailed = (url: string, cause: Cause.Cause<unknown>): PageFailed => ({\n _tag: 'PageFailed',\n source,\n level: 'error',\n message: `${url} was answered 500: ${Cause.pretty(cause)}`,\n url,\n cause,\n})\n\nexport const handlerUnnamed = (plan: string, element: string, event: string): HandlerUnnamed => ({\n _tag: 'HandlerUnnamed',\n source,\n level: 'warning',\n message: `plan \"${plan}\": ${element} handles ${event} with a function, which the page cannot name, so that event waits for the live runtime. Give the handler a Message, or, for OnInput, OnChange, OnKeyDown or OnKeyUp, the Message's constructor with the field the event fills left out.`,\n plan,\n element,\n event,\n})\n\n/** `effect` reporting to `report` when one is given, else to the reporter in its context. */\nexport const reportingTo =\n (report: ReportDiagnostic | undefined) =>\n <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>\n report === undefined ? effect : Effect.provideService(effect, Diagnostics.Reporter, report)\n\nexport const cachedPageDiffers = (url: string): CachedPageDiffers => ({\n _tag: 'CachedPageDiffers',\n source,\n level: 'error',\n message: `the page kept for ${url} was drawn otherwise for a request it served, so something the render read is not the URL alone; find what in flags, prepare, headers, status or the view differs between requests`,\n url,\n})\n"],"mappings":";;;;;;;;;AAUA,MAAM,SAAS;AAsEf,MAAa,eAA6B;CACxC,MAAM;CACN;CACA,OAAO;CACP,SACE;AACJ;AAEA,MAAa,iBAAiB,QAAiC,YAAmC;CAChG,MAAM;CACN;CACA,OAAO;CACP,SAAS,+CAA+C;CACxD;AACF;AAEA,MAAa,YAA2B,cACtC,aACA,gRACF;;AAGA,MAAa,cAAc,QAA+B,WACxD,cACE,cACA,oBAAoB,OAAO,MAAM,QAAQ;CACvC,cAAc;CACd,SAAQ,OAAM,eAAe,GAAG;AAClC,CAAC,EAAE,2CAA2C,OAAO,8SACvD;AAEF,MAAa,uBAAuB,YAAyC;CAC3E,MAAM;CACN;CACA,OAAO;CACP,SAAS,sBAAsB,OAAO;CACtC;AACF;AAEA,MAAa,kBAAkB,WAAoC;CACjE,MAAM;CACN;CACA,OAAO;CACP,SAAS,oEAAoE,OAAO,KAAK;CACzF;AACF;AAEA,MAAa,cAAc,KAAa,WAA6C;CACnF,MAAM;CACN;CACA,OAAO;CACP,SAAS,GAAG,IAAI,qBAAqB,MAAM,OAAO,KAAK;CACvD;CACA;AACF;AAEA,MAAa,kBAAkB,MAAc,SAAiB,WAAmC;CAC/F,MAAM;CACN;CACA,OAAO;CACP,SAAS,SAAS,KAAK,KAAK,QAAQ,WAAW,MAAM;CACrD;CACA;CACA;AACF;;AAGA,MAAa,eACV,YACS,WACR,WAAW,KAAA,IAAY,SAAS,OAAO,eAAe,QAAQ,YAAY,UAAU,MAAM;AAE9F,MAAa,qBAAqB,SAAoC;CACpE,MAAM;CACN;CACA,OAAO;CACP,SAAS,qBAAqB,IAAI;CAClC;AACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The seam between `foldkit-ssr/loader` and `SSR.hydrate`. The loader runs
|
|
3
|
+
* the runtime's chunk and offers itself here; `SSR.hydrate`, in that chunk,
|
|
4
|
+
* claims it. Both import this module, which imports nothing, so a build puts
|
|
5
|
+
* it in one chunk and the two share its state.
|
|
6
|
+
*/
|
|
7
|
+
/** An event the loader held for the runtime, with the elements it passed as it happened. */
|
|
8
|
+
export interface HeldEvent {
|
|
9
|
+
readonly event: Event;
|
|
10
|
+
readonly path: ReadonlyArray<EventTarget>;
|
|
11
|
+
}
|
|
12
|
+
/** The loader that ran this chunk, as `SSR.hydrate` claims it. */
|
|
13
|
+
export interface Loader {
|
|
14
|
+
/** Stops holding, cancels each held event's deadline, and hands the events over. */
|
|
15
|
+
readonly take: () => ReadonlyArray<HeldEvent>;
|
|
16
|
+
/** Stops holding and releases what it held to the browser now: a page that does not resume. */
|
|
17
|
+
readonly release: () => void;
|
|
18
|
+
}
|
|
19
|
+
/** The loader, as it runs the chunk. */
|
|
20
|
+
export declare const offer: (loader: Loader) => void;
|
|
21
|
+
/** `SSR.hydrate`: the loader that ran this chunk, if one did, claimed once. */
|
|
22
|
+
export declare const claim: () => Loader | undefined;
|
|
23
|
+
//# sourceMappingURL=handoff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handoff.d.ts","names":[],"sources":["../src/handoff.ts"],"mappings":";;;;;;;iBAQiB;WACN,OAAO;WACP,MAAM,cAAc;;;iBAId;;WAEN,YAAY,cAAc;;WAE1B;;;qBAQE,QAAK,QAAY;;qBAKjB,aAAY"}
|
package/dist/handoff.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/handoff.ts
|
|
2
|
+
let offered;
|
|
3
|
+
/** The loader, as it runs the chunk. */
|
|
4
|
+
const offer = (loader) => {
|
|
5
|
+
offered = loader;
|
|
6
|
+
};
|
|
7
|
+
/** `SSR.hydrate`: the loader that ran this chunk, if one did, claimed once. */
|
|
8
|
+
const claim = () => {
|
|
9
|
+
const loader = offered;
|
|
10
|
+
offered = void 0;
|
|
11
|
+
return loader;
|
|
12
|
+
};
|
|
13
|
+
export { claim, offer };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=handoff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handoff.js","names":[],"sources":["../src/handoff.ts"],"sourcesContent":["/**\n * The seam between `foldkit-ssr/loader` and `SSR.hydrate`. The loader runs\n * the runtime's chunk and offers itself here; `SSR.hydrate`, in that chunk,\n * claims it. Both import this module, which imports nothing, so a build puts\n * it in one chunk and the two share its state.\n */\n\n/** An event the loader held for the runtime, with the elements it passed as it happened. */\nexport interface HeldEvent {\n readonly event: Event\n readonly path: ReadonlyArray<EventTarget>\n}\n\n/** The loader that ran this chunk, as `SSR.hydrate` claims it. */\nexport interface Loader {\n /** Stops holding, cancels each held event's deadline, and hands the events over. */\n readonly take: () => ReadonlyArray<HeldEvent>\n /** Stops holding and releases what it held to the browser now: a page that does not resume. */\n readonly release: () => void\n}\n\n// `undefined` for no loader: this module imports nothing, `effect`'s `Option`\n// included; `claim`'s caller converts it.\nlet offered: Loader | undefined\n\n/** The loader, as it runs the chunk. */\nexport const offer = (loader: Loader): void => {\n offered = loader\n}\n\n/** `SSR.hydrate`: the loader that ran this chunk, if one did, claimed once. */\nexport const claim = (): Loader | undefined => {\n const loader = offered\n offered = undefined\n return loader\n}\n"],"mappings":";AAuBA,IAAI;;AAGJ,MAAa,SAAS,WAAyB;CAC7C,UAAU;AACZ;;AAGA,MAAa,cAAkC;CAC7C,MAAM,SAAS;CACf,UAAU,KAAA;CACV,OAAO;AACT"}
|