@solidjs/web 2.0.0-rc.2 → 2.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/server.dev.js +5165 -0
- package/dist/server.js +1876 -374
- package/dist/{server.cjs → server.observe.js} +2070 -577
- package/dist/{dev.cjs → web.dev.js} +955 -567
- package/dist/web.js +646 -350
- package/dist/{dev.js → web.observe.js} +699 -421
- package/frames/dist/assets.js +92 -0
- package/frames/dist/client.dev.js +1296 -1198
- package/frames/dist/client.js +1128 -1191
- package/frames/dist/client.observe.js +2041 -0
- package/frames/dist/regions.js +171 -0
- package/frames/dist/server.dev.js +2545 -0
- package/frames/dist/server.js +1683 -3004
- package/frames/dist/server.observe.js +2544 -0
- package/frames/dist/trace.js +45 -0
- package/frames/dist/wire.js +594 -0
- package/frames/package.json +2 -25
- package/package.json +244 -256
- package/performance-tracks/dist/performance-tracks.dev.js +679 -0
- package/performance-tracks/dist/performance-tracks.js +6 -0
- package/performance-tracks/dist/performance-tracks.observe.js +667 -0
- package/performance-tracks/package.json +7 -0
- package/performance-tracks/types/index.d.ts +69 -0
- package/serialization/decode/package.json +2 -15
- package/serialization/dist/decode.js +121 -25
- package/serialization/dist/serialization.js +282 -88
- package/serialization/package.json +2 -15
- package/serialization/types/index.d.ts +115 -153
- package/serialization/types/serializer-decode.d.ts +173 -114
- package/serialization/types/serializer.d.ts +144 -0
- package/server-functions/dist/client.dev.js +1462 -0
- package/server-functions/dist/client.js +667 -165
- package/server-functions/dist/client.observe.js +1441 -0
- package/server-functions/dist/rich-args.js +102 -1
- package/server-functions/dist/server.dev.js +2802 -299
- package/server-functions/dist/server.js +2724 -314
- package/server-functions/dist/server.observe.js +3680 -0
- package/server-functions/package.json +2 -35
- package/server-functions/rich-args/package.json +2 -15
- package/skills/server-components/SKILL.md +117 -0
- package/storage/package.json +2 -15
- package/types/client.d.ts +342 -288
- package/types/constants.d.ts +22 -0
- package/types/cookies.d.ts +32 -84
- package/types/diagnostics.d.ts +80 -0
- package/types/frames/assets-tier.d.ts +78 -0
- package/types/frames/client.d.ts +40 -1
- package/types/frames/frame-client.d.ts +443 -280
- package/types/frames/frame-container-plugin.d.ts +64 -0
- package/types/frames/frame-morph.d.ts +29 -0
- package/types/frames/frame-sink.d.ts +141 -161
- package/types/frames/frame-transport.d.ts +263 -184
- package/types/frames/regions-tier.d.ts +60 -0
- package/types/frames/serializer-decode.d.ts +241 -0
- package/types/frames/serializer.d.ts +115 -153
- package/types/frames/server.d.ts +2 -2
- package/types/frames/trace-tier.d.ts +2 -0
- package/types/frames/tree-rewrite.d.ts +39 -0
- package/types/frames/wire-tier.d.ts +169 -0
- package/types/head.d.ts +20 -0
- package/types/index.d.ts +98 -81
- package/types/index.server.d.ts +159 -0
- package/types/jsx.d.ts +49 -44
- package/types/observe.d.ts +535 -0
- package/types/reconcile.d.ts +1 -0
- package/types/render.d.ts +11 -0
- package/types/request-error-hook.d.ts +5 -0
- package/types/response.d.ts +95 -147
- package/types/serializer-decode.d.ts +173 -114
- package/types/serializer.d.ts +115 -153
- package/types/server-functions/argument-codec.d.ts +30 -0
- package/types/server-functions/client.d.ts +237 -223
- package/types/server-functions/flash.d.ts +28 -30
- package/types/server-functions/registry.d.ts +105 -0
- package/types/server-functions/rich-args.d.ts +1 -10
- package/types/server-functions/server.d.ts +538 -531
- package/types/server-functions/shared.d.ts +398 -425
- package/types/server-functions/uploads.d.ts +53 -0
- package/types/server-mock.d.ts +154 -20
- package/types/server-observe.d.ts +86 -0
- package/types/server.d.ts +601 -422
- package/types/trace.d.ts +127 -0
- package/LICENSE +0 -21
- package/dist/web.cjs +0 -2033
- package/frames/dist/client.cjs +0 -2002
- package/frames/dist/client.dev.cjs +0 -2022
- package/frames/dist/server.cjs +0 -3877
- package/serialization/dist/decode.cjs +0 -139
- package/serialization/dist/serialization.cjs +0 -261
- package/serialization/types-cjs/index.d.cts +0 -182
- package/serialization/types-cjs/package.json +0 -3
- package/serialization/types-cjs/serializer-decode.d.cts +0 -182
- package/server-functions/dist/client.cjs +0 -834
- package/server-functions/dist/rich-args.cjs +0 -11
- package/server-functions/dist/server.cjs +0 -1242
- package/server-functions/dist/server.dev.cjs +0 -1242
- package/storage/dist/storage.cjs +0 -12
- package/storage/types-cjs/index.d.cts +0 -28
- package/storage/types-cjs/package.json +0 -3
- package/types/core.d.ts +0 -9
- package/types-cjs/client.d.cts +0 -337
- package/types-cjs/cookies.d.cts +0 -93
- package/types-cjs/core.d.cts +0 -9
- package/types-cjs/frames/client.d.cts +0 -36
- package/types-cjs/frames/frame-client.d.cts +0 -356
- package/types-cjs/frames/frame-sink.d.cts +0 -194
- package/types-cjs/frames/frame-transport.d.cts +0 -222
- package/types-cjs/frames/serializer.d.cts +0 -182
- package/types-cjs/frames/server.d.cts +0 -52
- package/types-cjs/index.d.cts +0 -244
- package/types-cjs/jsx-properties.d.cts +0 -93
- package/types-cjs/jsx.d.cts +0 -4159
- package/types-cjs/package.json +0 -3
- package/types-cjs/response.d.cts +0 -174
- package/types-cjs/serializer-decode.d.cts +0 -182
- package/types-cjs/serializer.d.cts +0 -182
- package/types-cjs/server-functions/client.d.cts +0 -262
- package/types-cjs/server-functions/flash.d.cts +0 -38
- package/types-cjs/server-functions/rich-args.d.cts +0 -10
- package/types-cjs/server-functions/server.d.cts +0 -681
- package/types-cjs/server-functions/shared.d.cts +0 -523
- package/types-cjs/server-mock.d.cts +0 -286
- package/types-cjs/server.d.cts +0 -544
|
@@ -1,165 +1,38 @@
|
|
|
1
|
-
import { getOwner, onCleanup, createMemo, runWithOwner,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { OBSERVE, DEV, getOwner, onCleanup, createMemo, runWithOwner, untrack, createRenderEffect, onHydrationEnd, createSignal, createOwner } from 'solid-js';
|
|
2
|
+
import { installServerComponentHydration, insert } from '@solidjs/web';
|
|
3
|
+
import { frameAddress, SINGLE_FLIGHT_HEADER, LIVE_WIRE, deserializeStream, getServerFunctionsCodec, createChunk, deliverFlightData, ERROR_HEADER, hasFlightMetadata, ChunkReader, configureServerFunctionsClient } from '@solidjs/web/server-functions/client';
|
|
4
|
+
import { setSignalIdentities, sharedConfig, createLoadingBoundary, setWriteHook, setReadWatch, signalName, storeName } from 'solid-js/internal';
|
|
4
5
|
|
|
5
6
|
const ELEMENT_NODE = 1;
|
|
6
|
-
const TEXT_NODE = 3;
|
|
7
7
|
const COMMENT_NODE = 8;
|
|
8
|
-
const CLAIM_SEAM = Symbol.for("
|
|
8
|
+
const CLAIM_SEAM = Symbol.for("solid.element-claims");
|
|
9
9
|
const CLAIMED_ELEMENTS = "a[href], form[action]";
|
|
10
10
|
function claimHandlers() {
|
|
11
11
|
const handlers = globalThis[CLAIM_SEAM];
|
|
12
12
|
return handlers !== undefined && handlers.length !== 0 ? handlers : undefined;
|
|
13
13
|
}
|
|
14
|
-
function claimNode(handlers, el) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const boundSeam = globalThis[BOUND_SEAM] || (globalThis[BOUND_SEAM] = {});
|
|
20
|
-
const BND_ATTR = "_bnd";
|
|
21
|
-
const BND_SELECTOR = "[_bnd]";
|
|
22
|
-
function bndMap(el) {
|
|
23
|
-
const s = el.getAttribute(BND_ATTR);
|
|
24
|
-
if (!s) return undefined;
|
|
25
|
-
const map = {};
|
|
26
|
-
for (const entry of s.split(",")) {
|
|
27
|
-
const eq = entry.indexOf("=");
|
|
28
|
-
if (eq < 1) continue;
|
|
29
|
-
const pos = entry.slice(0, eq);
|
|
30
|
-
const prop = decodeURIComponent(entry.slice(eq + 1));
|
|
31
|
-
const prev = map[pos];
|
|
32
|
-
if (prev === undefined) map[pos] = prop;else if (Array.isArray(prev)) prev.push(prop);else map[pos] = [prev, prop];
|
|
33
|
-
}
|
|
34
|
-
return map;
|
|
35
|
-
}
|
|
36
|
-
boundSeam.resolve = (el, type) => {
|
|
37
|
-
const frame = el._$bndFrame;
|
|
38
|
-
if (!frame) return undefined;
|
|
39
|
-
const map = bndMap(el);
|
|
40
|
-
const prop = map && map[type];
|
|
41
|
-
if (typeof prop !== "string") return undefined;
|
|
42
|
-
return claimFn(frame, type, prop);
|
|
43
|
-
};
|
|
44
|
-
function claimFn(frame, pos, prop) {
|
|
45
|
-
const fn = frame.clientProp(prop);
|
|
46
|
-
if (typeof fn === "function") return fn;
|
|
47
|
-
if (fn !== undefined) {
|
|
48
|
-
console.warn(`A server element claims \`${pos}\` from client prop \`${prop}\`, but the mounted ` + `frame's prop is not a function.`);
|
|
49
|
-
}
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
function sweepBound(root, frame, delegate, scope) {
|
|
53
|
-
const isElement = root.nodeType === ELEMENT_NODE;
|
|
54
|
-
if (!isElement && root.nodeType !== 11 ) return;
|
|
55
|
-
let els;
|
|
56
|
-
if (isElement && root.hasAttribute(BND_ATTR)) (els = []).push(root);
|
|
57
|
-
const found = root.querySelectorAll(BND_SELECTOR);
|
|
58
|
-
if (found.length) {
|
|
59
|
-
els || (els = []);
|
|
60
|
-
for (let i = 0; i < found.length; i++) els.push(found[i]);
|
|
61
|
-
}
|
|
62
|
-
if (!els) return;
|
|
63
|
-
const run = () => {
|
|
64
|
-
let types;
|
|
65
|
-
for (const el of els) {
|
|
66
|
-
el._$bndFrame = frame;
|
|
67
|
-
const map = bndMap(el);
|
|
68
|
-
if (!map) continue;
|
|
69
|
-
for (const pos in map) {
|
|
70
|
-
if (pos === "ref") fireRefs(frame, el, map.ref);else (types || (types = [])).push(pos);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (types && delegate) delegate(types);
|
|
74
|
-
};
|
|
75
|
-
scope ? scope(run) : run();
|
|
76
|
-
}
|
|
77
|
-
function fireRefs(frame, el, prop) {
|
|
78
|
-
const fired = el._$bndFired || (el._$bndFired = new Set());
|
|
79
|
-
for (const p of Array.isArray(prop) ? prop : [prop]) {
|
|
80
|
-
if (fired.has(p)) continue;
|
|
81
|
-
fired.add(p);
|
|
82
|
-
const fn = claimFn(frame, "ref", p);
|
|
83
|
-
if (fn) fn(el);
|
|
14
|
+
function claimNode(handlers, el, adopter) {
|
|
15
|
+
if (adopter) {
|
|
16
|
+
const by = adoptedBy.get(el);
|
|
17
|
+
if (by && liveFrames.has(by)) return;
|
|
18
|
+
adoptedBy.set(el, adopter);
|
|
84
19
|
}
|
|
20
|
+
for (let i = 0; i < handlers.length; i++) handlers[i](el);
|
|
85
21
|
}
|
|
86
|
-
function claimTree(handlers, root) {
|
|
22
|
+
function claimTree(handlers, root, adopter) {
|
|
87
23
|
const isElement = root.nodeType === ELEMENT_NODE;
|
|
88
24
|
if (!isElement && root.nodeType !== 11 ) return;
|
|
89
|
-
if (isElement && root.matches(CLAIMED_ELEMENTS)) claimNode(handlers, root);
|
|
25
|
+
if (isElement && root.matches(CLAIMED_ELEMENTS)) claimNode(handlers, root, adopter);
|
|
90
26
|
const found = root.querySelectorAll(CLAIMED_ELEMENTS);
|
|
91
|
-
for (let i = 0; i < found.length; i++) claimNode(handlers, found[i]);
|
|
27
|
+
for (let i = 0; i < found.length; i++) claimNode(handlers, found[i], adopter);
|
|
92
28
|
}
|
|
29
|
+
const adoptedBy = new WeakMap();
|
|
93
30
|
const placeholderId = name => `pl-${name}`;
|
|
94
31
|
const SLOT_START = /^slot:(.+):start$/;
|
|
95
32
|
const SLOT_END = /^slot:(.+):end$/;
|
|
96
33
|
const slotEnd = id => `slot:${id}:end`;
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
case "start":
|
|
100
|
-
case "data":
|
|
101
|
-
return {};
|
|
102
|
-
case "html":
|
|
103
|
-
return {
|
|
104
|
-
"": {
|
|
105
|
-
kind: "html",
|
|
106
|
-
value: chunk.html
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
case "fragment":
|
|
110
|
-
return {
|
|
111
|
-
[`seg:${chunk.key}`]: {
|
|
112
|
-
kind: "html",
|
|
113
|
-
value: chunk.html
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
case "reveal":
|
|
117
|
-
{
|
|
118
|
-
const records = {};
|
|
119
|
-
const gate = chunk.fallback ? "fallback" : "reveal";
|
|
120
|
-
for (const key of chunk.keys) records[`seg:${key}:${gate}`] = true;
|
|
121
|
-
return records;
|
|
122
|
-
}
|
|
123
|
-
case "assets":
|
|
124
|
-
return {
|
|
125
|
-
[`seg:${chunk.key}:assets`]: chunk
|
|
126
|
-
};
|
|
127
|
-
case "slot":
|
|
128
|
-
return {
|
|
129
|
-
[`slot:${chunk.key}`]: {
|
|
130
|
-
kind: "slot",
|
|
131
|
-
args: chunk.args
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
case "hole":
|
|
135
|
-
return {
|
|
136
|
-
[`hole:${chunk.key}`]: {
|
|
137
|
-
kind: "html",
|
|
138
|
-
value: chunk.html
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
case "attr":
|
|
142
|
-
return {
|
|
143
|
-
[`attr:${chunk.key}`]: {
|
|
144
|
-
kind: "attrs",
|
|
145
|
-
value: chunk.attrs,
|
|
146
|
-
removed: chunk.removed
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
case "complete":
|
|
150
|
-
return {
|
|
151
|
-
":complete": true
|
|
152
|
-
};
|
|
153
|
-
case "error":
|
|
154
|
-
if (!chunk.key) return {
|
|
155
|
-
":error": chunk.error
|
|
156
|
-
};
|
|
157
|
-
return {
|
|
158
|
-
[`${/^lha?:/.test(chunk.key) ? "hole" : "seg"}:${chunk.key}:error`]: chunk.error
|
|
159
|
-
};
|
|
160
|
-
default:
|
|
161
|
-
return {};
|
|
162
|
-
}
|
|
34
|
+
function isAsyncValue(v) {
|
|
35
|
+
return v !== null && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
|
|
163
36
|
}
|
|
164
37
|
function createFrameHost(options = {}) {
|
|
165
38
|
const frames = new Map();
|
|
@@ -172,28 +45,77 @@ function createFrameHost(options = {}) {
|
|
|
172
45
|
});
|
|
173
46
|
return store;
|
|
174
47
|
};
|
|
48
|
+
const landings = new Map();
|
|
49
|
+
const lands = records => "" in records || ":error" in records || ":complete" in records;
|
|
50
|
+
const applyTo = (id, version, r) => {
|
|
51
|
+
const set = frames.get(id);
|
|
52
|
+
if (set) for (const frame of set) frame.apply({
|
|
53
|
+
version,
|
|
54
|
+
r
|
|
55
|
+
});
|
|
56
|
+
};
|
|
175
57
|
const write = (store, version, records) => {
|
|
176
58
|
if (store.version !== undefined && version < store.version) return false;
|
|
177
59
|
if (store.version === undefined || version > store.version) {
|
|
178
60
|
store.version = version;
|
|
179
|
-
|
|
61
|
+
store.records = {};
|
|
180
62
|
}
|
|
63
|
+
const assets = records["seg::assets"];
|
|
64
|
+
const previous = assets && store.records["seg::assets"];
|
|
181
65
|
Object.assign(store.records, records);
|
|
66
|
+
if (previous && previous !== assets) {
|
|
67
|
+
const merged = {
|
|
68
|
+
...previous
|
|
69
|
+
};
|
|
70
|
+
for (const name in assets) {
|
|
71
|
+
const values = assets[name];
|
|
72
|
+
if (Array.isArray(values)) merged[name] = previous[name] ? previous[name].concat(values) : values;
|
|
73
|
+
}
|
|
74
|
+
store.records["seg::assets"] = merged;
|
|
75
|
+
}
|
|
182
76
|
return true;
|
|
183
77
|
};
|
|
78
|
+
const settleArgs = (store, recordKey, record, chunk) => {
|
|
79
|
+
const args = record.args;
|
|
80
|
+
const out = {};
|
|
81
|
+
let regions, decoded;
|
|
82
|
+
const settle = () => {
|
|
83
|
+
if (! --record.pending && store.records[recordKey] === record) applyTo(chunk.id, store.version, {
|
|
84
|
+
[recordKey]: record
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
for (const key in args) {
|
|
88
|
+
const value = args[key];
|
|
89
|
+
if (value && typeof value.$ref === "string") {
|
|
90
|
+
const resolved = out[key] = options.resolve && options.resolve(value, chunk.id, chunk.version, store.version);
|
|
91
|
+
(decoded ??= {})[key] = true;
|
|
92
|
+
if (resolved instanceof Promise && resolved.s === 0) {
|
|
93
|
+
record.pending = (record.pending || 0) + 1;
|
|
94
|
+
resolved.c.push(settle);
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
if (value && typeof value.$frame === "string") (regions ??= {})[key] = value.$frame;
|
|
98
|
+
out[key] = value;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
record.args = out;
|
|
102
|
+
record.regions = regions;
|
|
103
|
+
record.decoded = decoded;
|
|
104
|
+
};
|
|
184
105
|
return {
|
|
185
|
-
delegate: options.delegate,
|
|
186
106
|
register(id, frame) {
|
|
187
107
|
let set = frames.get(id);
|
|
188
108
|
if (!set) frames.set(id, set = new Set());
|
|
189
109
|
set.add(frame);
|
|
190
110
|
const store = stores.get(id);
|
|
191
111
|
if (store && store.version !== undefined) {
|
|
192
|
-
frame.apply({
|
|
112
|
+
if (!store.open) frame.apply({
|
|
193
113
|
version: store.version,
|
|
194
114
|
r: store.records
|
|
115
|
+
});else if (store.shown) frame.apply({
|
|
116
|
+
version: store.shownVersion,
|
|
117
|
+
r: store.shown
|
|
195
118
|
});
|
|
196
|
-
frame.rebase && frame.rebase();
|
|
197
119
|
}
|
|
198
120
|
},
|
|
199
121
|
unregister(id, frame) {
|
|
@@ -211,26 +133,86 @@ function createFrameHost(options = {}) {
|
|
|
211
133
|
value: html
|
|
212
134
|
};
|
|
213
135
|
if (store.version === undefined) store.version = 0;
|
|
136
|
+
store.shown = store.records;
|
|
137
|
+
store.shownVersion = store.version;
|
|
214
138
|
}
|
|
215
139
|
}
|
|
216
140
|
}
|
|
217
141
|
}
|
|
218
|
-
if (!frame)
|
|
142
|
+
if (!frame) {
|
|
143
|
+
stores.delete(id);
|
|
144
|
+
landings.delete(id);
|
|
145
|
+
}
|
|
219
146
|
},
|
|
220
|
-
apply(
|
|
221
|
-
if (
|
|
222
|
-
|
|
147
|
+
apply(msg) {
|
|
148
|
+
if (msg.type === "data") {
|
|
149
|
+
const store = stores.get(msg.id);
|
|
150
|
+
const current = store && store.version;
|
|
151
|
+
if (store && msg.version < current) return;
|
|
152
|
+
options.applyData && options.applyData(msg, current);
|
|
223
153
|
return;
|
|
224
154
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
155
|
+
let records = msg.r || {};
|
|
156
|
+
let slots;
|
|
157
|
+
for (const key in records) if (key.startsWith("slot:")) {
|
|
158
|
+
if (!slots) records = {
|
|
159
|
+
...records
|
|
160
|
+
};
|
|
161
|
+
(slots ??= []).push(key);
|
|
162
|
+
records[key] = {
|
|
163
|
+
...records[key]
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const store = storeFor(msg.id);
|
|
167
|
+
if (!write(store, msg.version, records)) return;
|
|
168
|
+
if (slots) for (const key of slots) settleArgs(store, key, records[key], msg);
|
|
169
|
+
if (records[":bound"]) {
|
|
170
|
+
const bound = records[":bound"];
|
|
171
|
+
console.warn(`Server component "${msg.id}" kept streaming past the server's ${bound} ` + `bound and was cut off (:bound: "${bound}"); its content is the last ` + `value the server sent, not a settled one. A source meant to keep streaming is ` + `declared with live(): wrap the server function (live(fn)) so the client holds a ` + `standing connection instead.`);
|
|
172
|
+
}
|
|
173
|
+
let r = records;
|
|
174
|
+
if (msg.type === "start") {
|
|
175
|
+
store.open = true;
|
|
176
|
+
if (store.startedVersion !== msg.version) {
|
|
177
|
+
store.startedVersion = msg.version;
|
|
178
|
+
store.startedAt = msg.startedAt ?? performance.now();
|
|
179
|
+
}
|
|
180
|
+
} else if (lands(records)) {
|
|
181
|
+
store.open = false;
|
|
182
|
+
store.shown = r = store.records;
|
|
183
|
+
store.shownVersion = msg.version;
|
|
184
|
+
const landed = landings.get(msg.id);
|
|
185
|
+
if (landed && !(":complete" in records && ":error" in r)) {
|
|
186
|
+
landings.delete(msg.id);
|
|
187
|
+
":error" in records ? landed.j(records[":error"]) : landed.r();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
applyTo(msg.id, msg.version, r);
|
|
191
|
+
if (":complete" in records || ":error" in records) options.closeData && options.closeData(msg.id, msg.version, records[":error"]);
|
|
192
|
+
},
|
|
193
|
+
landing(id) {
|
|
194
|
+
const store = stores.get(id);
|
|
195
|
+
if (!store || !store.open && !store.shown) return undefined;
|
|
196
|
+
if (store.shown && !(":error" in store.shown)) return undefined;
|
|
197
|
+
let wait = landings.get(id);
|
|
198
|
+
if (!wait) {
|
|
199
|
+
landings.set(id, wait = {});
|
|
200
|
+
wait.p = new Promise((r, j) => (wait.r = r, wait.j = j));
|
|
201
|
+
if (store.open) OBSERVE.attribution.markFlight(wait.p, store.startedAt);
|
|
202
|
+
}
|
|
203
|
+
return wait.p;
|
|
204
|
+
},
|
|
205
|
+
preview(msg) {
|
|
206
|
+
const set = frames.get(msg.id);
|
|
207
|
+
if (!set || !msg.r) return;
|
|
208
|
+
let records;
|
|
209
|
+
for (const key in msg.r) if (key.startsWith("slot:")) {
|
|
210
|
+
const record = (records ??= {})[key] = {
|
|
211
|
+
...msg.r[key]
|
|
212
|
+
};
|
|
213
|
+
settleArgs(storeFor(msg.id), key, record, msg);
|
|
233
214
|
}
|
|
215
|
+
if (records) for (const frame of set) frame.preview && frame.preview(records);
|
|
234
216
|
},
|
|
235
217
|
get(id) {
|
|
236
218
|
const set = frames.get(id);
|
|
@@ -240,83 +222,123 @@ function createFrameHost(options = {}) {
|
|
|
240
222
|
if (!options.serialize) throw new Error("host has no serializer");
|
|
241
223
|
return options.serialize(value);
|
|
242
224
|
},
|
|
243
|
-
resolve(ref, frameId) {
|
|
244
|
-
return options.resolve ? options.resolve(ref, frameId) : undefined;
|
|
245
|
-
},
|
|
246
225
|
revive: options.revive,
|
|
247
|
-
isContainer: options.isContainer,
|
|
248
226
|
prepareData: options.prepareData
|
|
249
227
|
};
|
|
250
228
|
}
|
|
251
229
|
const FRAME_APPLIED_EVENT = "frame:applied";
|
|
230
|
+
const tierLoaders = {};
|
|
231
|
+
const tierLoads = {};
|
|
232
|
+
const liveFrames = new Set();
|
|
233
|
+
let deferDriver = null;
|
|
234
|
+
function setDeferDriver(driver) {
|
|
235
|
+
deferDriver = driver;
|
|
236
|
+
}
|
|
237
|
+
let deferMountWatch = null;
|
|
238
|
+
function setDeferMountWatch(watch) {
|
|
239
|
+
deferMountWatch = watch;
|
|
240
|
+
}
|
|
241
|
+
function deferredFrames() {
|
|
242
|
+
return [...liveFrames].filter(f => f.deferred);
|
|
243
|
+
}
|
|
244
|
+
function releaseDeferHolds() {
|
|
245
|
+
for (const f of liveFrames) f.releaseDeferHold();
|
|
246
|
+
}
|
|
247
|
+
function hasSlotRange(root) {
|
|
248
|
+
const w = root.ownerDocument.createTreeWalker(root, 0x80);
|
|
249
|
+
for (let n; n = w.nextNode();) if (n.data.startsWith("slot:")) return true;
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
function liveFrameAt(node) {
|
|
253
|
+
let hit;
|
|
254
|
+
for (const f of liveFrames) if (f.el.contains(node) && (!hit || hit.el.contains(f.el))) hit = f;
|
|
255
|
+
return hit;
|
|
256
|
+
}
|
|
257
|
+
function prepareTier(name) {
|
|
258
|
+
let load = tierLoads[name];
|
|
259
|
+
if (!load) {
|
|
260
|
+
const loader = tierLoaders[name];
|
|
261
|
+
tierLoads[name] = load = loader ? loader().then(module => {
|
|
262
|
+
load.r = module;
|
|
263
|
+
module.install?.();
|
|
264
|
+
for (const frame of liveFrames) frame.apply({
|
|
265
|
+
version: frame.version,
|
|
266
|
+
r: {}
|
|
267
|
+
});
|
|
268
|
+
}) : Promise.resolve();
|
|
269
|
+
}
|
|
270
|
+
return load;
|
|
271
|
+
}
|
|
272
|
+
const prepareMorph = () => liveFrames.size && prepareTier("wire");
|
|
273
|
+
const tierReady = name => !tierLoaders[name] || prepareTier(name).r;
|
|
274
|
+
const needsRegions = record => record.regions && !tierReady("regions");
|
|
275
|
+
const carriesTrace = value => value != null && typeof value === "object" && (value.$tr != null || Object.values(value).some(carriesTrace));
|
|
276
|
+
const needsTrace = args => !tierLoads.trace?.r && carriesTrace(args) && !tierReady("trace");
|
|
252
277
|
class FrameImpl {
|
|
253
278
|
#element;
|
|
254
|
-
#start;
|
|
255
|
-
#end;
|
|
256
279
|
#options;
|
|
280
|
+
#outer;
|
|
257
281
|
#version;
|
|
258
282
|
#store = Object.create(null);
|
|
259
|
-
#
|
|
283
|
+
#content = new Set();
|
|
284
|
+
#appliedRoot;
|
|
285
|
+
#appliedError;
|
|
260
286
|
#hasContent = false;
|
|
261
|
-
#errorNotified = false;
|
|
262
|
-
#revealed = new Set();
|
|
263
|
-
#fallbackShown = new Set();
|
|
264
287
|
#appliedHoles = new Map();
|
|
288
|
+
#liveTargets = new Map();
|
|
289
|
+
#shows = {};
|
|
290
|
+
#liveMount;
|
|
265
291
|
#slots;
|
|
266
292
|
#mountedSlots = new Set();
|
|
267
293
|
#slotCleanups = new Map();
|
|
268
294
|
#slotArgs = new Map();
|
|
269
295
|
#slotUpdaters = new Map();
|
|
270
|
-
#
|
|
271
|
-
#
|
|
272
|
-
#
|
|
273
|
-
#
|
|
274
|
-
#recordRefresh = null;
|
|
296
|
+
#hold;
|
|
297
|
+
#heldRecords = new Map();
|
|
298
|
+
#found;
|
|
299
|
+
#waiting = new Set();
|
|
275
300
|
#disposed = false;
|
|
276
|
-
#
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
#
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
301
|
+
#defers = false;
|
|
302
|
+
#deferred = false;
|
|
303
|
+
#deferFound;
|
|
304
|
+
#deferWaiting = false;
|
|
305
|
+
#deferMounted = new Map();
|
|
306
|
+
#deferHold;
|
|
307
|
+
#claimTree = (node, direct, adopter) => {
|
|
284
308
|
const handlers = claimHandlers();
|
|
285
309
|
if (!handlers) return;
|
|
286
|
-
this.#scoped(() => direct ? claimNode(handlers, node) : claimTree(handlers, node));
|
|
310
|
+
this.#scoped(() => direct ? claimNode(handlers, node) : claimTree(handlers, node, adopter));
|
|
287
311
|
};
|
|
288
|
-
clientProp(name) {
|
|
289
|
-
const props = this.#options.props;
|
|
290
|
-
return props ? props[name] : undefined;
|
|
291
|
-
}
|
|
292
312
|
#scoped(fn) {
|
|
293
313
|
const scope = this.#options.ownerScope;
|
|
294
314
|
return scope ? scope(fn) : fn();
|
|
295
315
|
}
|
|
296
|
-
constructor(element,
|
|
316
|
+
constructor(element, options = {}) {
|
|
297
317
|
this.#element = element;
|
|
298
|
-
this.#start = start;
|
|
299
|
-
this.#end = end;
|
|
300
318
|
this.#options = options;
|
|
301
319
|
this.#slots = options.slots;
|
|
320
|
+
this.#outer = options.parent;
|
|
321
|
+
liveFrames.add(this);
|
|
302
322
|
if (options.adopt) {
|
|
303
323
|
this.#hasContent = true;
|
|
304
324
|
this.#claimContent();
|
|
325
|
+
this.#defers = !!deferDriver && !!(options.defer || this.#outer?.defers);
|
|
326
|
+
this.#deferred = this.#defers && !!(this.#slots || this.#outer) && hasSlotRange(element);
|
|
305
327
|
}
|
|
306
328
|
if (options.host && options.id !== undefined) {
|
|
307
329
|
options.host.register(options.id, this);
|
|
308
330
|
}
|
|
309
|
-
if (
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
331
|
+
if (this.#deferred) {
|
|
332
|
+
this.#deferHold = options.hold?.();
|
|
333
|
+
deferDriver(this);
|
|
334
|
+
} else if (options.adopt && this.#version === undefined) this.#syncSlots();
|
|
313
335
|
}
|
|
314
336
|
#applied(version, reason) {
|
|
315
337
|
this.#options.onApply?.({
|
|
316
338
|
version,
|
|
317
339
|
reason
|
|
318
340
|
});
|
|
319
|
-
const parent = this.#
|
|
341
|
+
const parent = this.#element;
|
|
320
342
|
const Ev = parent && (parent.ownerDocument || parent).defaultView?.CustomEvent;
|
|
321
343
|
if (Ev) {
|
|
322
344
|
parent.dispatchEvent(new Ev(FRAME_APPLIED_EVENT, {
|
|
@@ -329,18 +351,12 @@ class FrameImpl {
|
|
|
329
351
|
}));
|
|
330
352
|
}
|
|
331
353
|
}
|
|
332
|
-
#firstContent() {
|
|
333
|
-
return this.#start ? this.#start.nextSibling : this.#parent().firstChild;
|
|
334
|
-
}
|
|
335
354
|
get version() {
|
|
336
355
|
return this.#version;
|
|
337
356
|
}
|
|
338
357
|
get store() {
|
|
339
358
|
return this.#store;
|
|
340
359
|
}
|
|
341
|
-
isRevealed(segment) {
|
|
342
|
-
return this.#revealed.has(segment);
|
|
343
|
-
}
|
|
344
360
|
get error() {
|
|
345
361
|
return this.#store[":error"];
|
|
346
362
|
}
|
|
@@ -355,163 +371,274 @@ class FrameImpl {
|
|
|
355
371
|
this.#version = v;
|
|
356
372
|
this.#resetStreamState();
|
|
357
373
|
}
|
|
374
|
+
let only = [];
|
|
358
375
|
for (const key in write.r) {
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
this.#store[key] = incoming;
|
|
376
|
+
const prev = this.#store[key];
|
|
377
|
+
const occurrence = key.slice(5);
|
|
378
|
+
if (this.#deferred && prev?.kind === "slot" && !prev.pending && !this.#mountedSlots.has(occurrence)) this.#heldRecords.has(occurrence) || this.#heldRecords.set(occurrence, prev);
|
|
379
|
+
this.#store[key] = write.r[key];
|
|
380
|
+
if (key.startsWith("slot:")) only?.push(occurrence);else this.#content.add(key), only = undefined;
|
|
367
381
|
}
|
|
368
|
-
this.#flush();
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
this.#
|
|
382
|
+
this.#flush(only?.length ? only : undefined);
|
|
383
|
+
}
|
|
384
|
+
preview(records, inherited) {
|
|
385
|
+
const adopted = new Set();
|
|
386
|
+
if (this.#disposed) return adopted;
|
|
387
|
+
const R = tierLoads.regions?.r;
|
|
388
|
+
for (const key in records) {
|
|
389
|
+
const record = records[key];
|
|
390
|
+
if (!record || record.kind !== "slot" || !key.startsWith("slot:")) continue;
|
|
391
|
+
if (inherited && key in this.#store) continue;
|
|
392
|
+
const occurrence = key.slice(5);
|
|
393
|
+
const update = this.#mountedSlots.has(occurrence) && this.#slotUpdaters.get(occurrence);
|
|
394
|
+
if (!update || (R ? R.changed(this, occurrence, record) : record.regions)) continue;
|
|
395
|
+
this.#slotArgs.set(occurrence, record);
|
|
396
|
+
adopted.add(key);
|
|
397
|
+
update(this.#resolveArgs(occurrence, record));
|
|
398
|
+
}
|
|
399
|
+
if (R) for (const frame of R.frames(this)) for (const key of frame.preview(records, true)) adopted.add(key);
|
|
400
|
+
if (!inherited) for (const key of adopted) this.#store[key] = records[key];
|
|
401
|
+
return adopted;
|
|
402
|
+
}
|
|
403
|
+
#resetStreamState() {
|
|
404
|
+
if (this.#hasContent) prepareTier("wire");
|
|
405
|
+
this.#found = undefined;
|
|
406
|
+
this.#store = Object.create(null);
|
|
407
|
+
this.#content.clear();
|
|
408
|
+
this.#appliedRoot = this.#appliedError = undefined;
|
|
373
409
|
this.#appliedHoles.clear();
|
|
374
|
-
this.#
|
|
375
|
-
|
|
410
|
+
this.#liveTargets.clear();
|
|
411
|
+
this.#shows = {};
|
|
376
412
|
}
|
|
377
|
-
#flush() {
|
|
413
|
+
#flush(only) {
|
|
378
414
|
if (this.#disposed) return;
|
|
379
415
|
const version = this.#version;
|
|
380
416
|
const root = this.#store[""];
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
this.#
|
|
384
|
-
|
|
417
|
+
const applied = this.#appliedRoot;
|
|
418
|
+
if (root && root.kind === "html" && root !== this.#appliedRoot) {
|
|
419
|
+
const wire = this.#hasContent ? tierReady("wire") : null;
|
|
420
|
+
if (wire === undefined) return;
|
|
421
|
+
const reason = wire ? "morph" : "materialize";
|
|
422
|
+
this.#applyRoot(root.value, wire);
|
|
423
|
+
this.#appliedRoot = root;
|
|
424
|
+
this.#recordHave("", root);
|
|
385
425
|
this.#applied(version, reason);
|
|
386
426
|
}
|
|
387
|
-
|
|
388
|
-
|
|
427
|
+
const error = this.#store[":error"];
|
|
428
|
+
if (error && error !== this.#appliedError) {
|
|
429
|
+
this.#appliedError = error;
|
|
389
430
|
this.#applied(version, "error");
|
|
390
431
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
this.#revealSegment(name);
|
|
399
|
-
this.#applied(version, "reveal");
|
|
400
|
-
progressed = true;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
for (const key in this.#store) {
|
|
404
|
-
const m = /^seg:([^:]+):fallback$/.exec(key);
|
|
405
|
-
if (!m) continue;
|
|
406
|
-
const name = m[1];
|
|
407
|
-
if (this.#revealed.has(name) || this.#fallbackShown.has(name)) continue;
|
|
408
|
-
if (this.#showFallback(name)) {
|
|
409
|
-
this.#fallbackShown.add(name);
|
|
410
|
-
this.#applied(version, "reveal");
|
|
411
|
-
progressed = true;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
432
|
+
for (const key of this.#content) {
|
|
433
|
+
const record = this.#store[key];
|
|
434
|
+
if (!key.endsWith(":assets") || !record || this.#appliedHoles.get(key) === record) continue;
|
|
435
|
+
const tier = tierReady("assets");
|
|
436
|
+
if (!tier) break;
|
|
437
|
+
this.#appliedHoles.set(key, record);
|
|
438
|
+
tier.apply(record);
|
|
414
439
|
}
|
|
415
|
-
|
|
440
|
+
const revealed = this.#revealSegments();
|
|
441
|
+
let morphed = false;
|
|
442
|
+
const index = {};
|
|
443
|
+
let wire;
|
|
444
|
+
for (const key of this.#content) {
|
|
416
445
|
const record = this.#store[key];
|
|
417
446
|
if (!record || this.#appliedHoles.get(key) === record) continue;
|
|
418
447
|
if (key.startsWith("hole:")) {
|
|
419
448
|
if (key.endsWith(":error")) {
|
|
420
449
|
this.#appliedHoles.set(key, record);
|
|
421
450
|
console.error(`Live hole ${key.slice(5, -6)} failed on the server; latched:`, record);
|
|
422
|
-
|
|
423
|
-
this.#appliedHoles.set(key, record);
|
|
424
|
-
this.#applied(version, "morph");
|
|
451
|
+
continue;
|
|
425
452
|
}
|
|
426
|
-
} else if (key.startsWith("attr:"))
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
453
|
+
} else if (!key.startsWith("attr:")) continue;
|
|
454
|
+
if (!this.#hasContent || !(wire ??= tierReady("wire"))) continue;
|
|
455
|
+
const name = key.slice(5);
|
|
456
|
+
const attr = key[0] === "a";
|
|
457
|
+
if (!attr) this.#found = undefined;
|
|
458
|
+
if (attr ? wire.attrs(this.#live, name, record) : wire.hole(this.#live, name, record, index)) {
|
|
459
|
+
this.#appliedHoles.set(key, record);
|
|
460
|
+
this.#recordHave(attr ? "lha:" + name : name, record);
|
|
461
|
+
morphed = true;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (index.r?.size) wire.graft(index.g, index.r);
|
|
465
|
+
if (morphed) this.#applied(version, "morph");
|
|
466
|
+
if (this.#deferred) {
|
|
467
|
+
if (!morphed && this.#appliedRoot === applied) {
|
|
468
|
+
if (revealed || !only) this.#deferFound = undefined;
|
|
469
|
+
const mounted = only ? new Map() : new Map(this.#deferMounted);
|
|
470
|
+
if (only) for (const id of only) {
|
|
471
|
+
const start = this.#deferMounted.get(id);
|
|
472
|
+
if (start) mounted.set(id, start);else if (!this.#deferFound?.has(id)) this.#deferFound = undefined;
|
|
430
473
|
}
|
|
474
|
+
if (mounted.size) this.#deferWaiting = this.#mountFound(mounted) || this.#deferWaiting;
|
|
475
|
+
return;
|
|
431
476
|
}
|
|
477
|
+
this.#deferred = false;
|
|
478
|
+
this.#deferFound = undefined;
|
|
479
|
+
this.#deferMounted.clear();
|
|
432
480
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
|
|
481
|
+
const found = this.#found;
|
|
482
|
+
if (only && found && this.#appliedRoot === applied) {
|
|
483
|
+
const sub = new Map();
|
|
484
|
+
for (const id of only) {
|
|
485
|
+
const start = found.get(id);
|
|
486
|
+
if (!start?.isConnected) return this.#syncSlots();
|
|
487
|
+
sub.set(id, start);
|
|
439
488
|
}
|
|
489
|
+
this.#mountFound(sub);
|
|
490
|
+
return this.#holdIf(this.#waiting.size);
|
|
440
491
|
}
|
|
441
492
|
this.#syncSlots();
|
|
442
493
|
}
|
|
443
494
|
#resolveSlot(prop) {
|
|
444
|
-
return this.#slots?.[prop] ?? this.#
|
|
495
|
+
return this.#slots?.[prop] ?? (this.#outer && this.#outer.#resolveSlot(prop));
|
|
445
496
|
}
|
|
446
497
|
#resolveSlotRecord(occurrence) {
|
|
447
498
|
const record = this.#store[`slot:${occurrence}`];
|
|
448
499
|
if (record !== undefined) return record;
|
|
449
|
-
return this.#
|
|
500
|
+
return this.#outer && this.#outer.#resolveSlotRecord(occurrence);
|
|
450
501
|
}
|
|
451
502
|
#removeSlotRecord(occurrence) {
|
|
452
503
|
const key = `slot:${occurrence}`;
|
|
453
504
|
if (key in this.#store) {
|
|
454
505
|
if (!this.#mountedSlots.has(occurrence)) delete this.#store[key];
|
|
455
|
-
} else this.#
|
|
506
|
+
} else this.#outer && this.#outer.#removeSlotRecord(occurrence);
|
|
456
507
|
}
|
|
457
508
|
#syncSlots(root) {
|
|
458
|
-
if (!this.#slots && !this.#
|
|
509
|
+
if (!this.#slots && !this.#outer) return;
|
|
459
510
|
const found = new Map();
|
|
460
|
-
|
|
511
|
+
this.#collectSlots(found, root);
|
|
512
|
+
if (root) this.#found = undefined;else this.#found = found, this.#waiting.clear();
|
|
513
|
+
const waiting = this.#mountFound(found);
|
|
514
|
+
if (!root) {
|
|
515
|
+
for (const occurrence of [...this.#mountedSlots]) {
|
|
516
|
+
if (!found.has(occurrence)) this.#unmountSlot(occurrence);
|
|
517
|
+
}
|
|
518
|
+
this.#holdIf(waiting);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
#holdIf(waiting) {
|
|
522
|
+
if (waiting && !this.#hold) this.#hold = this.#options.hold?.();else if (!waiting && this.#hold) this.#releaseHold();
|
|
523
|
+
}
|
|
524
|
+
#mountFound(found) {
|
|
525
|
+
let waiting = false;
|
|
526
|
+
const R = tierLoads.regions?.r;
|
|
461
527
|
for (const [occurrence, start] of found) {
|
|
528
|
+
this.#waiting.delete(occurrence);
|
|
462
529
|
const callback = this.#resolveSlot(propOf(occurrence));
|
|
463
530
|
if (!callback) continue;
|
|
464
531
|
const record = this.#resolveSlotRecord(occurrence);
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
if (zombie) {
|
|
470
|
-
this.#mountedSlots.delete(occurrence);
|
|
471
|
-
this.#runSlotCleanups(occurrence);
|
|
532
|
+
const mounted = this.#mountedSlots.has(occurrence);
|
|
533
|
+
if (record === undefined && isCalled(occurrence)) {
|
|
534
|
+
if (!mounted) waiting = true, this.#waiting.add(occurrence);
|
|
535
|
+
continue;
|
|
472
536
|
}
|
|
473
|
-
if (!
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
const nodes = this.#invokeSlot(occurrence, callback, record, start, this.#options.adopt);
|
|
485
|
-
if (nodes) this.#replaceRange(occurrence, start, nodes);
|
|
486
|
-
this.#slotNodes.set(occurrence, nodes);
|
|
537
|
+
if (!mounted && record && (record.pending || needsRegions(record) || needsTrace(record.args))) {
|
|
538
|
+
waiting = true;
|
|
539
|
+
this.#waiting.add(occurrence);
|
|
540
|
+
if (this.#options.adopt) this.#heldRecords.has(occurrence) || this.#heldRecords.set(occurrence, record);
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
if (!mounted) {
|
|
544
|
+
const held = this.#heldRecords.get(occurrence);
|
|
545
|
+
this.#heldRecords.delete(occurrence);
|
|
546
|
+
const mountRecord = held || record;
|
|
547
|
+
this.#invokeSlot(occurrence, callback, mountRecord, start, this.#options.adopt);
|
|
487
548
|
this.#mountedSlots.add(occurrence);
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
this.#reconcileRegions(occurrence, record);
|
|
494
|
-
continue;
|
|
495
|
-
}
|
|
549
|
+
R?.bind(this, occurrence);
|
|
550
|
+
if (mountRecord === record || !record || record.kind !== "slot") continue;
|
|
551
|
+
}
|
|
552
|
+
if (record !== this.#slotArgs.get(occurrence)) {
|
|
553
|
+
if (needsRegions(record) || needsTrace(record.args)) continue;
|
|
496
554
|
const update = this.#slotUpdaters.get(occurrence);
|
|
497
555
|
if (update) {
|
|
498
|
-
const props = this.#resolveArgs(occurrence, record
|
|
556
|
+
const props = this.#resolveArgs(occurrence, record);
|
|
499
557
|
this.#slotArgs.set(occurrence, record);
|
|
500
558
|
update(props);
|
|
501
|
-
this
|
|
559
|
+
R?.bind(this, occurrence);
|
|
502
560
|
continue;
|
|
503
561
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
this.#slotNodes.set(occurrence, nodes);
|
|
507
|
-
this.#bindRegions(occurrence);
|
|
562
|
+
this.#invokeSlot(occurrence, callback, record, start);
|
|
563
|
+
R?.bind(this, occurrence);
|
|
508
564
|
}
|
|
509
565
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
566
|
+
return waiting;
|
|
567
|
+
}
|
|
568
|
+
get el() {
|
|
569
|
+
return this.#element;
|
|
570
|
+
}
|
|
571
|
+
get defers() {
|
|
572
|
+
return this.#defers;
|
|
573
|
+
}
|
|
574
|
+
get deferred() {
|
|
575
|
+
return this.#deferred;
|
|
576
|
+
}
|
|
577
|
+
mountEnclosing(target) {
|
|
578
|
+
if (!this.#deferred) return false;
|
|
579
|
+
const root = this.#element;
|
|
580
|
+
let outer;
|
|
581
|
+
for (let node = target; node && node !== root; node = node.parentNode) {
|
|
582
|
+
let depth = 0;
|
|
583
|
+
for (let s = node.previousSibling; s; s = s.previousSibling) {
|
|
584
|
+
if (s.nodeType !== COMMENT_NODE || !s.data.startsWith("slot:")) continue;
|
|
585
|
+
if (SLOT_END.test(s.data)) depth++;else if (depth) depth--;else outer = s;
|
|
513
586
|
}
|
|
514
587
|
}
|
|
588
|
+
const id = outer && slotStartId(outer);
|
|
589
|
+
if (!id || this.#mountedSlots.has(id)) return false;
|
|
590
|
+
return this.#mountOne(id, outer);
|
|
591
|
+
}
|
|
592
|
+
#mountOne(id, start) {
|
|
593
|
+
const mount = () => {
|
|
594
|
+
this.#deferWaiting = this.#mountFound(new Map([[id, start]])) || this.#deferWaiting;
|
|
595
|
+
};
|
|
596
|
+
if (deferMountWatch) deferMountWatch(this.#options.claimScope ?? this.#options.id, id, mount);else mount();
|
|
597
|
+
if (!this.#mountedSlots.has(id)) return false;
|
|
598
|
+
this.#deferMounted.set(id, start);
|
|
599
|
+
return true;
|
|
600
|
+
}
|
|
601
|
+
mountDeferred(deadline) {
|
|
602
|
+
if (!this.#deferred) return true;
|
|
603
|
+
let found = this.#deferFound;
|
|
604
|
+
if (!found) {
|
|
605
|
+
found = this.#deferFound = new Map();
|
|
606
|
+
this.#collectSlots(found);
|
|
607
|
+
}
|
|
608
|
+
for (const [id, start] of found) {
|
|
609
|
+
found.delete(id);
|
|
610
|
+
if (this.#mountedSlots.has(id)) this.#deferWaiting = this.#mountFound(new Map([[id, start]])) || this.#deferWaiting;else this.#mountOne(id, start);
|
|
611
|
+
if (deadline !== undefined && found.size && performance.now() > deadline) return false;
|
|
612
|
+
}
|
|
613
|
+
this.#deferred = false;
|
|
614
|
+
this.#deferFound = undefined;
|
|
615
|
+
this.#deferMounted.clear();
|
|
616
|
+
if (this.#deferWaiting && !this.#hold) this.#hold = this.#options.hold?.();
|
|
617
|
+
return true;
|
|
618
|
+
}
|
|
619
|
+
mountOccurrence(id) {
|
|
620
|
+
if (!this.#deferred) return false;
|
|
621
|
+
if (this.#mountedSlots.has(id)) return true;
|
|
622
|
+
let found = this.#deferFound;
|
|
623
|
+
if (!found) {
|
|
624
|
+
found = this.#deferFound = new Map();
|
|
625
|
+
this.#collectSlots(found);
|
|
626
|
+
}
|
|
627
|
+
const start = found.get(id);
|
|
628
|
+
if (!start) return false;
|
|
629
|
+
found.delete(id);
|
|
630
|
+
this.#mountOne(id, start);
|
|
631
|
+
return true;
|
|
632
|
+
}
|
|
633
|
+
releaseDeferHold() {
|
|
634
|
+
const release = this.#deferHold;
|
|
635
|
+
this.#deferHold = undefined;
|
|
636
|
+
release && release();
|
|
637
|
+
}
|
|
638
|
+
#releaseHold() {
|
|
639
|
+
const release = this.#hold;
|
|
640
|
+
this.#hold = undefined;
|
|
641
|
+
release && release();
|
|
515
642
|
}
|
|
516
643
|
#invokeSlot(occurrence, callback, record, start, adopted) {
|
|
517
644
|
this.#slotUpdaters.delete(occurrence);
|
|
@@ -532,31 +659,19 @@ class FrameImpl {
|
|
|
532
659
|
end
|
|
533
660
|
} : undefined
|
|
534
661
|
};
|
|
535
|
-
const props = record && record.kind === "slot" ? this.#resolveArgs(occurrence, record
|
|
536
|
-
|
|
662
|
+
const props = record && record.kind === "slot" ? this.#resolveArgs(occurrence, record, adopted, start) : {};
|
|
663
|
+
this.#scoped(() => callback(props, ctx));
|
|
537
664
|
this.#slotArgs.set(occurrence, record);
|
|
538
665
|
if (cleanups.length) this.#slotCleanups.set(occurrence, cleanups);
|
|
539
|
-
if (content == null) return null;
|
|
540
|
-
return Array.isArray(content) ? content : [content];
|
|
541
|
-
}
|
|
542
|
-
#replaceRange(key, start, nodes) {
|
|
543
|
-
const parent = start.parentNode;
|
|
544
|
-
const end = eachInRange(start, key, n => parent.removeChild(n));
|
|
545
|
-
for (const node of nodes) parent.insertBefore(node, end);
|
|
546
666
|
}
|
|
547
667
|
#unmountSlot(key) {
|
|
548
668
|
this.#mountedSlots.delete(key);
|
|
549
|
-
this.#slotNodes.delete(key);
|
|
550
669
|
this.#slotArgs.delete(key);
|
|
551
670
|
this.#slotUpdaters.delete(key);
|
|
552
|
-
this.#
|
|
671
|
+
this.#heldRecords.delete(key);
|
|
553
672
|
this.#removeSlotRecord(key);
|
|
554
673
|
this.#runSlotCleanups(key);
|
|
555
|
-
|
|
556
|
-
if (regions) {
|
|
557
|
-
disposeRegions(regions);
|
|
558
|
-
this.#slotRegions.delete(key);
|
|
559
|
-
}
|
|
674
|
+
tierLoads.regions?.r?.unmount(this, key);
|
|
560
675
|
}
|
|
561
676
|
#runSlotCleanups(key) {
|
|
562
677
|
const cleanups = this.#slotCleanups.get(key);
|
|
@@ -564,129 +679,33 @@ class FrameImpl {
|
|
|
564
679
|
this.#slotCleanups.delete(key);
|
|
565
680
|
for (const fn of cleanups) fn();
|
|
566
681
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
host,
|
|
570
|
-
id
|
|
571
|
-
} = this.#options;
|
|
572
|
-
if (host) for (const key in args) {
|
|
573
|
-
if (isDataRef(args[key]) && host.resolve(args[key], id) === undefined) return true;
|
|
574
|
-
}
|
|
575
|
-
return false;
|
|
576
|
-
}
|
|
577
|
-
#regionsFor(slotKey) {
|
|
578
|
-
let regions = this.#slotRegions.get(slotKey);
|
|
579
|
-
if (!regions) this.#slotRegions.set(slotKey, regions = new Map());
|
|
580
|
-
return regions;
|
|
682
|
+
get options() {
|
|
683
|
+
return this.#options;
|
|
581
684
|
}
|
|
582
|
-
#resolveArgs(slotKey,
|
|
583
|
-
const
|
|
584
|
-
|
|
685
|
+
#resolveArgs(slotKey, record, claiming, start) {
|
|
686
|
+
const {
|
|
687
|
+
args,
|
|
688
|
+
regions,
|
|
689
|
+
decoded
|
|
690
|
+
} = record;
|
|
691
|
+
const revive = this.#options.host && this.#options.host.revive;
|
|
585
692
|
const props = {};
|
|
586
693
|
for (const key in args) {
|
|
694
|
+
if (regions && key in regions) continue;
|
|
587
695
|
const value = args[key];
|
|
588
|
-
|
|
589
|
-
const resolved = host ? host.resolve(value, this.#options.id) : undefined;
|
|
590
|
-
let cache = this.#slotResolvedRefs.get(slotKey);
|
|
591
|
-
if (!cache) this.#slotResolvedRefs.set(slotKey, cache = {});
|
|
592
|
-
cache[key] = resolved;
|
|
593
|
-
props[key] = resolved;
|
|
594
|
-
} else if (isFrameRef(value)) {
|
|
595
|
-
let entry = regions.get(key);
|
|
596
|
-
if (!entry) {
|
|
597
|
-
const element = makeFrameElement(value.$frame);
|
|
598
|
-
entry = {
|
|
599
|
-
childId: value.$frame,
|
|
600
|
-
element,
|
|
601
|
-
frame: undefined
|
|
602
|
-
};
|
|
603
|
-
regions.set(key, entry);
|
|
604
|
-
} else if (entry.childId !== value.$frame) {
|
|
605
|
-
renameRegion(entry, value.$frame);
|
|
606
|
-
}
|
|
607
|
-
props[key] = entry.element;
|
|
608
|
-
} else {
|
|
609
|
-
props[key] = host && host.revive ? host.revive(value) : value;
|
|
610
|
-
}
|
|
696
|
+
props[key] = revive && !(decoded && key in decoded) ? revive(value, claiming) : value;
|
|
611
697
|
}
|
|
698
|
+
if (regions) tierLoads.regions.r.resolve(this, slotKey, regions, props, claiming && start);
|
|
612
699
|
return props;
|
|
613
700
|
}
|
|
614
|
-
#
|
|
615
|
-
|
|
616
|
-
const regions = this.#regionsFor(slotKey);
|
|
617
|
-
eachInRange(start, slotKey, n => collectRegionElements(n, regions));
|
|
618
|
-
}
|
|
619
|
-
#refArgsUnchanged(occurrence, record) {
|
|
620
|
-
const old = this.#slotArgs.get(occurrence);
|
|
621
|
-
if (!record || record.kind !== "slot") return false;
|
|
622
|
-
if (old && old.kind !== "slot") return false;
|
|
623
|
-
const a = old && old.args || {};
|
|
624
|
-
const b = record.args || {};
|
|
625
|
-
const ka = Object.keys(a);
|
|
626
|
-
const kb = Object.keys(b);
|
|
627
|
-
if (kb.length !== ka.length) return false;
|
|
628
|
-
const cache = this.#slotResolvedRefs.get(occurrence);
|
|
629
|
-
for (const key of ka) {
|
|
630
|
-
const va = a[key];
|
|
631
|
-
const vb = b[key];
|
|
632
|
-
if (va === vb) continue;
|
|
633
|
-
if (isFrameRef(va) && isFrameRef(vb)) continue;
|
|
634
|
-
if (isDataRef(va) && isDataRef(vb) && cache && key in cache) {
|
|
635
|
-
const host = this.#options.host;
|
|
636
|
-
const next = host ? host.resolve(vb, this.#options.id) : undefined;
|
|
637
|
-
if (host && host.isContainer && (host.isContainer(next) || host.isContainer(cache[key]))) {
|
|
638
|
-
if (next === cache[key]) continue;
|
|
639
|
-
return false;
|
|
640
|
-
}
|
|
641
|
-
if (isAsyncLike(next) || isAsyncLike(cache[key])) return false;
|
|
642
|
-
try {
|
|
643
|
-
if (JSON.stringify(next) === JSON.stringify(cache[key])) continue;
|
|
644
|
-
} catch (e) {
|
|
645
|
-
return false;
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
return false;
|
|
649
|
-
}
|
|
650
|
-
return true;
|
|
701
|
+
#collectSlots(found, root) {
|
|
702
|
+
collectSlots(root || this.#element, found);
|
|
651
703
|
}
|
|
652
|
-
#
|
|
653
|
-
|
|
654
|
-
if (!args) return;
|
|
655
|
-
const regions = this.#slotRegions.get(occurrence);
|
|
656
|
-
if (!regions) return;
|
|
657
|
-
for (const key in args) {
|
|
658
|
-
const value = args[key];
|
|
659
|
-
if (!isFrameRef(value)) continue;
|
|
660
|
-
const entry = regions.get(key);
|
|
661
|
-
if (entry && entry.childId !== value.$frame) renameRegion(entry, value.$frame);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
#bindRegions(slotKey) {
|
|
665
|
-
const regions = this.#slotRegions.get(slotKey);
|
|
666
|
-
if (!regions) return;
|
|
667
|
-
for (const entry of regions.values()) {
|
|
668
|
-
if (!entry.frame) {
|
|
669
|
-
entry.frame = new FrameImpl(entry.element, null, null, {
|
|
670
|
-
id: entry.childId,
|
|
671
|
-
host: this.#options.host,
|
|
672
|
-
adopt: entry.adopt,
|
|
673
|
-
claimScope: this.#options.claimScope ?? this.#options.id,
|
|
674
|
-
ownerScope: this.#options.ownerScope,
|
|
675
|
-
resolveSlot: prop => this.#resolveSlot(prop),
|
|
676
|
-
resolveSlotRecord: occurrence => this.#resolveSlotRecord(occurrence),
|
|
677
|
-
removeSlotRecord: occurrence => this.#removeSlotRecord(occurrence)
|
|
678
|
-
});
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
#collectSlots(found) {
|
|
683
|
-
collectSlots(this.#firstContent(), this.#end, found);
|
|
684
|
-
}
|
|
685
|
-
#findPlaceholder(name) {
|
|
686
|
-
return findPlaceholder(this.#firstContent(), this.#end, placeholderId(name));
|
|
704
|
+
#findPlaceholder(name, root) {
|
|
705
|
+
return findPlaceholder((root || this.#element).firstChild, null, placeholderId(name));
|
|
687
706
|
}
|
|
688
707
|
contentHTML() {
|
|
689
|
-
if (this.#disposed || !this.#
|
|
708
|
+
if (this.#disposed || !this.#hasContent) return null;
|
|
690
709
|
return this.#element.innerHTML;
|
|
691
710
|
}
|
|
692
711
|
rebind(id) {
|
|
@@ -704,12 +723,27 @@ class FrameImpl {
|
|
|
704
723
|
this.#element.setAttribute(FRAME_ID_ATTR, id);
|
|
705
724
|
}
|
|
706
725
|
this.#version = undefined;
|
|
707
|
-
this.#
|
|
708
|
-
this.#resetStreamState(true);
|
|
726
|
+
this.#resetStreamState();
|
|
709
727
|
if (host) host.register(id, this);
|
|
710
728
|
}
|
|
711
|
-
|
|
712
|
-
this.#
|
|
729
|
+
get #live() {
|
|
730
|
+
return this.#liveMount ??= {
|
|
731
|
+
e: this.#element,
|
|
732
|
+
t: this.#liveTargets,
|
|
733
|
+
c: this.#claimTree,
|
|
734
|
+
k: found => this.#collectSlots(found),
|
|
735
|
+
s: () => this.#shows,
|
|
736
|
+
x: (key, record) => (this.#appliedHoles.set(key, record), tierLoads.wire.r.cancel(this.#options.host, this.#options.id)),
|
|
737
|
+
w: ((marker, open) => console.error(`Live hole "${marker}" is missing its closing comment; update dropped. ` + `Likely an HTML-rewriting layer stripped it.`, open))
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
#recordHave(key, record) {
|
|
741
|
+
this.#shows = key ? Object.assign(this.#shows, {
|
|
742
|
+
[key]: record.digest
|
|
743
|
+
}, record.holes) : {
|
|
744
|
+
...record.holes
|
|
745
|
+
};
|
|
746
|
+
tierLoads.wire?.r?.have(this, key, record);
|
|
713
747
|
}
|
|
714
748
|
dispose() {
|
|
715
749
|
if (this.#disposed) return;
|
|
@@ -719,125 +753,96 @@ class FrameImpl {
|
|
|
719
753
|
} = this.#options;
|
|
720
754
|
if (host && id !== undefined) host.unregister(id, this);
|
|
721
755
|
this.#disposed = true;
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
}
|
|
756
|
+
liveFrames.delete(this);
|
|
757
|
+
this.#releaseHold();
|
|
758
|
+
this.releaseDeferHold();
|
|
726
759
|
for (const key of [...this.#slotCleanups.keys()]) this.#runSlotCleanups(key);
|
|
727
760
|
for (const key of this.#mountedSlots) this.#removeSlotRecord(key);
|
|
728
|
-
|
|
729
|
-
this.#slotRegions.clear();
|
|
761
|
+
tierLoads.regions?.r?.unmount(this);
|
|
730
762
|
this.#mountedSlots.clear();
|
|
731
763
|
}
|
|
732
|
-
#applyRoot(html) {
|
|
764
|
+
#applyRoot(html, wire) {
|
|
765
|
+
this.#found = undefined;
|
|
766
|
+
this.#liveTargets.clear();
|
|
767
|
+
this.#shows = {};
|
|
733
768
|
const fragment = parseFragment(html);
|
|
734
|
-
const parent = this.#
|
|
769
|
+
const parent = this.#element;
|
|
735
770
|
if (!this.#hasContent) {
|
|
736
|
-
|
|
771
|
+
parent.textContent = "";
|
|
737
772
|
this.#claimTree(fragment);
|
|
738
|
-
parent.
|
|
773
|
+
parent.appendChild(fragment);
|
|
739
774
|
this.#hasContent = true;
|
|
740
775
|
} else {
|
|
741
776
|
const claim = this.#claimTree;
|
|
742
777
|
const ranges = new Map();
|
|
743
778
|
this.#collectSlots(ranges);
|
|
744
|
-
|
|
745
|
-
reconcileChildren(parent, fragment, this.#start, this.#end, claim, ranges, grafts);
|
|
746
|
-
if (ranges.size) for (const root of grafts) flushGrafts(root, ranges);
|
|
779
|
+
wire.morph(parent, fragment, claim, ranges);
|
|
747
780
|
}
|
|
748
781
|
}
|
|
749
|
-
#
|
|
750
|
-
|
|
751
|
-
const open = findLiveTarget(this.#firstContent(), this.#end, n => n.nodeType === COMMENT_NODE && n.data === marker);
|
|
752
|
-
if (!open) return false;
|
|
753
|
-
const close = rangeClose(open, "lh:/" + marker.slice(3));
|
|
754
|
-
if (!close) {
|
|
755
|
-
{
|
|
756
|
-
console.error(`Live hole "${marker}" is missing its closing comment; update dropped. ` + `Likely an HTML-rewriting layer stripped it.`, open);
|
|
757
|
-
}
|
|
758
|
-
return false;
|
|
759
|
-
}
|
|
760
|
-
reconcileChildren(open.parentNode, parseFragment(html), open, close, this.#claimTree);
|
|
761
|
-
return true;
|
|
782
|
+
#claimContent() {
|
|
783
|
+
for (let n = this.#element.firstChild; n; n = n.nextSibling) this.#claimTree(n, false, this);
|
|
762
784
|
}
|
|
763
|
-
#
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
785
|
+
#revealSegments(root) {
|
|
786
|
+
const version = this.#version;
|
|
787
|
+
let revealed = false;
|
|
788
|
+
for (const key of this.#content) {
|
|
789
|
+
const record = this.#store[key];
|
|
790
|
+
const name = segmentName(key);
|
|
791
|
+
if (name === null || !record || this.#appliedHoles.get(key) === record) continue;
|
|
792
|
+
if (this.#segmentReady(name, root)) {
|
|
793
|
+
this.#appliedHoles.set(key, record);
|
|
794
|
+
this.#revealSegment(name, root);
|
|
795
|
+
this.#applied(version, "reveal");
|
|
796
|
+
revealed = true;
|
|
775
797
|
}
|
|
776
798
|
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
let n = this.#firstContent();
|
|
785
|
-
while (n && n !== this.#end) {
|
|
786
|
-
this.#claimTree(n);
|
|
787
|
-
n = n.nextSibling;
|
|
799
|
+
for (const key of this.#content) {
|
|
800
|
+
const m = /^seg:([^:]+):fallback$/.exec(key);
|
|
801
|
+
if (!m || this.#appliedHoles.has(key) || this.#appliedHoles.has(`seg:${m[1]}`)) continue;
|
|
802
|
+
if (this.#showFallback(m[1], root)) {
|
|
803
|
+
this.#appliedHoles.set(key, this.#store[key]);
|
|
804
|
+
this.#applied(version, "reveal");
|
|
805
|
+
}
|
|
788
806
|
}
|
|
807
|
+
return revealed;
|
|
789
808
|
}
|
|
790
|
-
#segmentReady(name) {
|
|
809
|
+
#segmentReady(name, root) {
|
|
791
810
|
const content = this.#store[`seg:${name}`];
|
|
792
811
|
if (!content || content.kind !== "html") return false;
|
|
793
812
|
if (!this.#store[`seg:${name}:reveal`]) return false;
|
|
794
813
|
const assets = this.#store[`seg:${name}:assets`];
|
|
795
|
-
if (assets && assets.styles)
|
|
796
|
-
|
|
797
|
-
for (const entry of assets.styles) ready = ensureStylesheet(entry, this.#styleFlush) && ready;
|
|
798
|
-
if (!ready) return false;
|
|
799
|
-
}
|
|
800
|
-
if (!this.#findPlaceholder(name)) return false;
|
|
801
|
-
return true;
|
|
814
|
+
if (assets && (assets.styles || assets.inlineStyles) && !tierReady("assets")?.gate(assets.styles || [], this)) return false;
|
|
815
|
+
return !!this.#findPlaceholder(name, root);
|
|
802
816
|
}
|
|
803
|
-
#revealSegment(name) {
|
|
804
|
-
const tpl = this.#findPlaceholder(name);
|
|
817
|
+
#revealSegment(name, root) {
|
|
818
|
+
const tpl = this.#findPlaceholder(name, root);
|
|
805
819
|
if (!tpl) return;
|
|
806
|
-
|
|
807
|
-
if (assets && assets.inlineStyles) applyInlineStyles(assets.inlineStyles);
|
|
820
|
+
this.#found = undefined;
|
|
808
821
|
const content = this.#store[`seg:${name}`];
|
|
809
822
|
const closing = rangeClose(tpl, placeholderId(name));
|
|
810
823
|
if (!closing) {
|
|
811
|
-
console.error(`Frame fragment placeholder "${name}" is missing its closing comment ` + `(<!--${placeholderId(name)}-->);
|
|
812
|
-
}
|
|
813
|
-
const parent = tpl.parentNode;
|
|
814
|
-
removeUntil(parent, tpl.nextSibling, closing);
|
|
815
|
-
if (this.#options.reveal) {
|
|
816
|
-
const fallbackFrag = tpl.content.cloneNode(true);
|
|
817
|
-
this.#claimTree(fallbackFrag);
|
|
818
|
-
this.#options.reveal({
|
|
819
|
-
before: closing,
|
|
820
|
-
fallback: [...fallbackFrag.childNodes],
|
|
821
|
-
content: () => {
|
|
822
|
-
const materialized = this.#materialize(content);
|
|
823
|
-
this.#syncSlots(materialized);
|
|
824
|
-
this.#claimTree(materialized);
|
|
825
|
-
return materialized;
|
|
826
|
-
}
|
|
827
|
-
});
|
|
828
|
-
tpl.remove();
|
|
829
|
-
this.#revealed.add(name);
|
|
824
|
+
console.error(`Frame fragment placeholder "${name}" is missing its closing comment ` + `(<!--${placeholderId(name)}-->); the segment is not revealed. Likely an ` + `HTML-rewriting layer stripped the comment, or invalid nesting split the ` + `placeholder range.`, tpl);
|
|
830
825
|
return;
|
|
831
826
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
827
|
+
removeUntil(tpl.parentNode, tpl.nextSibling, closing);
|
|
828
|
+
const fallbackFrag = tpl.content.cloneNode(true);
|
|
829
|
+
this.#claimTree(fallbackFrag);
|
|
830
|
+
(this.#options.reveal || revealAtOnce)({
|
|
831
|
+
before: closing,
|
|
832
|
+
fallback: [...fallbackFrag.childNodes],
|
|
833
|
+
content: () => {
|
|
834
|
+
const materialized = this.#materialize(content);
|
|
835
|
+
this.#syncSlots(materialized);
|
|
836
|
+
this.#claimTree(materialized);
|
|
837
|
+
this.#revealSegments(materialized);
|
|
838
|
+
return materialized;
|
|
839
|
+
}
|
|
840
|
+
});
|
|
835
841
|
tpl.remove();
|
|
836
|
-
|
|
837
|
-
this.#revealed.add(name);
|
|
842
|
+
this.#recordHave(name, content);
|
|
838
843
|
}
|
|
839
|
-
#showFallback(name) {
|
|
840
|
-
const tpl = this.#findPlaceholder(name);
|
|
844
|
+
#showFallback(name, root) {
|
|
845
|
+
const tpl = this.#findPlaceholder(name, root);
|
|
841
846
|
if (!tpl) return false;
|
|
842
847
|
const closing = rangeClose(tpl, placeholderId(name));
|
|
843
848
|
if (!closing) return false;
|
|
@@ -851,13 +856,13 @@ class FrameImpl {
|
|
|
851
856
|
}
|
|
852
857
|
}
|
|
853
858
|
function createFrame(boundary, options) {
|
|
854
|
-
return new FrameImpl(boundary,
|
|
859
|
+
return new FrameImpl(boundary, options);
|
|
855
860
|
}
|
|
856
|
-
const FRAME_TAG = "
|
|
861
|
+
const FRAME_TAG = "solid-frame";
|
|
857
862
|
const FRAME_ID_ATTR = "data-fid";
|
|
858
863
|
function createFrameElement(options) {
|
|
859
864
|
const el = makeFrameElement(options.id);
|
|
860
|
-
const frame = new FrameImpl(el,
|
|
865
|
+
const frame = new FrameImpl(el, options);
|
|
861
866
|
return {
|
|
862
867
|
element: el,
|
|
863
868
|
frame,
|
|
@@ -873,30 +878,20 @@ function makeFrameElement(id) {
|
|
|
873
878
|
if (id !== undefined) el.setAttribute(FRAME_ID_ATTR, id);
|
|
874
879
|
return el;
|
|
875
880
|
}
|
|
876
|
-
function isFrameElement(node) {
|
|
877
|
-
return node.nodeType === ELEMENT_NODE && node.hasAttribute(FRAME_ID_ATTR);
|
|
878
|
-
}
|
|
879
881
|
function segmentName(key) {
|
|
880
882
|
const m = /^seg:([^:]+)$/.exec(key);
|
|
881
883
|
return m ? m[1] : null;
|
|
882
884
|
}
|
|
883
|
-
function isAsyncLike(v) {
|
|
884
|
-
return !!v && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
|
|
885
|
-
}
|
|
886
885
|
function propOf(occurrence) {
|
|
887
886
|
const hash = occurrence.indexOf("#");
|
|
888
887
|
return hash === -1 ? occurrence : occurrence.slice(0, hash);
|
|
889
888
|
}
|
|
890
|
-
function
|
|
891
|
-
return
|
|
892
|
-
}
|
|
893
|
-
function isFrameRef(value) {
|
|
894
|
-
return !!value && typeof value.$frame === "string";
|
|
889
|
+
function isCalled(occurrence) {
|
|
890
|
+
return occurrence.indexOf("#") !== -1;
|
|
895
891
|
}
|
|
896
|
-
function
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
} of regions.values()) frame?.dispose();
|
|
892
|
+
function revealAtOnce(seam) {
|
|
893
|
+
seam.before.parentNode.insertBefore(seam.content(), seam.before);
|
|
894
|
+
seam.before.remove();
|
|
900
895
|
}
|
|
901
896
|
function removeUntil(parent, n, stop) {
|
|
902
897
|
while (n && n !== stop) {
|
|
@@ -910,56 +905,6 @@ function parseFragment(html) {
|
|
|
910
905
|
template.innerHTML = html;
|
|
911
906
|
return template.content;
|
|
912
907
|
}
|
|
913
|
-
function findHeadElement(selector, attr, value) {
|
|
914
|
-
for (const node of document.head.querySelectorAll(selector)) {
|
|
915
|
-
if (node.getAttribute(attr) === value) return node;
|
|
916
|
-
}
|
|
917
|
-
return null;
|
|
918
|
-
}
|
|
919
|
-
function ensureStylesheet(entry, onSettle) {
|
|
920
|
-
const href = typeof entry === "string" ? entry : entry.href;
|
|
921
|
-
let link = findHeadElement('link[rel="stylesheet"]', "href", href);
|
|
922
|
-
if (!link) {
|
|
923
|
-
link = document.createElement("link");
|
|
924
|
-
link.rel = "stylesheet";
|
|
925
|
-
if (typeof entry !== "string" && entry.attrs) {
|
|
926
|
-
for (const name in entry.attrs) link.setAttribute(name, entry.attrs[name]);
|
|
927
|
-
}
|
|
928
|
-
link.href = href;
|
|
929
|
-
const waiters = new Set();
|
|
930
|
-
link._$frWaiters = waiters;
|
|
931
|
-
const settle = () => {
|
|
932
|
-
link._$frWaiters = null;
|
|
933
|
-
for (const fn of waiters) fn();
|
|
934
|
-
};
|
|
935
|
-
link.addEventListener("load", settle);
|
|
936
|
-
link.addEventListener("error", settle);
|
|
937
|
-
document.head.appendChild(link);
|
|
938
|
-
}
|
|
939
|
-
const waiters = link._$frWaiters;
|
|
940
|
-
if (waiters == null) return true;
|
|
941
|
-
waiters.add(onSettle);
|
|
942
|
-
return false;
|
|
943
|
-
}
|
|
944
|
-
function ensureModulePreload(href) {
|
|
945
|
-
if (findHeadElement('link[rel="modulepreload"]', "href", href)) return;
|
|
946
|
-
const link = document.createElement("link");
|
|
947
|
-
link.rel = "modulepreload";
|
|
948
|
-
link.href = href;
|
|
949
|
-
document.head.appendChild(link);
|
|
950
|
-
}
|
|
951
|
-
function applyInlineStyles(inlineStyles) {
|
|
952
|
-
for (const entry of inlineStyles) {
|
|
953
|
-
if (findHeadElement("style[data-asset]", "data-asset", entry.id)) continue;
|
|
954
|
-
const el = document.createElement("style");
|
|
955
|
-
el.setAttribute("data-asset", entry.id);
|
|
956
|
-
if (entry.attrs) {
|
|
957
|
-
for (const name in entry.attrs) el.setAttribute(name, entry.attrs[name]);
|
|
958
|
-
}
|
|
959
|
-
el.textContent = entry.content || "";
|
|
960
|
-
document.head.appendChild(el);
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
908
|
function isPlaceholderStart(node, id) {
|
|
964
909
|
return node.tagName === "TEMPLATE" && node.id === id;
|
|
965
910
|
}
|
|
@@ -971,20 +916,6 @@ function rangeClose(start, id) {
|
|
|
971
916
|
}
|
|
972
917
|
return null;
|
|
973
918
|
}
|
|
974
|
-
function findLiveTarget(n, end, test) {
|
|
975
|
-
while (n && n !== end) {
|
|
976
|
-
if (n.nodeType === ELEMENT_NODE) {
|
|
977
|
-
const fid = isFrameElement(n) ? n.getAttribute(FRAME_ID_ATTR) : null;
|
|
978
|
-
if (fid === null || fid.includes(".")) {
|
|
979
|
-
if (test(n)) return n;
|
|
980
|
-
const found = findLiveTarget(n.firstChild, null, test);
|
|
981
|
-
if (found) return found;
|
|
982
|
-
}
|
|
983
|
-
} else if (test(n)) return n;
|
|
984
|
-
n = n.nextSibling;
|
|
985
|
-
}
|
|
986
|
-
return null;
|
|
987
|
-
}
|
|
988
919
|
function findPlaceholder(n, end, id) {
|
|
989
920
|
while (n && n !== end) {
|
|
990
921
|
if (isPlaceholderStart(n, id)) return n;
|
|
@@ -996,41 +927,27 @@ function findPlaceholder(n, end, id) {
|
|
|
996
927
|
}
|
|
997
928
|
return null;
|
|
998
929
|
}
|
|
999
|
-
function collectSlots(
|
|
1000
|
-
|
|
930
|
+
function collectSlots(root, out) {
|
|
931
|
+
const w = root.ownerDocument.createTreeWalker(root, 0x80);
|
|
932
|
+
let n, p;
|
|
933
|
+
while (n = w.nextNode()) {
|
|
934
|
+
if (!n.data.startsWith("slot:")) continue;
|
|
1001
935
|
const id = slotStartId(n);
|
|
1002
|
-
if (id
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
936
|
+
if (!id) continue;
|
|
937
|
+
for (p = n.parentNode; p !== root; p = p.parentNode) if (p.hasAttribute(FRAME_ID_ATTR)) break;
|
|
938
|
+
if (p !== root) continue;
|
|
939
|
+
if (!out.has(id)) out.set(id, n);
|
|
940
|
+
const end = findMarker(n, slotEnd(id));
|
|
941
|
+
if (end) {
|
|
942
|
+
w.currentNode = end;
|
|
1006
943
|
continue;
|
|
1007
944
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
if (node.nodeType !== ELEMENT_NODE) return;
|
|
1014
|
-
if (isFrameElement(node)) {
|
|
1015
|
-
const childId = node.getAttribute(FRAME_ID_ATTR);
|
|
1016
|
-
if (childId && childId.includes(".")) {
|
|
1017
|
-
const argKey = childId.slice(childId.lastIndexOf(".") + 1);
|
|
1018
|
-
if (!regions.has(argKey)) {
|
|
1019
|
-
regions.set(argKey, {
|
|
1020
|
-
childId,
|
|
1021
|
-
element: node,
|
|
1022
|
-
frame: undefined,
|
|
1023
|
-
adopt: true
|
|
1024
|
-
});
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
return;
|
|
945
|
+
devReportRange(id);
|
|
946
|
+
p = n.parentNode;
|
|
947
|
+
if (p === root) return;
|
|
948
|
+
while (p.lastChild) p = p.lastChild;
|
|
949
|
+
w.currentNode = p;
|
|
1028
950
|
}
|
|
1029
|
-
for (let c = node.firstChild; c; c = c.nextSibling) collectRegionElements(c, regions);
|
|
1030
|
-
}
|
|
1031
|
-
function renameRegion(entry, childId) {
|
|
1032
|
-
entry.childId = childId;
|
|
1033
|
-
if (entry.frame) entry.frame.rebind(childId);else entry.element.setAttribute(FRAME_ID_ATTR, childId);
|
|
1034
951
|
}
|
|
1035
952
|
function eachInRange(start, key, cb) {
|
|
1036
953
|
const end = slotEnd(key);
|
|
@@ -1042,286 +959,203 @@ function eachInRange(start, key, cb) {
|
|
|
1042
959
|
}
|
|
1043
960
|
return n;
|
|
1044
961
|
}
|
|
1045
|
-
function clearStreamRecords(records, root) {
|
|
1046
|
-
for (const key in records) {
|
|
1047
|
-
if (/^(seg|hole|attr):/.test(key) || key === ":error" || root && key === "") {
|
|
1048
|
-
delete records[key];
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
function argsEquivalent(a, b) {
|
|
1053
|
-
if (a === b) return true;
|
|
1054
|
-
if (!a || !b) return false;
|
|
1055
|
-
const ka = Object.keys(a);
|
|
1056
|
-
const kb = Object.keys(b);
|
|
1057
|
-
if (ka.length !== kb.length) return false;
|
|
1058
|
-
for (const key of ka) {
|
|
1059
|
-
const va = a[key];
|
|
1060
|
-
const vb = b[key];
|
|
1061
|
-
if (va === vb) continue;
|
|
1062
|
-
if (isFrameRef(va) && va.$frame === vb?.$frame) continue;
|
|
1063
|
-
return false;
|
|
1064
|
-
}
|
|
1065
|
-
return true;
|
|
1066
|
-
}
|
|
1067
962
|
function slotStartId(node) {
|
|
1068
963
|
if (node.nodeType !== COMMENT_NODE) return null;
|
|
1069
964
|
const m = SLOT_START.exec(node.data);
|
|
1070
965
|
return m ? m[1] : null;
|
|
1071
966
|
}
|
|
1072
|
-
function
|
|
1073
|
-
if (node.nodeType !== COMMENT_NODE) return false;
|
|
1074
|
-
const data = node.data;
|
|
1075
|
-
return SLOT_START.test(data) || SLOT_END.test(data);
|
|
1076
|
-
}
|
|
1077
|
-
function compatible(a, b) {
|
|
1078
|
-
if (a.nodeType !== b.nodeType) return false;
|
|
1079
|
-
if (a.nodeType === ELEMENT_NODE) return a.nodeName === b.nodeName && a.getAttribute("_key") === b.getAttribute("_key");
|
|
1080
|
-
return a.nodeType === TEXT_NODE || a.nodeType === COMMENT_NODE;
|
|
1081
|
-
}
|
|
1082
|
-
function preservesOpen(el) {
|
|
1083
|
-
const t = el.tagName;
|
|
1084
|
-
return t === "DETAILS" || t === "DIALOG";
|
|
1085
|
-
}
|
|
1086
|
-
function morphAttributes(oldEl, newEl, claim) {
|
|
1087
|
-
let reclaim = false;
|
|
1088
|
-
let changed = false;
|
|
1089
|
-
const keepOpen = preservesOpen(oldEl);
|
|
1090
|
-
const oldAttrs = oldEl.attributes;
|
|
1091
|
-
for (let i = oldAttrs.length - 1; i >= 0; i--) {
|
|
1092
|
-
const name = oldAttrs[i].name;
|
|
1093
|
-
if (keepOpen && name === "open") continue;
|
|
1094
|
-
if (!newEl.hasAttribute(name)) {
|
|
1095
|
-
oldEl.removeAttribute(name);
|
|
1096
|
-
changed = true;
|
|
1097
|
-
reclaim ||= claimedAttr(name);
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
const newAttrs = newEl.attributes;
|
|
1101
|
-
for (let i = 0; i < newAttrs.length; i++) {
|
|
1102
|
-
const attr = newAttrs[i];
|
|
1103
|
-
if (keepOpen && attr.name === "open") continue;
|
|
1104
|
-
if (oldEl.getAttribute(attr.name) !== attr.value) {
|
|
1105
|
-
oldEl.setAttribute(attr.name, attr.value);
|
|
1106
|
-
changed = true;
|
|
1107
|
-
reclaim ||= claimedAttr(attr.name);
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
if (claim && (reclaim || changed && oldEl.matches(CLAIMED_ELEMENTS))) claim(oldEl, true);
|
|
1111
|
-
}
|
|
1112
|
-
function morphNode(oldNode, newNode, claim, ranges, grafts) {
|
|
1113
|
-
if (oldNode.nodeType === ELEMENT_NODE) {
|
|
1114
|
-
if (oldNode.hasAttribute("data-preserve")) return;
|
|
1115
|
-
morphAttributes(oldNode, newNode, claim);
|
|
1116
|
-
reconcileChildren(oldNode, newNode, null, null, claim, ranges, grafts);
|
|
1117
|
-
} else if (oldNode.data !== newNode.data) {
|
|
1118
|
-
oldNode.data = newNode.data;
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
function afterRange(start, id) {
|
|
1122
|
-
const end = slotEnd(id);
|
|
967
|
+
function findMarker(start, end) {
|
|
1123
968
|
let n = start.nextSibling;
|
|
1124
969
|
while (n) {
|
|
1125
|
-
if (n.nodeType === COMMENT_NODE && n.data === end) return n
|
|
970
|
+
if (n.nodeType === COMMENT_NODE && n.data === end) return n;
|
|
1126
971
|
n = n.nextSibling;
|
|
1127
972
|
}
|
|
1128
973
|
return null;
|
|
1129
974
|
}
|
|
1130
|
-
function
|
|
975
|
+
function devReportRange(id) {
|
|
1131
976
|
const end = slotEnd(id);
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
while (n && n !== bound) {
|
|
1143
|
-
if (n.nodeType === COMMENT_NODE && n.data === target) return n;
|
|
1144
|
-
n = n.nextSibling;
|
|
1145
|
-
}
|
|
1146
|
-
return null;
|
|
1147
|
-
}
|
|
1148
|
-
function moveRangeBefore(parent, start, id, ref) {
|
|
1149
|
-
const end = slotEnd(id);
|
|
1150
|
-
let n = start;
|
|
1151
|
-
while (n) {
|
|
1152
|
-
const next = n.nextSibling;
|
|
1153
|
-
const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
|
|
1154
|
-
parent.insertBefore(n, ref);
|
|
1155
|
-
if (isEnd) break;
|
|
1156
|
-
n = next;
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
function placeRange(parent, range, id, ref) {
|
|
1160
|
-
if (range.nodeType === 11 ) {
|
|
1161
|
-
parent.insertBefore(range, ref);
|
|
1162
|
-
} else {
|
|
1163
|
-
moveRangeBefore(parent, range, id, ref);
|
|
1164
|
-
}
|
|
977
|
+
DEV.report(OBSERVE.diagnostics.emit({
|
|
978
|
+
code: "FRAME_MARKER_CORRUPTED",
|
|
979
|
+
kind: "ssr",
|
|
980
|
+
severity: "error",
|
|
981
|
+
message: `[FRAME_MARKER_CORRUPTED] Frame slot range "${id}" is missing its end marker (<!--${end}-->) among its start ` + `marker's siblings. Slots after it in this content cannot be discovered. Likely causes: ` + `invalid HTML nesting split the range during parsing (e.g. a block element inside <p>), ` + `or an HTML-rewriting layer (CDN/minifier/translator) removed or moved the comment — ` + `serve frame documents with Cache-Control: no-transform.`,
|
|
982
|
+
data: {
|
|
983
|
+
slot: id,
|
|
984
|
+
end
|
|
985
|
+
}
|
|
986
|
+
}, null));
|
|
1165
987
|
}
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
if (
|
|
1176
|
-
|
|
988
|
+
|
|
989
|
+
const RECORDS = Symbol.for("@solidjs/signals/observe/records");
|
|
990
|
+
function records() {
|
|
991
|
+
return globalThis[RECORDS];
|
|
992
|
+
}
|
|
993
|
+
function frameRecordCensus(event, message, own) {
|
|
994
|
+
const r = message.r;
|
|
995
|
+
let counted = !r;
|
|
996
|
+
for (const key in r) {
|
|
997
|
+
if (key === ":complete" || key === ":bound") continue;
|
|
998
|
+
counted = true;
|
|
999
|
+
countEvent(event, key === "" ? "html" : key.endsWith(":error") ? "error" : key.startsWith("slot:") ? "slot" : key.startsWith("seg:") && r[key] && r[key].kind === "html" ? "fragment" : key, own);
|
|
1000
|
+
}
|
|
1001
|
+
if (counted) event.chunks++;
|
|
1002
|
+
}
|
|
1003
|
+
function countEvent(event, type, own) {
|
|
1004
|
+
switch (type) {
|
|
1005
|
+
case "html":
|
|
1006
|
+
if (!own) event.regions++;else if (event.shellMs === undefined) event.shellMs = performance.now() - event.at;
|
|
1007
|
+
break;
|
|
1008
|
+
case "fragment":
|
|
1009
|
+
event.fragments++;
|
|
1010
|
+
break;
|
|
1011
|
+
case "slot":
|
|
1012
|
+
event.slots++;
|
|
1013
|
+
break;
|
|
1014
|
+
case "error":
|
|
1015
|
+
event.errors++;
|
|
1177
1016
|
break;
|
|
1178
|
-
}
|
|
1179
|
-
n = next;
|
|
1180
|
-
}
|
|
1181
|
-
return after;
|
|
1182
|
-
}
|
|
1183
|
-
function reconcileChildren(parent, source, boundStart = null, boundEnd = null, claim = null, ranges = null, grafts = null) {
|
|
1184
|
-
let oldChild = boundStart ? boundStart.nextSibling : parent.firstChild;
|
|
1185
|
-
let newChild = source.firstChild;
|
|
1186
|
-
while (newChild) {
|
|
1187
|
-
const nextNew = newChild.nextSibling;
|
|
1188
|
-
const pid = slotStartId(newChild);
|
|
1189
|
-
const old = oldChild === boundEnd ? null : oldChild;
|
|
1190
|
-
if (pid !== null) {
|
|
1191
|
-
if (old && slotStartId(old) === pid) {
|
|
1192
|
-
oldChild = afterRange(old, pid);
|
|
1193
|
-
newChild = afterRange(newChild, pid);
|
|
1194
|
-
} else {
|
|
1195
|
-
const displaced = ranges && ranges.get(pid);
|
|
1196
|
-
const existing = displaced || findRangeStart(old, pid, boundEnd);
|
|
1197
|
-
if (existing) {
|
|
1198
|
-
if (ranges) ranges.delete(pid);
|
|
1199
|
-
placeRange(parent, existing, pid, old ?? boundEnd);
|
|
1200
|
-
newChild = afterRange(newChild, pid);
|
|
1201
|
-
} else {
|
|
1202
|
-
newChild = adoptRange(parent, newChild, pid, old ?? boundEnd, claim);
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
continue;
|
|
1206
|
-
}
|
|
1207
|
-
if (!old) {
|
|
1208
|
-
parent.insertBefore(newChild, boundEnd);
|
|
1209
|
-
if (claim) claim(newChild);
|
|
1210
|
-
if (grafts) grafts.push(newChild);
|
|
1211
|
-
newChild = nextNew;
|
|
1212
|
-
continue;
|
|
1213
|
-
}
|
|
1214
|
-
if (isSlotMarker(old)) {
|
|
1215
|
-
parent.insertBefore(newChild, old);
|
|
1216
|
-
if (claim) claim(newChild);
|
|
1217
|
-
if (grafts) grafts.push(newChild);
|
|
1218
|
-
newChild = nextNew;
|
|
1219
|
-
continue;
|
|
1220
|
-
}
|
|
1221
|
-
if (compatible(old, newChild)) {
|
|
1222
|
-
morphNode(old, newChild, claim, ranges, grafts);
|
|
1223
|
-
oldChild = old.nextSibling;
|
|
1224
|
-
newChild = nextNew;
|
|
1225
|
-
continue;
|
|
1226
|
-
}
|
|
1227
|
-
if (newChild.nodeType === 1) {
|
|
1228
|
-
let ahead = old.nextSibling;
|
|
1229
|
-
while (ahead && ahead !== boundEnd && !compatible(ahead, newChild)) {
|
|
1230
|
-
const aheadPid = slotStartId(ahead);
|
|
1231
|
-
ahead = aheadPid !== null ? afterRange(ahead, aheadPid) : ahead.nextSibling;
|
|
1232
|
-
}
|
|
1233
|
-
if (ahead && ahead !== boundEnd) {
|
|
1234
|
-
parent.insertBefore(ahead, old);
|
|
1235
|
-
morphNode(ahead, newChild, claim, ranges, grafts);
|
|
1236
|
-
newChild = nextNew;
|
|
1237
|
-
continue;
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
parent.insertBefore(newChild, old);
|
|
1241
|
-
if (claim) claim(newChild);
|
|
1242
|
-
if (grafts) grafts.push(newChild);
|
|
1243
|
-
newChild = nextNew;
|
|
1244
|
-
}
|
|
1245
|
-
while (oldChild && oldChild !== boundEnd) {
|
|
1246
|
-
const next = oldChild.nextSibling;
|
|
1247
|
-
const pid = ranges ? slotStartId(oldChild) : null;
|
|
1248
|
-
if (pid !== null && ranges.get(pid) === oldChild) {
|
|
1249
|
-
const frag = document.createDocumentFragment();
|
|
1250
|
-
const after = stashRange(frag, oldChild, pid);
|
|
1251
|
-
ranges.set(pid, frag);
|
|
1252
|
-
oldChild = after;
|
|
1253
|
-
continue;
|
|
1254
|
-
}
|
|
1255
|
-
parent.removeChild(oldChild);
|
|
1256
|
-
oldChild = next;
|
|
1257
1017
|
}
|
|
1258
1018
|
}
|
|
1259
|
-
function
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1019
|
+
function observeFrameApply(response) {
|
|
1020
|
+
const channel = records();
|
|
1021
|
+
if (channel === undefined || !channel.observed("frame")) return undefined;
|
|
1022
|
+
let current;
|
|
1023
|
+
const close = (outcome, error) => {
|
|
1024
|
+
const open = current;
|
|
1025
|
+
current = undefined;
|
|
1026
|
+
open.event.durationMs = performance.now() - open.event.at;
|
|
1027
|
+
open.event.outcome = outcome;
|
|
1028
|
+
const live = {
|
|
1029
|
+
response
|
|
1030
|
+
};
|
|
1031
|
+
if (error !== undefined) live.error = error;
|
|
1032
|
+
channel.emit("frame", open.event, live);
|
|
1033
|
+
};
|
|
1034
|
+
return {
|
|
1035
|
+
chunk(chunk, wireId) {
|
|
1036
|
+
if (chunk.type === "start") {
|
|
1037
|
+
if (current !== undefined) close("truncated");
|
|
1038
|
+
const event = {
|
|
1039
|
+
side: "client",
|
|
1040
|
+
id: wireId,
|
|
1041
|
+
version: chunk.version,
|
|
1042
|
+
at: performance.now(),
|
|
1043
|
+
durationMs: 0,
|
|
1044
|
+
outcome: "complete",
|
|
1045
|
+
chunks: 0,
|
|
1046
|
+
fragments: 0,
|
|
1047
|
+
slots: 0,
|
|
1048
|
+
regions: 0,
|
|
1049
|
+
errors: 0
|
|
1050
|
+
};
|
|
1051
|
+
if (chunk.id !== wireId) event.address = chunk.id;
|
|
1052
|
+
current = {
|
|
1053
|
+
event,
|
|
1054
|
+
applied: chunk.id
|
|
1055
|
+
};
|
|
1056
|
+
return;
|
|
1271
1057
|
}
|
|
1272
|
-
|
|
1273
|
-
|
|
1058
|
+
if (current === undefined) return;
|
|
1059
|
+
frameRecordCensus(current.event, chunk, chunk.id === current.applied);
|
|
1060
|
+
if (chunk.r && ":complete" in chunk.r && chunk.id === current.applied) close("complete");
|
|
1061
|
+
},
|
|
1062
|
+
end(error) {
|
|
1063
|
+
if (current !== undefined) close(error !== undefined ? "error" : "truncated", error);
|
|
1274
1064
|
}
|
|
1275
|
-
|
|
1276
|
-
n = n.nextSibling;
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
function stashRange(frag, start, id) {
|
|
1280
|
-
const end = slotEnd(id);
|
|
1281
|
-
let n = start;
|
|
1282
|
-
while (n) {
|
|
1283
|
-
const next = n.nextSibling;
|
|
1284
|
-
const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
|
|
1285
|
-
frag.appendChild(n);
|
|
1286
|
-
if (isEnd) return next;
|
|
1287
|
-
n = next;
|
|
1288
|
-
}
|
|
1289
|
-
return null;
|
|
1065
|
+
};
|
|
1290
1066
|
}
|
|
1291
1067
|
|
|
1292
1068
|
const FRAME_STREAM_HEADER = "X-Frame-Stream";
|
|
1069
|
+
const FRAME_TIERS_HEADER = "X-Frame-Tiers";
|
|
1293
1070
|
function isFrameStreamResponse(response) {
|
|
1294
1071
|
return response.headers.has(FRAME_STREAM_HEADER);
|
|
1295
1072
|
}
|
|
1296
|
-
|
|
1073
|
+
const applyFrameResponse = observedApplyFrameResponse ;
|
|
1074
|
+
async function observedApplyFrameResponse(response, host, options = {}) {
|
|
1075
|
+
const observation = observeFrameApply(response);
|
|
1076
|
+
if (!observation) return applyFrames(response, host, options);
|
|
1077
|
+
let applied;
|
|
1078
|
+
try {
|
|
1079
|
+
applied = await applyFrames(response, host, options, observation);
|
|
1080
|
+
} catch (error) {
|
|
1081
|
+
observation.end(error);
|
|
1082
|
+
throw error;
|
|
1083
|
+
}
|
|
1084
|
+
observation.end();
|
|
1085
|
+
return applied;
|
|
1086
|
+
}
|
|
1087
|
+
const ends = msg => !!msg.r && (":complete" in msg.r || ":error" in msg.r);
|
|
1088
|
+
const readsData = msg => {
|
|
1089
|
+
for (const key in msg.r) if (key.startsWith("slot:")) for (const v of Object.values(msg.r[key].args)) if (v && v.$ref) return true;
|
|
1090
|
+
return false;
|
|
1091
|
+
};
|
|
1092
|
+
function applyFrames(response, host, options = {}, observation) {
|
|
1297
1093
|
const rootId = response.headers.get(FRAME_STREAM_HEADER) ?? "";
|
|
1094
|
+
response.headers.get(FRAME_TIERS_HEADER)?.split(",").forEach(prepareTier);
|
|
1298
1095
|
const as = options.as;
|
|
1299
1096
|
const version = options.version;
|
|
1300
1097
|
const perFrame = typeof version === "function" ? new Map() : null;
|
|
1301
|
-
const reader = new ChunkReader(response.body);
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
let v = perFrame.get(chunk.id);
|
|
1311
|
-
if (v === undefined) perFrame.set(chunk.id, v = version(chunk.id));
|
|
1312
|
-
chunk.version = v;
|
|
1313
|
-
} else if (version !== undefined) chunk.version = version;
|
|
1314
|
-
if (chunk.type === "data" && host.prepareData) await host.prepareData();
|
|
1315
|
-
host.apply(chunk);
|
|
1098
|
+
const reader = options[LIVE_WIRE] || new ChunkReader(response.body);
|
|
1099
|
+
const open = new Map();
|
|
1100
|
+
const errorRecord = (id, error) => ({
|
|
1101
|
+
id,
|
|
1102
|
+
version: open.get(id),
|
|
1103
|
+
r: {
|
|
1104
|
+
":error": {
|
|
1105
|
+
message: String(error && error.message)
|
|
1106
|
+
}
|
|
1316
1107
|
}
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1108
|
+
});
|
|
1109
|
+
const drain = async () => {
|
|
1110
|
+
let result = await reader.next();
|
|
1111
|
+
while (!result.done) {
|
|
1112
|
+
const chunk = JSON.parse(result.value);
|
|
1113
|
+
if (chunk.type === "outcome") {
|
|
1114
|
+
if (options.onOutcome) options.onOutcome(chunk.payload);
|
|
1115
|
+
} else {
|
|
1116
|
+
const wireId = chunk.id;
|
|
1117
|
+
if (as !== undefined && chunk.id === rootId) chunk.id = as;
|
|
1118
|
+
if (perFrame) {
|
|
1119
|
+
let v = perFrame.get(chunk.id);
|
|
1120
|
+
if (v === undefined) perFrame.set(chunk.id, v = version(chunk.id));
|
|
1121
|
+
chunk.version = v;
|
|
1122
|
+
} else if (version !== undefined) chunk.version = version;
|
|
1123
|
+
if (chunk.type === "start") open.set(chunk.id, chunk.version);else if (ends(chunk)) open.delete(chunk.id);
|
|
1124
|
+
if (observation) observation.chunk(chunk, wireId);
|
|
1125
|
+
const needs = chunk.tiers?.map(prepareTier) || [];
|
|
1126
|
+
if (chunk.type === "data" || readsData(chunk)) await Promise.all([host.prepareData?.(), ...needs]);
|
|
1127
|
+
host.apply(chunk);
|
|
1128
|
+
}
|
|
1129
|
+
result = await reader.next();
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
1132
|
+
const end = error => {
|
|
1133
|
+
if (error === undefined) for (const id of open.keys()) host.apply(errorRecord(id, new Error("Frame stream ended before the frame completed.")));
|
|
1134
|
+
};
|
|
1135
|
+
return drain().then(() => {
|
|
1136
|
+
end(undefined);
|
|
1137
|
+
return as !== undefined ? as : rootId;
|
|
1138
|
+
}, error => {
|
|
1139
|
+
end(error);
|
|
1140
|
+
throw error;
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
const SERVER_COMPONENT = /*#__PURE__*/Symbol.for("solid.server-component");
|
|
1144
|
+
const SERVER_COMPONENT_ADDRESS = /*#__PURE__*/Symbol.for("solid.server-component-address");
|
|
1145
|
+
const COMPONENT_BINDING = /*#__PURE__*/Symbol.for("solid.component-binding");
|
|
1146
|
+
const CONTENT_TOKEN = "\u0000";
|
|
1147
|
+
function contentAddress(token) {
|
|
1148
|
+
return token.split(CONTENT_TOKEN)[0];
|
|
1320
1149
|
}
|
|
1321
|
-
const
|
|
1322
|
-
|
|
1323
|
-
|
|
1150
|
+
const stagedContent = {
|
|
1151
|
+
preview() {},
|
|
1152
|
+
commit() {}
|
|
1153
|
+
};
|
|
1324
1154
|
let resolveServerComponent;
|
|
1155
|
+
const calls = new Map();
|
|
1156
|
+
function callFor(address) {
|
|
1157
|
+
return calls.get(address);
|
|
1158
|
+
}
|
|
1325
1159
|
function parseServerComponent(value, ctx) {
|
|
1326
1160
|
return {
|
|
1327
1161
|
id: ctx.parse(value[SERVER_COMPONENT]),
|
|
@@ -1329,7 +1163,7 @@ function parseServerComponent(value, ctx) {
|
|
|
1329
1163
|
};
|
|
1330
1164
|
}
|
|
1331
1165
|
const ServerComponentPlugin = {
|
|
1332
|
-
tag: "
|
|
1166
|
+
tag: "solid/server-component",
|
|
1333
1167
|
test(value) {
|
|
1334
1168
|
return typeof value === "function" && SERVER_COMPONENT in value;
|
|
1335
1169
|
},
|
|
@@ -1367,10 +1201,7 @@ function flightCodec(codec) {
|
|
|
1367
1201
|
function createServerComponentHandler({
|
|
1368
1202
|
host,
|
|
1369
1203
|
component,
|
|
1370
|
-
|
|
1371
|
-
intercept,
|
|
1372
|
-
consumer = getFlightDataConsumer,
|
|
1373
|
-
codec = getServerFunctionsCodec
|
|
1204
|
+
intercept
|
|
1374
1205
|
}) {
|
|
1375
1206
|
const byFn = new Map();
|
|
1376
1207
|
const componentFor = fnId => {
|
|
@@ -1392,19 +1223,79 @@ function createServerComponentHandler({
|
|
|
1392
1223
|
}
|
|
1393
1224
|
return binding;
|
|
1394
1225
|
};
|
|
1395
|
-
|
|
1226
|
+
const staged = new Map();
|
|
1227
|
+
const latest = new Map();
|
|
1228
|
+
const stage = (address, base, version) => {
|
|
1229
|
+
if (!base) return undefined;
|
|
1230
|
+
let committed = false;
|
|
1231
|
+
const chunks = [];
|
|
1232
|
+
const token = address + CONTENT_TOKEN + version;
|
|
1233
|
+
const entry = {
|
|
1234
|
+
token,
|
|
1235
|
+
prepareData: host.prepareData,
|
|
1236
|
+
apply(chunk) {
|
|
1237
|
+
if (committed || chunk.type === "data") host.apply(chunk);else chunks.push(chunk);
|
|
1238
|
+
},
|
|
1239
|
+
preview() {
|
|
1240
|
+
if (host.preview) for (const chunk of chunks) host.preview(chunk);
|
|
1241
|
+
},
|
|
1242
|
+
commit() {
|
|
1243
|
+
committed = true;
|
|
1244
|
+
staged.delete(address);
|
|
1245
|
+
for (const chunk of chunks) host.apply(chunk);
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
staged.set(address, entry);
|
|
1249
|
+
const comp = base[COMPONENT_BINDING].component;
|
|
1250
|
+
const binding = props => comp(props, () => token);
|
|
1251
|
+
binding[COMPONENT_BINDING] = {
|
|
1252
|
+
component: comp,
|
|
1253
|
+
address: token
|
|
1254
|
+
};
|
|
1255
|
+
latest.set(address, binding);
|
|
1256
|
+
return entry;
|
|
1257
|
+
};
|
|
1258
|
+
const settled = (address, binding) => latest.get(address) || binding;
|
|
1259
|
+
const showing = address => {
|
|
1260
|
+
const frame = host.get(address);
|
|
1261
|
+
return frame !== undefined && frame.error === undefined;
|
|
1262
|
+
};
|
|
1263
|
+
const named = (token, half) => {
|
|
1264
|
+
const entry = staged.get(contentAddress(token));
|
|
1265
|
+
if (entry && entry.token === token) entry[half]();
|
|
1266
|
+
};
|
|
1267
|
+
stagedContent.preview = token => named(token, "preview");
|
|
1268
|
+
stagedContent.commit = token => named(token, "commit");
|
|
1269
|
+
resolveServerComponent = (id, address) => settled(address, bindingFor(address, id));
|
|
1396
1270
|
const versions = new Map();
|
|
1397
1271
|
const bump = address => {
|
|
1398
1272
|
const version = (versions.get(address) || 0) + 1;
|
|
1399
1273
|
versions.set(address, version);
|
|
1274
|
+
staged.delete(address);
|
|
1275
|
+
tierLoads.wire?.r?.cancel(host, address);
|
|
1400
1276
|
return version;
|
|
1401
1277
|
};
|
|
1278
|
+
const begin = (address, version) => host.apply({
|
|
1279
|
+
type: "start",
|
|
1280
|
+
id: address,
|
|
1281
|
+
version
|
|
1282
|
+
});
|
|
1402
1283
|
return {
|
|
1403
1284
|
intercept: intercept && (info => {
|
|
1404
1285
|
const hit = intercept(info);
|
|
1405
|
-
if (hit === undefined) return
|
|
1406
|
-
|
|
1286
|
+
if (hit === undefined) return void prepareMorph();
|
|
1287
|
+
const address = frameAddress(info.id, info.args);
|
|
1288
|
+
if (!info.meta?.live) calls.set(address, info);
|
|
1289
|
+
const binding = () => bindingFor(address, info.id);
|
|
1290
|
+
if (typeof hit.then === "function") return hit.then(landed => landed ? binding() : undefined);
|
|
1291
|
+
return binding();
|
|
1407
1292
|
}),
|
|
1293
|
+
onLive() {
|
|
1294
|
+
prepareTier("wire");
|
|
1295
|
+
},
|
|
1296
|
+
resume(info) {
|
|
1297
|
+
return tierLoads.wire?.r?.resume(host, info, versions);
|
|
1298
|
+
},
|
|
1408
1299
|
handle(response, ctx) {
|
|
1409
1300
|
if (!isFrameStreamResponse(response)) return undefined;
|
|
1410
1301
|
const address = frameAddress(ctx.id, ctx.args);
|
|
@@ -1412,30 +1303,34 @@ function createServerComponentHandler({
|
|
|
1412
1303
|
if (response.headers.has(SINGLE_FLIGHT_HEADER)) {
|
|
1413
1304
|
return applyFlightResponse(response, address, binding);
|
|
1414
1305
|
}
|
|
1306
|
+
const wire = ctx[LIVE_WIRE];
|
|
1307
|
+
if (wire) return prepareTier("wire").then(() => tierLoads.wire.r.connect(response, wire, address, binding, host, bump, begin));
|
|
1308
|
+
calls.set(address, ctx);
|
|
1415
1309
|
const version = bump(address);
|
|
1416
|
-
|
|
1417
|
-
|
|
1310
|
+
const entry = showing(address) ? stage(address, binding, version) : undefined;
|
|
1311
|
+
if (!entry) host.apply({
|
|
1312
|
+
type: "start",
|
|
1313
|
+
id: address,
|
|
1314
|
+
version,
|
|
1315
|
+
startedAt: ctx.startedAt
|
|
1316
|
+
}) ;
|
|
1317
|
+
const target = entry || host;
|
|
1318
|
+
const applied = applyFrameResponse(response, target, {
|
|
1418
1319
|
as: address,
|
|
1419
|
-
version
|
|
1420
|
-
}).catch(err =>
|
|
1421
|
-
type: "error",
|
|
1320
|
+
version: frameId => frameId === address ? version : bump(frameId)
|
|
1321
|
+
}).catch(err => target.apply({
|
|
1422
1322
|
id: address,
|
|
1423
1323
|
version,
|
|
1424
|
-
|
|
1425
|
-
|
|
1324
|
+
r: {
|
|
1325
|
+
":error": {
|
|
1326
|
+
message: String(err && err.message)
|
|
1327
|
+
}
|
|
1426
1328
|
}
|
|
1427
1329
|
}));
|
|
1428
|
-
return binding;
|
|
1330
|
+
return entry ? applied.then(() => settled(address, binding)) : binding;
|
|
1429
1331
|
},
|
|
1430
1332
|
showing(address, functionId) {
|
|
1431
1333
|
bindingFor(address, functionId);
|
|
1432
|
-
const comp = componentFor(functionId);
|
|
1433
|
-
if (comp && (typeof comp === "function" || typeof comp === "object") && !comp[COMPONENT_BINDING]) {
|
|
1434
|
-
comp[COMPONENT_BINDING] = {
|
|
1435
|
-
component: comp,
|
|
1436
|
-
address
|
|
1437
|
-
};
|
|
1438
|
-
}
|
|
1439
1334
|
}
|
|
1440
1335
|
};
|
|
1441
1336
|
async function applyFlightResponse(response, address, binding) {
|
|
@@ -1447,13 +1342,28 @@ function createServerComponentHandler({
|
|
|
1447
1342
|
feed = controller;
|
|
1448
1343
|
}
|
|
1449
1344
|
});
|
|
1450
|
-
const payload = deserializeStream(new Response(source), flightCodec(
|
|
1345
|
+
const payload = deserializeStream(new Response(source), flightCodec(getServerFunctionsCodec()));
|
|
1451
1346
|
let carried = false;
|
|
1452
|
-
|
|
1347
|
+
const regions = new Map();
|
|
1348
|
+
const regionOf = id => {
|
|
1349
|
+
for (const [root, entry] of regions) if (id === root || id.startsWith(root + ".")) return entry;
|
|
1350
|
+
};
|
|
1351
|
+
const target = {
|
|
1352
|
+
apply: chunk => {
|
|
1353
|
+
const entry = regionOf(chunk.id);
|
|
1354
|
+
if (entry) entry.apply(chunk);else host.apply(chunk);
|
|
1355
|
+
},
|
|
1356
|
+
prepareData: host.prepareData
|
|
1357
|
+
};
|
|
1358
|
+
await applyFrameResponse(response, target, {
|
|
1453
1359
|
as,
|
|
1454
1360
|
version: frameId => {
|
|
1455
1361
|
const version = bump(frameId);
|
|
1456
|
-
|
|
1362
|
+
let entry = regionOf(frameId);
|
|
1363
|
+
if (!entry && showing(frameId)) {
|
|
1364
|
+
entry = stage(frameId, frameId === as ? binding : byAddress.get(frameId), version);
|
|
1365
|
+
if (entry) regions.set(frameId, entry);
|
|
1366
|
+
}
|
|
1457
1367
|
return version;
|
|
1458
1368
|
},
|
|
1459
1369
|
onOutcome: text => {
|
|
@@ -1464,54 +1374,19 @@ function createServerComponentHandler({
|
|
|
1464
1374
|
feed.close();
|
|
1465
1375
|
if (!carried) throw new Error("Single-flight frame response carried no outcome");
|
|
1466
1376
|
const envelope = await payload;
|
|
1467
|
-
|
|
1468
|
-
if (
|
|
1469
|
-
response
|
|
1470
|
-
});
|
|
1471
|
-
if (response.headers.has(ERROR_HEADER) && !response.headers.has("Location") && !response.headers.has(REVALIDATE_HEADER)) {
|
|
1377
|
+
await deliverFlightData(response, envelope.data);
|
|
1378
|
+
if (response.headers.has(ERROR_HEADER) && !hasFlightMetadata(response)) {
|
|
1472
1379
|
throw envelope.value;
|
|
1473
1380
|
}
|
|
1474
|
-
return rootId ? binding : envelope.value;
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
|
|
1478
|
-
const STATE = Symbol.for("dom-expressions.container-trace-state");
|
|
1479
|
-
const state = globalThis[STATE] || (globalThis[STATE] = {
|
|
1480
|
-
materialized: new WeakMap(),
|
|
1481
|
-
materializedValues: new WeakSet()
|
|
1482
|
-
});
|
|
1483
|
-
function setContainerTraceMaterializer(fn) {
|
|
1484
|
-
state.materializeTrace = fn;
|
|
1485
|
-
}
|
|
1486
|
-
function materialize(marker) {
|
|
1487
|
-
let value = state.materialized.get(marker.$tr);
|
|
1488
|
-
if (value === undefined) {
|
|
1489
|
-
value = state.materializeTrace(marker);
|
|
1490
|
-
state.materialized.set(marker.$tr, value);
|
|
1491
|
-
if (value !== null && typeof value === "object") state.materializedValues.add(value);
|
|
1381
|
+
return rootId ? settled(address, binding) : envelope.value;
|
|
1492
1382
|
}
|
|
1493
|
-
return value;
|
|
1494
|
-
}
|
|
1495
|
-
function isMaterializedContainer(value) {
|
|
1496
|
-
return value !== null && typeof value === "object" && state.materializedValues.has(value);
|
|
1497
|
-
}
|
|
1498
|
-
function isContainerTraceMarker(value) {
|
|
1499
|
-
if (value == null || typeof value !== "object" || value.$tr == null) return false;
|
|
1500
|
-
const tr = value.$tr;
|
|
1501
|
-
return tr.__SEROVAL_STREAM__ === true || typeof tr[Symbol.asyncIterator] === "function";
|
|
1502
|
-
}
|
|
1503
|
-
function reviveContainerTraces(value) {
|
|
1504
|
-
if (!state.materializeTrace || value == null || typeof value !== "object") return value;
|
|
1505
|
-
if (isContainerTraceMarker(value)) return materialize(value);
|
|
1506
|
-
if (Array.isArray(value)) {
|
|
1507
|
-
for (let i = 0; i < value.length; i++) value[i] = reviveContainerTraces(value[i]);
|
|
1508
|
-
} else if (Object.getPrototypeOf(value) === Object.prototype) {
|
|
1509
|
-
for (const key of Object.keys(value)) value[key] = reviveContainerTraces(value[key]);
|
|
1510
|
-
}
|
|
1511
|
-
return value;
|
|
1512
1383
|
}
|
|
1513
1384
|
|
|
1514
|
-
|
|
1385
|
+
const TRACE_STATE = Symbol.for("solid.container-trace-state");
|
|
1386
|
+
tierLoaders.trace = () => import('@solidjs/web/frames/trace');
|
|
1387
|
+
tierLoaders.regions = () => import('@solidjs/web/frames/regions');
|
|
1388
|
+
tierLoaders.assets = () => import('@solidjs/web/frames/assets');
|
|
1389
|
+
tierLoaders.wire = () => import('@solidjs/web/frames/wire');
|
|
1515
1390
|
function asyncArg(value) {
|
|
1516
1391
|
return value;
|
|
1517
1392
|
}
|
|
@@ -1524,117 +1399,146 @@ function loadCodec() {
|
|
|
1524
1399
|
});
|
|
1525
1400
|
}
|
|
1526
1401
|
const tables = new Map();
|
|
1527
|
-
function
|
|
1528
|
-
let
|
|
1529
|
-
if (!
|
|
1530
|
-
|
|
1402
|
+
function tableFor(id, version, current) {
|
|
1403
|
+
let byVersion = tables.get(id);
|
|
1404
|
+
if (!byVersion) tables.set(id, byVersion = new Map());else for (const v of byVersion.keys()) if (v < current) byVersion.delete(v);
|
|
1405
|
+
let t = byVersion.get(version);
|
|
1406
|
+
if (!t && codec) byVersion.set(version, t = codec.createJSONDataTable());
|
|
1407
|
+
return t;
|
|
1408
|
+
}
|
|
1409
|
+
function followAddress(host, frame, binding) {
|
|
1410
|
+
createRenderEffect(() => {
|
|
1411
|
+
const token = binding();
|
|
1412
|
+
stagedContent.preview(token);
|
|
1413
|
+
return token;
|
|
1414
|
+
}, token => {
|
|
1415
|
+
stagedContent.commit(token);
|
|
1416
|
+
frame.rebind(contentAddress(token));
|
|
1417
|
+
});
|
|
1531
1418
|
}
|
|
1532
|
-
function
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1419
|
+
function landing(host, address, value, failed) {
|
|
1420
|
+
let frame, thrown;
|
|
1421
|
+
const errored = () => (frame = host.get(address))?.error !== undefined && (thrown === (thrown = frame.version) ? 1 : 2);
|
|
1422
|
+
errored();
|
|
1423
|
+
return createMemo(() => {
|
|
1424
|
+
failed();
|
|
1425
|
+
const state = errored();
|
|
1426
|
+
if (state > 1) throw frame.error;
|
|
1427
|
+
const wait = host.landing(address);
|
|
1428
|
+
if (!wait) return value;
|
|
1429
|
+
const landed = (state ? reask(address, wait) : wait).then(() => value);
|
|
1430
|
+
if (!state) {
|
|
1431
|
+
const origin = OBSERVE.attribution.flightOrigin(wait);
|
|
1432
|
+
if (origin !== undefined) OBSERVE.attribution.markFlight(landed, origin);
|
|
1433
|
+
}
|
|
1434
|
+
return landed;
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
function reask(address, wait) {
|
|
1438
|
+
const call = callFor(address);
|
|
1439
|
+
if (!call) console.error(`Server component boundary "${address}" errored, but no call is recorded for it; ` + `reset() cannot re-ask the server. (The address was written by hand, not by a call.)`);
|
|
1440
|
+
return call ? call.retry().then(() => wait) : wait;
|
|
1536
1441
|
}
|
|
1537
|
-
function
|
|
1538
|
-
|
|
1442
|
+
function failing() {
|
|
1443
|
+
const [failed, setFailed] = createSignal(0, {
|
|
1444
|
+
ownedWrite: true
|
|
1445
|
+
});
|
|
1446
|
+
return [failed, info => info.reason === "error" && setFailed(n => n + 1)];
|
|
1539
1447
|
}
|
|
1540
1448
|
function getFrameHost() {
|
|
1541
1449
|
if (!sharedHost) {
|
|
1542
1450
|
sharedHost = createFrameHost({
|
|
1543
1451
|
prepareData: loadCodec,
|
|
1544
|
-
applyData: c => tableFor(c.id)?.apply(c),
|
|
1545
|
-
resolve: (ref, id) => tableFor(id)?.resolve(ref),
|
|
1546
|
-
|
|
1547
|
-
isContainer: isMaterializedContainer,
|
|
1548
|
-
delegate: delegateEvents
|
|
1452
|
+
applyData: (c, current) => tableFor(c.id, c.version, current)?.apply(c),
|
|
1453
|
+
resolve: (ref, id, version, current) => tableFor(id, version, current)?.resolve(ref),
|
|
1454
|
+
closeData: (id, version, error) => tables.get(id)?.get(version)?.close(error)
|
|
1549
1455
|
});
|
|
1550
1456
|
}
|
|
1551
1457
|
return sharedHost;
|
|
1552
1458
|
}
|
|
1553
|
-
function
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1459
|
+
function claimScope(el) {
|
|
1460
|
+
const registry = sharedConfig.registry;
|
|
1461
|
+
const buckets = new Map();
|
|
1462
|
+
const bucketOf = key => key.slice(0, key.lastIndexOf("-") + 1);
|
|
1463
|
+
const index = root => {
|
|
1464
|
+
if (registry) for (const n of root.querySelectorAll("[_hk]")) {
|
|
1465
|
+
const p = bucketOf(n.getAttribute("_hk"));
|
|
1466
|
+
const b = buckets.get(p);
|
|
1467
|
+
b ? b.push(n) : buckets.set(p, [n]);
|
|
1560
1468
|
}
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
if (n.nodeType !== 1) continue;
|
|
1574
|
-
const el = n;
|
|
1575
|
-
if (el.tagName === "TEMPLATE" && el.id.startsWith("pl-")) return true;
|
|
1576
|
-
if (el.querySelector?.('template[id^="pl-"]')) return true;
|
|
1577
|
-
}
|
|
1578
|
-
return false;
|
|
1469
|
+
};
|
|
1470
|
+
index(el);
|
|
1471
|
+
return {
|
|
1472
|
+
registry,
|
|
1473
|
+
gather(id) {
|
|
1474
|
+
for (const n of buckets.get(bucketOf(id)) || []) {
|
|
1475
|
+
const k = n.getAttribute("_hk");
|
|
1476
|
+
if (k.startsWith(id) && n.isConnected && !registry.has(k)) registry.set(k, n);
|
|
1477
|
+
}
|
|
1478
|
+
},
|
|
1479
|
+
index
|
|
1480
|
+
};
|
|
1579
1481
|
}
|
|
1580
|
-
function claimRender(prefix, existing, render) {
|
|
1482
|
+
function claimRender(prefix, owner, existing, render, scope, bound) {
|
|
1581
1483
|
const sc = sharedConfig;
|
|
1582
|
-
if (!sc.
|
|
1583
|
-
const
|
|
1584
|
-
for (const n of existing) {
|
|
1585
|
-
if (n.nodeType !== 1) continue;
|
|
1586
|
-
gatherClaims(n, registry);
|
|
1587
|
-
}
|
|
1588
|
-
if (!registry.size && !hasPendingFragment(existing)) return render();
|
|
1589
|
-
const prevRegistry = sc.registry;
|
|
1590
|
-
const prevHydrating = sc.hydrating;
|
|
1591
|
-
const prevClaimRoots = sc.claimRoots;
|
|
1592
|
-
if (prevRegistry) for (const key of registry.keys()) prevRegistry.delete(key);
|
|
1593
|
-
sc.registry = registry;
|
|
1594
|
-
sc.hydrating = true;
|
|
1484
|
+
if (!sc.hydrateWindow || !sc.registry) return runWithOwner(owner, render);
|
|
1485
|
+
const prevRoots = sc.claimRoots;
|
|
1595
1486
|
sc.claimRoots = existing;
|
|
1596
1487
|
try {
|
|
1597
|
-
return runWithOwner(
|
|
1598
|
-
id: prefix
|
|
1599
|
-
}), render);
|
|
1488
|
+
return runWithOwner(owner, () => sc.hydrateWindow(bound ? undefined : prefix, render, scope));
|
|
1600
1489
|
} finally {
|
|
1601
|
-
sc.
|
|
1602
|
-
sc.hydrating = prevHydrating;
|
|
1603
|
-
sc.claimRoots = prevClaimRoots;
|
|
1490
|
+
sc.claimRoots = prevRoots;
|
|
1604
1491
|
}
|
|
1605
1492
|
}
|
|
1606
1493
|
function liveSlotProps(initial, ctx) {
|
|
1607
|
-
const [args, setArgs] = createSignal(initial
|
|
1494
|
+
const [args, setArgs] = createSignal(initial, {
|
|
1495
|
+
ownedWrite: true
|
|
1496
|
+
});
|
|
1608
1497
|
ctx.onUpdate(next => setArgs(() => next));
|
|
1609
1498
|
return slotArgsProxy(args);
|
|
1610
1499
|
}
|
|
1611
|
-
function
|
|
1612
|
-
|
|
1500
|
+
function sameArg(a, b) {
|
|
1501
|
+
if (a === b) return true;
|
|
1502
|
+
if (!a || !b || typeof a !== "object" || typeof b !== "object") return false;
|
|
1503
|
+
if (a instanceof Boxed || b instanceof Boxed) return a instanceof Boxed && b instanceof Boxed && a.c === b.c;
|
|
1504
|
+
if (isAsyncValue(a) || isAsyncValue(b) || a instanceof Node || b instanceof Node) return false;
|
|
1505
|
+
try {
|
|
1506
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
1507
|
+
} catch {
|
|
1508
|
+
return false;
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
class Boxed {
|
|
1512
|
+
constructor(c) {
|
|
1513
|
+
this.c = c;
|
|
1514
|
+
}
|
|
1613
1515
|
}
|
|
1614
1516
|
function slotArgsProxy(args) {
|
|
1615
1517
|
const owner = getOwner();
|
|
1616
|
-
const
|
|
1518
|
+
const reads = new Map();
|
|
1617
1519
|
return new Proxy({}, {
|
|
1618
1520
|
get: (_, key) => {
|
|
1619
|
-
|
|
1620
|
-
if (isMaterializedContainer(v)) return v;
|
|
1621
|
-
if (!isAsyncValue(v)) return v;
|
|
1622
|
-
let read = asyncReads.get(key);
|
|
1521
|
+
let read = reads.get(key);
|
|
1623
1522
|
if (!read) {
|
|
1624
1523
|
const make = () => createMemo(() => {
|
|
1625
1524
|
const raw = args()[key];
|
|
1525
|
+
if (globalThis[TRACE_STATE]?.materializedValues.has(raw)) return new Boxed(raw);
|
|
1626
1526
|
if (raw != null && typeof raw.then === "function") {
|
|
1627
1527
|
if (raw.s === 1) return raw.v;
|
|
1628
1528
|
if (raw.s === 2) throw raw.v;
|
|
1629
1529
|
}
|
|
1630
1530
|
return raw;
|
|
1631
1531
|
}, {
|
|
1632
|
-
transparent: true
|
|
1633
|
-
|
|
1532
|
+
transparent: true,
|
|
1533
|
+
equals: sameArg,
|
|
1534
|
+
_supersedes: true
|
|
1535
|
+
} );
|
|
1634
1536
|
read = owner ? runWithOwner(owner, make) : make();
|
|
1635
|
-
|
|
1537
|
+
reads.set(key, read);
|
|
1636
1538
|
}
|
|
1637
|
-
|
|
1539
|
+
const v = read();
|
|
1540
|
+
if (v instanceof Element) tierLoads.regions.r.place(v);
|
|
1541
|
+
return v instanceof Boxed ? v.c : v;
|
|
1638
1542
|
},
|
|
1639
1543
|
has: (_, key) => key in args(),
|
|
1640
1544
|
ownKeys: () => Reflect.ownKeys(args()),
|
|
@@ -1644,75 +1548,51 @@ function slotArgsProxy(args) {
|
|
|
1644
1548
|
} : undefined
|
|
1645
1549
|
});
|
|
1646
1550
|
}
|
|
1647
|
-
function
|
|
1648
|
-
if (typeof value === "function") return true;
|
|
1649
|
-
if (Array.isArray(value)) {
|
|
1650
|
-
for (const v of value) if (isReactiveContent(v)) return true;
|
|
1651
|
-
}
|
|
1652
|
-
return false;
|
|
1653
|
-
}
|
|
1654
|
-
function slotsFor(props) {
|
|
1655
|
-
const bindings = new Map();
|
|
1551
|
+
function slotsFor(props, scope) {
|
|
1656
1552
|
const fillScopes = new Map();
|
|
1657
1553
|
return new Proxy({}, {
|
|
1658
1554
|
get(_, prop) {
|
|
1659
1555
|
if (typeof prop !== "string" || !(prop in props)) return undefined;
|
|
1660
|
-
|
|
1556
|
+
const mount = (slotProps, ctx) => {
|
|
1661
1557
|
const key = ctx && ctx.key;
|
|
1662
|
-
const prev = key !== undefined && bindings.get(key);
|
|
1663
|
-
if (prev) {
|
|
1664
|
-
bindings.delete(key);
|
|
1665
|
-
prev.dispose();
|
|
1666
|
-
}
|
|
1667
1558
|
const prevFill = key !== undefined && fillScopes.get(key);
|
|
1668
1559
|
if (prevFill) {
|
|
1669
1560
|
fillScopes.delete(key);
|
|
1670
1561
|
prevFill.dispose();
|
|
1671
1562
|
}
|
|
1563
|
+
const range = ctx && ctx.range;
|
|
1564
|
+
if (!range) return undefined;
|
|
1672
1565
|
const fillOwner = streamInvoke ? createOwner() : null;
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
const existing = ctx && ctx.existing || [];
|
|
1682
|
-
if (existing.length) {
|
|
1683
|
-
const list = Array.isArray(out) ? out : [out];
|
|
1684
|
-
const inPlace = list.every(n => existing.some(e => e === n || e.nodeType === 1 && e.contains(n)));
|
|
1685
|
-
if (inPlace) return undefined;
|
|
1686
|
-
}
|
|
1687
|
-
return out;
|
|
1688
|
-
};
|
|
1566
|
+
const owner = fillOwner || createOwner({
|
|
1567
|
+
transparent: true
|
|
1568
|
+
});
|
|
1569
|
+
fillScopes.set(key, owner);
|
|
1570
|
+
ctx.onCleanup(() => {
|
|
1571
|
+
if (fillScopes.get(key) === owner) fillScopes.delete(key);
|
|
1572
|
+
owner.dispose();
|
|
1573
|
+
});
|
|
1689
1574
|
const evaluate = () => {
|
|
1690
1575
|
const v = props[prop];
|
|
1691
1576
|
if (typeof v === "function" && ctx && ctx.invoked) {
|
|
1692
|
-
|
|
1577
|
+
const fillProps = ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotArgsProxy(() => slotProps);
|
|
1578
|
+
return untrack(() => v(fillProps), `the \`${prop}\` template-slot fill` );
|
|
1693
1579
|
}
|
|
1694
1580
|
return v;
|
|
1695
1581
|
};
|
|
1696
1582
|
const adopted = !!(ctx && ctx.frame && ctx.adopted && ctx.existing && ctx.existing.length);
|
|
1697
1583
|
const prefix = ctx && ctx.frame ? `sc-${ctx.frame}-${ctx.key}-` : "";
|
|
1698
|
-
const
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
const end = ctx.range.end;
|
|
1711
|
-
const bind = () => insert(end.parentNode, () => typeof source === "function" ? source() : source, end, [...ctx.existing]);
|
|
1712
|
-
runWithOwner(owner, () => adopted ? claimRender(prefix, ctx.existing, bind) : bind());
|
|
1713
|
-
return undefined;
|
|
1714
|
-
}
|
|
1715
|
-
return settle(normalizeSlotContent(value));
|
|
1584
|
+
const claim = adopted && runWithOwner(owner, () => createOwner({
|
|
1585
|
+
id: prefix
|
|
1586
|
+
}));
|
|
1587
|
+
const value = adopted ? claimRender(prefix, claim, ctx.existing, evaluate, scope) : fillOwner ? runWithOwner(fillOwner, evaluate) : evaluate();
|
|
1588
|
+
const end = range.end;
|
|
1589
|
+
const bind = () => insert(end.parentNode, value, end, [...ctx.existing]);
|
|
1590
|
+
adopted ? claimRender(prefix, claim, ctx.existing, bind, scope, true) : runWithOwner(owner, bind);
|
|
1591
|
+
return undefined;
|
|
1592
|
+
};
|
|
1593
|
+
return (slotProps, ctx) => {
|
|
1594
|
+
const R = tierLoads.regions?.r;
|
|
1595
|
+
R ? R.nest(mount, slotProps, ctx) : mount(slotProps, ctx);
|
|
1716
1596
|
};
|
|
1717
1597
|
}
|
|
1718
1598
|
});
|
|
@@ -1735,12 +1615,8 @@ function boundaryScope(owner) {
|
|
|
1735
1615
|
function boundaryComponent(host, fnId) {
|
|
1736
1616
|
return (props, binding) => {
|
|
1737
1617
|
const owner = getOwner();
|
|
1738
|
-
const id = binding ? binding() : fnId;
|
|
1739
|
-
|
|
1740
|
-
let release;
|
|
1741
|
-
const arm = () => new Promise(r => release = r);
|
|
1742
|
-
const mountGate = applied ? undefined : arm();
|
|
1743
|
-
let setGate;
|
|
1618
|
+
const id = binding ? contentAddress(binding()) : fnId;
|
|
1619
|
+
const [failed, onApply] = failing();
|
|
1744
1620
|
const {
|
|
1745
1621
|
element,
|
|
1746
1622
|
frame,
|
|
@@ -1749,33 +1625,14 @@ function boundaryComponent(host, fnId) {
|
|
|
1749
1625
|
host,
|
|
1750
1626
|
id,
|
|
1751
1627
|
slots: slotsFor(props),
|
|
1752
|
-
props,
|
|
1753
1628
|
ownerScope: boundaryScope(owner),
|
|
1754
1629
|
reveal: revealSeam(owner),
|
|
1755
|
-
onApply
|
|
1756
|
-
applied = true;
|
|
1757
|
-
if (release) {
|
|
1758
|
-
release();
|
|
1759
|
-
release = undefined;
|
|
1760
|
-
}
|
|
1761
|
-
setGate && setGate(undefined);
|
|
1762
|
-
}
|
|
1630
|
+
onApply
|
|
1763
1631
|
});
|
|
1764
|
-
const [gatePromise, setGatePromise] = createSignal(applied ? undefined : mountGate);
|
|
1765
|
-
setGate = setGatePromise;
|
|
1766
|
-
if (binding) {
|
|
1767
|
-
createRenderEffect(binding, (address, prev) => {
|
|
1768
|
-
if (prev !== undefined && address !== prev && tables.has(address)) {
|
|
1769
|
-
applied = false;
|
|
1770
|
-
setGatePromise(arm());
|
|
1771
|
-
}
|
|
1772
|
-
frame.rebind(address);
|
|
1773
|
-
});
|
|
1774
|
-
}
|
|
1775
1632
|
onCleanup(dispose);
|
|
1776
|
-
if (
|
|
1777
|
-
|
|
1778
|
-
return createMemo(() => (
|
|
1633
|
+
if (!binding) return landing(host, id, element, failed);
|
|
1634
|
+
followAddress(host, frame, binding);
|
|
1635
|
+
return createMemo(() => landing(host, contentAddress(binding()), element, failed));
|
|
1779
1636
|
};
|
|
1780
1637
|
}
|
|
1781
1638
|
const claimedBoundaries = new Set();
|
|
@@ -1790,7 +1647,12 @@ function pumpLiveChannel() {
|
|
|
1790
1647
|
const pump = () => reader.read().then(r => {
|
|
1791
1648
|
if (r.done) return;
|
|
1792
1649
|
const op = r.value;
|
|
1793
|
-
liveOps.set(`${op.
|
|
1650
|
+
for (const key in op.r) liveOps.set(`${op.fid || ""}:${key}`, {
|
|
1651
|
+
fid: op.fid,
|
|
1652
|
+
r: {
|
|
1653
|
+
[key]: op.r[key]
|
|
1654
|
+
}
|
|
1655
|
+
});
|
|
1794
1656
|
for (const apply of liveAppliers) apply(op);
|
|
1795
1657
|
return pump();
|
|
1796
1658
|
});
|
|
@@ -1800,202 +1662,438 @@ function pumpLiveChannel() {
|
|
|
1800
1662
|
let boundaryIndex = null;
|
|
1801
1663
|
const isBoundaryId = id => !id.includes(".");
|
|
1802
1664
|
function indexBoundaries(root) {
|
|
1803
|
-
root.querySelectorAll(
|
|
1665
|
+
root.querySelectorAll(FRAME_SELECTOR).forEach(el => {
|
|
1804
1666
|
const key = el.getAttribute(FRAME_ID_ATTR);
|
|
1805
1667
|
if (key && isBoundaryId(key) && !boundaryIndex.has(key)) boundaryIndex.set(key, el);
|
|
1806
1668
|
});
|
|
1807
1669
|
}
|
|
1808
|
-
function findBoundaryElement(id) {
|
|
1670
|
+
function findBoundaryElement(id, address) {
|
|
1809
1671
|
if (!boundaryIndex) {
|
|
1810
1672
|
boundaryIndex = new Map();
|
|
1811
1673
|
if (typeof document !== "undefined" && document.body) indexBoundaries(document.body);
|
|
1812
1674
|
}
|
|
1813
|
-
|
|
1675
|
+
const args = address && address.slice(id.length + 1);
|
|
1676
|
+
let first, el;
|
|
1677
|
+
for (let n = 0;; n++) {
|
|
1678
|
+
const key = n ? id + "~" + (n + 1) : id;
|
|
1679
|
+
if (claimedBoundaries.has(key)) continue;
|
|
1680
|
+
if (!(el = boundaryIndex.get(key)) || !args || el.dataset.fa == args) return el || first;
|
|
1681
|
+
first = first || el;
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
const arrivals = new Map();
|
|
1685
|
+
const FRAME_SELECTOR = `[${FRAME_ID_ATTR}]`;
|
|
1686
|
+
const disposedFrames = new WeakSet();
|
|
1687
|
+
function awaitBoundary(id) {
|
|
1688
|
+
let arrival = arrivals.get(id);
|
|
1689
|
+
if (!arrival) {
|
|
1690
|
+
let resolve;
|
|
1691
|
+
const promise = new Promise(r => resolve = r);
|
|
1692
|
+
if (!resolve) return promise;
|
|
1693
|
+
arrivals.set(id, arrival = {
|
|
1694
|
+
promise,
|
|
1695
|
+
resolve
|
|
1696
|
+
});
|
|
1697
|
+
onHydrationEnd(releaseArrivals);
|
|
1698
|
+
}
|
|
1699
|
+
return arrival.promise;
|
|
1700
|
+
}
|
|
1701
|
+
function releaseArrivals() {
|
|
1702
|
+
if (!arrivals.size) return;
|
|
1703
|
+
const exhausted = !boundaryMayArrive();
|
|
1704
|
+
for (const [id, arrival] of arrivals) {
|
|
1705
|
+
const el = boundaryIndex && boundaryIndex.get(id);
|
|
1706
|
+
if (!el && !exhausted) continue;
|
|
1707
|
+
arrivals.delete(id);
|
|
1708
|
+
arrival.resolve(!!el);
|
|
1709
|
+
}
|
|
1814
1710
|
}
|
|
1815
|
-
const boundaryWaiters = new Map();
|
|
1816
1711
|
function boundaryMayArrive() {
|
|
1817
1712
|
const hy = globalThis._$HY;
|
|
1818
1713
|
if (!hy) return false;
|
|
1819
|
-
return !hy.done || !!(hy.fr && hy.fr.pending());
|
|
1714
|
+
return !(hy.done || sharedConfig.done) || !!(hy.fr && hy.fr.pending());
|
|
1820
1715
|
}
|
|
1821
1716
|
function installRevealHook() {
|
|
1717
|
+
installServerComponentHydration();
|
|
1822
1718
|
const hy = globalThis._$HY;
|
|
1823
1719
|
if (!hy || hy.$sc || !hy.fr) return;
|
|
1824
1720
|
hy.$sc = true;
|
|
1721
|
+
hy.fa = pl => {
|
|
1722
|
+
const el = pl.closest(FRAME_SELECTOR);
|
|
1723
|
+
return !!el && !disposedFrames.has(el);
|
|
1724
|
+
};
|
|
1825
1725
|
hy.fr.subscribe((_id, parent) => {
|
|
1826
1726
|
if (!boundaryIndex) return;
|
|
1827
1727
|
const root = parent || (typeof document !== "undefined" ? document.body : null);
|
|
1828
1728
|
if (root) indexBoundaries(root);
|
|
1829
|
-
|
|
1830
|
-
const exhausted = hy.done && !hy.fr.pending();
|
|
1831
|
-
for (const [id, notify] of boundaryWaiters) {
|
|
1832
|
-
const el = boundaryIndex && boundaryIndex.get(id);
|
|
1833
|
-
if (!el && !exhausted) continue;
|
|
1834
|
-
boundaryWaiters.delete(id);
|
|
1835
|
-
notify(el);
|
|
1836
|
-
}
|
|
1729
|
+
releaseArrivals();
|
|
1837
1730
|
});
|
|
1838
1731
|
}
|
|
1839
1732
|
function documentBoundary(host, id, props, binding) {
|
|
1840
1733
|
installRevealHook();
|
|
1841
|
-
const
|
|
1842
|
-
const el =
|
|
1734
|
+
const address = binding && contentAddress(binding());
|
|
1735
|
+
const el = findBoundaryElement(id, address);
|
|
1843
1736
|
if (el) return adoptBoundary(host, id, el, props, binding);
|
|
1844
|
-
if (!
|
|
1737
|
+
if (!claimedBoundaries.has(id) && boundaryMayArrive()) {
|
|
1845
1738
|
const owner = getOwner();
|
|
1846
|
-
|
|
1847
|
-
onCleanup(() =>
|
|
1848
|
-
return createMemo(() =>
|
|
1849
|
-
|
|
1739
|
+
let live = true;
|
|
1740
|
+
onCleanup(() => live = false);
|
|
1741
|
+
return createMemo(() => awaitBoundary(id).then(() => live && runWithOwner(owner, () => {
|
|
1742
|
+
const node = findBoundaryElement(id, address);
|
|
1743
|
+
return node ? adoptBoundary(host, id, node, props, binding) : boundaryComponent(host, id)(props, binding);
|
|
1744
|
+
})));
|
|
1850
1745
|
}
|
|
1851
1746
|
return boundaryComponent(host, id)(props, binding);
|
|
1852
1747
|
}
|
|
1853
|
-
function documentAddress(id) {
|
|
1854
|
-
const records = globalThis._$SC?.a;
|
|
1855
|
-
if (records) {
|
|
1856
|
-
for (const address in records) if (records[address] === id) return address;
|
|
1857
|
-
}
|
|
1858
|
-
return id;
|
|
1859
|
-
}
|
|
1860
1748
|
function adoptBoundary(host, id, el, props, binding) {
|
|
1861
|
-
|
|
1862
|
-
|
|
1749
|
+
const siteId = el.getAttribute(FRAME_ID_ATTR);
|
|
1750
|
+
claimedBoundaries.add(siteId);
|
|
1751
|
+
edgeRoots.set(siteId, el);
|
|
1752
|
+
const address = binding ? contentAddress(binding()) : id;
|
|
1863
1753
|
const appliedRecords = new Set();
|
|
1864
|
-
const
|
|
1865
|
-
const
|
|
1866
|
-
const
|
|
1867
|
-
if (!
|
|
1754
|
+
const reportedFragments = new Set();
|
|
1755
|
+
const reportRegionFragments = root => {
|
|
1756
|
+
const hy = globalThis._$HY;
|
|
1757
|
+
if (!hy || !hy.r) return;
|
|
1868
1758
|
root.querySelectorAll('template[id^="pl-"]').forEach(tpl => {
|
|
1869
1759
|
const fragId = tpl.id.slice(3);
|
|
1870
|
-
if (
|
|
1871
|
-
|
|
1872
|
-
|
|
1760
|
+
if (reportedFragments.has(fragId)) return;
|
|
1761
|
+
reportedFragments.add(fragId);
|
|
1762
|
+
const ref = hy.r[fragId + "_fr"];
|
|
1763
|
+
ref && typeof ref.then === "function" && ref.then(undefined, error => console.error(`Server <Loading> fragment "${fragId}" inside server component "${id}" rejected on ` + `the server; the frame shows what the server rendered for that outcome.`, error));
|
|
1873
1764
|
});
|
|
1874
1765
|
};
|
|
1875
1766
|
const drainRecords = () => {
|
|
1876
1767
|
const hy = globalThis._$HY;
|
|
1877
1768
|
if (!hy || !hy.r) return;
|
|
1878
1769
|
pumpLiveChannel();
|
|
1879
|
-
const slotPrefix = `sc:slot:${
|
|
1770
|
+
const slotPrefix = `sc:slot:${siteId}:`;
|
|
1880
1771
|
for (const key of Object.keys(hy.r)) {
|
|
1881
1772
|
if (appliedRecords.has(key)) continue;
|
|
1882
1773
|
if (key.startsWith(slotPrefix)) {
|
|
1883
1774
|
appliedRecords.add(key);
|
|
1884
|
-
host.apply({
|
|
1885
|
-
type: "slot",
|
|
1775
|
+
const apply = args => host.apply({
|
|
1886
1776
|
id: address,
|
|
1887
1777
|
version: 0,
|
|
1888
|
-
|
|
1889
|
-
|
|
1778
|
+
r: {
|
|
1779
|
+
[`slot:${key.slice(slotPrefix.length)}`]: {
|
|
1780
|
+
kind: "slot",
|
|
1781
|
+
args
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1890
1784
|
});
|
|
1785
|
+
const value = hy.r[key];
|
|
1786
|
+
if (value && typeof value.then === "function") {
|
|
1787
|
+
if (value.s === 1) apply(value.v);else if (value.s === 2) value.then(undefined, () => {});else value.then(apply, () => {});
|
|
1788
|
+
} else apply(value);
|
|
1891
1789
|
} else if (key.startsWith("sc:region:")) {
|
|
1892
1790
|
const childId = key.slice("sc:region:".length);
|
|
1893
|
-
if (childId.startsWith(
|
|
1791
|
+
if (childId.startsWith(siteId + ".")) {
|
|
1894
1792
|
appliedRecords.add(key);
|
|
1895
1793
|
const val = hy.r[key];
|
|
1896
1794
|
const apply = html => host.apply({
|
|
1897
|
-
type: "html",
|
|
1898
1795
|
id: childId,
|
|
1899
1796
|
version: 0,
|
|
1900
|
-
|
|
1797
|
+
r: {
|
|
1798
|
+
"": {
|
|
1799
|
+
kind: "html",
|
|
1800
|
+
value: html
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1901
1803
|
});
|
|
1902
1804
|
val && typeof val.then === "function" ? val.then(apply) : apply(val);
|
|
1903
1805
|
}
|
|
1904
1806
|
}
|
|
1905
1807
|
}
|
|
1906
1808
|
};
|
|
1907
|
-
|
|
1809
|
+
reportRegionFragments(el);
|
|
1810
|
+
const scope = claimScope(el);
|
|
1908
1811
|
const fr = globalThis._$HY?.fr;
|
|
1812
|
+
let frame;
|
|
1909
1813
|
const unsubscribe = fr ? fr.subscribe((_fragId, parent) => {
|
|
1910
|
-
|
|
1814
|
+
const inside = !!parent && el.contains(parent);
|
|
1815
|
+
inside && scope.index(parent);
|
|
1816
|
+
inside && reportRegionFragments(parent);
|
|
1911
1817
|
drainRecords();
|
|
1818
|
+
if (inside && frame) frame.apply({
|
|
1819
|
+
version: frame.version ?? 0,
|
|
1820
|
+
r: {}
|
|
1821
|
+
});
|
|
1912
1822
|
}) : undefined;
|
|
1913
1823
|
const applyLiveOp = op => {
|
|
1914
|
-
if (op.
|
|
1824
|
+
if (op.fid && op.fid !== siteId) return;
|
|
1915
1825
|
host.apply({
|
|
1916
|
-
...op,
|
|
1917
1826
|
id: address,
|
|
1918
|
-
version: 0
|
|
1827
|
+
version: 0,
|
|
1828
|
+
r: op.r
|
|
1919
1829
|
});
|
|
1920
1830
|
};
|
|
1921
1831
|
liveAppliers.add(applyLiveOp);
|
|
1922
1832
|
onCleanup(() => {
|
|
1923
1833
|
liveAppliers.delete(applyLiveOp);
|
|
1924
1834
|
unsubscribe && unsubscribe();
|
|
1925
|
-
if (fr && fr.release) for (const fragId of claimedFragments) fr.release(fragId);
|
|
1926
1835
|
});
|
|
1927
1836
|
drainRecords();
|
|
1928
1837
|
for (const op of liveOps.values()) applyLiveOp(op);
|
|
1929
1838
|
const owner = getOwner();
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1839
|
+
const sc = sharedConfig;
|
|
1840
|
+
const [failed, onApply] = failing();
|
|
1841
|
+
frame = createFrame(el, {
|
|
1933
1842
|
adopt: true,
|
|
1843
|
+
defer: true,
|
|
1934
1844
|
host,
|
|
1935
1845
|
id: address,
|
|
1936
|
-
slots: slotsFor(props),
|
|
1937
|
-
props,
|
|
1846
|
+
slots: slotsFor(props, scope),
|
|
1938
1847
|
ownerScope: boundaryScope(owner),
|
|
1939
1848
|
reveal: revealSeam(owner),
|
|
1940
|
-
onApply
|
|
1941
|
-
|
|
1942
|
-
release();
|
|
1943
|
-
release = undefined;
|
|
1944
|
-
}
|
|
1945
|
-
setGate && setGate(undefined);
|
|
1946
|
-
},
|
|
1849
|
+
onApply,
|
|
1850
|
+
hold: () => sc.isHydrationInProgress?.() ? runWithOwner(owner, () => untrack(() => sc.holdBoundary("sc:" + siteId))) : () => {},
|
|
1947
1851
|
...{
|
|
1948
|
-
|
|
1949
|
-
if (document.readyState === "loading") return true;
|
|
1950
|
-
const hy = globalThis._$HY;
|
|
1951
|
-
return !!(hy && hy.fr && hy.fr.pending());
|
|
1952
|
-
},
|
|
1953
|
-
drainRecords,
|
|
1954
|
-
claimScope: id
|
|
1852
|
+
claimScope: siteId
|
|
1955
1853
|
}
|
|
1956
1854
|
});
|
|
1957
1855
|
if (binding) {
|
|
1958
|
-
|
|
1959
|
-
const
|
|
1960
|
-
|
|
1961
|
-
const gate = createMemo(() => gatePromise());
|
|
1962
|
-
createRenderEffect(binding, (address, prev) => {
|
|
1963
|
-
if (prev !== undefined && address !== prev && tables.has(address)) {
|
|
1964
|
-
setGatePromise(arm());
|
|
1965
|
-
}
|
|
1966
|
-
frame.rebind(address);
|
|
1967
|
-
});
|
|
1968
|
-
createRenderEffect(() => (gate(), undefined), () => {});
|
|
1856
|
+
followAddress(host, frame, binding);
|
|
1857
|
+
const source = createMemo(() => landing(host, contentAddress(binding()), true, failed));
|
|
1858
|
+
createRenderEffect(() => source()(), () => {});
|
|
1969
1859
|
}
|
|
1970
|
-
onCleanup(() =>
|
|
1860
|
+
onCleanup(() => {
|
|
1861
|
+
frame.dispose();
|
|
1862
|
+
disposedFrames.add(el);
|
|
1863
|
+
el.querySelectorAll(FRAME_SELECTOR).forEach(e => disposedFrames.add(e));
|
|
1864
|
+
});
|
|
1971
1865
|
return el;
|
|
1972
1866
|
}
|
|
1973
|
-
|
|
1867
|
+
const DEFER_EVENTS = ["click", "input", "change", "keydown", "pointerdown", "submit", "focusin"];
|
|
1868
|
+
const DEFER_BUDGET = 8;
|
|
1869
|
+
let mounting = false;
|
|
1870
|
+
const idleTick = () => new Promise(r => typeof requestIdleCallback === "function" ? requestIdleCallback(() => r(), {
|
|
1871
|
+
timeout: 100
|
|
1872
|
+
}) : setTimeout(r, 0));
|
|
1873
|
+
function wakeAt(e) {
|
|
1874
|
+
const target = e.target;
|
|
1875
|
+
if (!target || mounting) return;
|
|
1876
|
+
mounting = true;
|
|
1877
|
+
try {
|
|
1878
|
+
for (let f; (f = liveFrameAt(target)) && f.mountEnclosing(target););
|
|
1879
|
+
} finally {
|
|
1880
|
+
mounting = false;
|
|
1881
|
+
}
|
|
1882
|
+
deferDone();
|
|
1883
|
+
}
|
|
1884
|
+
function mountAllDeferred() {
|
|
1885
|
+
if (mounting || sharedConfig.hydrating) return;
|
|
1886
|
+
mounting = true;
|
|
1887
|
+
try {
|
|
1888
|
+
for (let frames; (frames = deferredFrames()).length;) for (const f of frames) f.mountDeferred();
|
|
1889
|
+
} finally {
|
|
1890
|
+
mounting = false;
|
|
1891
|
+
}
|
|
1892
|
+
deferDone();
|
|
1893
|
+
}
|
|
1894
|
+
const edgeRoots = new Map();
|
|
1895
|
+
let edgeIndex;
|
|
1896
|
+
const DEPS = "sc:deps:";
|
|
1897
|
+
function buildEdgeIndex() {
|
|
1898
|
+
const r = globalThis._$HY?.r;
|
|
1899
|
+
if (!r) return undefined;
|
|
1900
|
+
const idx = {
|
|
1901
|
+
readers: new Map(),
|
|
1902
|
+
wide: new Set(),
|
|
1903
|
+
untracked: [],
|
|
1904
|
+
sites: new Set(),
|
|
1905
|
+
starts: new Map()
|
|
1906
|
+
};
|
|
1907
|
+
for (const site of edgeRoots.keys()) for (let n = 0, batch; batch = r[DEPS + site + ":" + n]; n++) {
|
|
1908
|
+
if (typeof batch !== "object") return undefined;
|
|
1909
|
+
idx.sites.add(site);
|
|
1910
|
+
for (const sid in batch) {
|
|
1911
|
+
const occs = unpackOccurrences(batch[sid]);
|
|
1912
|
+
if (sid === "*") occs.forEach(w => idx.wide.add(w));else if (sid === "!") occs.forEach(o => idx.untracked.push([site, o]));else {
|
|
1913
|
+
let list = idx.readers.get(sid);
|
|
1914
|
+
if (!list) idx.readers.set(sid, list = []);
|
|
1915
|
+
for (const o of occs) list.push([site, o]);
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
return idx;
|
|
1920
|
+
}
|
|
1921
|
+
function unpackOccurrences(packed) {
|
|
1922
|
+
const out = [];
|
|
1923
|
+
for (const part of packed.split(" ")) {
|
|
1924
|
+
const m = /^(.*)#(\d+)-(\d+)$/.exec(part);
|
|
1925
|
+
if (!m) part && out.push(part);else for (let i = +m[2]; i <= +m[3]; i++) out.push(m[1] + "#" + i);
|
|
1926
|
+
}
|
|
1927
|
+
return out;
|
|
1928
|
+
}
|
|
1929
|
+
function startOf(idx, site, occ) {
|
|
1930
|
+
let m = idx.starts.get(site);
|
|
1931
|
+
if (!m) {
|
|
1932
|
+
idx.starts.set(site, m = new Map());
|
|
1933
|
+
const root = edgeRoots.get(site);
|
|
1934
|
+
if (root) {
|
|
1935
|
+
const w = document.createTreeWalker(root, 128 );
|
|
1936
|
+
for (let c = w.nextNode(); c; c = w.nextNode()) {
|
|
1937
|
+
const d = c.data;
|
|
1938
|
+
if (d.startsWith("slot:") && d.endsWith(":start")) m.set(d.slice(5, -6), c);
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
return m.get(occ);
|
|
1943
|
+
}
|
|
1944
|
+
function edgesCover(idx) {
|
|
1945
|
+
outer: for (const f of deferredFrames()) {
|
|
1946
|
+
for (const [site, root] of edgeRoots) if (idx.sites.has(site) && root.contains(f.el)) continue outer;
|
|
1947
|
+
return false;
|
|
1948
|
+
}
|
|
1949
|
+
return true;
|
|
1950
|
+
}
|
|
1951
|
+
function mountForWrite(node) {
|
|
1952
|
+
if (mounting || sharedConfig.hydrating) return;
|
|
1953
|
+
const sid = signalName(node) ?? storeName(node);
|
|
1954
|
+
if (sid === undefined || document.readyState === "loading") return mountAllDeferred();
|
|
1955
|
+
const idx = edgeIndex ||= buildEdgeIndex();
|
|
1956
|
+
if (!idx || idx.wide.has(sid) || !edgesCover(idx)) return mountAllDeferred();
|
|
1957
|
+
const readers = idx.readers.get(sid);
|
|
1958
|
+
if (!readers && !idx.untracked.length) return;
|
|
1959
|
+
mounting = true;
|
|
1960
|
+
try {
|
|
1961
|
+
for (const list of [readers || [], idx.untracked]) for (const [site, occ] of list) {
|
|
1962
|
+
const root = edgeRoots.get(site);
|
|
1963
|
+
if (root && deferredFrames().some(f => root.contains(f.el) && f.mountOccurrence(occ))) continue;
|
|
1964
|
+
const start = startOf(idx, site, occ);
|
|
1965
|
+
const target = start && (start.nextSibling || start);
|
|
1966
|
+
if (target) for (let f; (f = liveFrameAt(target)) && f.mountEnclosing(target););
|
|
1967
|
+
}
|
|
1968
|
+
} finally {
|
|
1969
|
+
mounting = false;
|
|
1970
|
+
}
|
|
1971
|
+
deferDone();
|
|
1972
|
+
}
|
|
1973
|
+
let driftReads;
|
|
1974
|
+
const driftWarned = new Set();
|
|
1975
|
+
function watchDeferredMount(site, occ, mount) {
|
|
1976
|
+
const reads = new Set();
|
|
1977
|
+
setReadWatch(node => {
|
|
1978
|
+
const sid = signalName(node);
|
|
1979
|
+
if (sid !== undefined) reads.add(sid);
|
|
1980
|
+
});
|
|
1981
|
+
try {
|
|
1982
|
+
mount();
|
|
1983
|
+
} finally {
|
|
1984
|
+
setReadWatch(null);
|
|
1985
|
+
}
|
|
1986
|
+
const idx = edgeIndex ||= buildEdgeIndex();
|
|
1987
|
+
if (!idx || !idx.sites.has(site) || idx.untracked.some(([s, o]) => s === site && o === occ)) return;
|
|
1988
|
+
if (!driftReads) {
|
|
1989
|
+
driftReads = new Map();
|
|
1990
|
+
for (const [sid, list] of idx.readers) for (const [s, o] of list) {
|
|
1991
|
+
const key = s + " " + o;
|
|
1992
|
+
let set = driftReads.get(key);
|
|
1993
|
+
if (!set) driftReads.set(key, set = new Set());
|
|
1994
|
+
set.add(sid);
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
const own = `sc-${site}-${occ}-`;
|
|
1998
|
+
const listed = driftReads.get(site + " " + occ);
|
|
1999
|
+
for (const sid of reads) {
|
|
2000
|
+
if (sid.startsWith(own) || listed?.has(sid) || driftWarned.has(sid)) continue;
|
|
2001
|
+
driftWarned.add(sid);
|
|
2002
|
+
console.warn(`[deferred hydration] The slot occurrence "${occ}" read the signal "${sid}" while mounting, ` + `but the server did not record that read. The client and the server name this signal ` + `differently: a plain signal is created on only one side, under the same component or ` + `owner, before it (code that branches on isServer, or a client-only helper). A write to ` + `it would mount the wrong occurrences. Create such signals after the shared ones, or ` + `under their own owner.`);
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
let idlePass;
|
|
2006
|
+
function mountIdle() {
|
|
2007
|
+
return idlePass ||= (async () => {
|
|
2008
|
+
if (document.readyState !== "complete") await new Promise(r => addEventListener("load", r, {
|
|
2009
|
+
once: true
|
|
2010
|
+
}));
|
|
2011
|
+
globalThis._$HY?.r?.["sc:tiers"]?.forEach(prepareTier);
|
|
2012
|
+
await Promise.all(Object.values(tierLoads)).catch(() => {});
|
|
2013
|
+
for (let frames; (frames = deferredFrames()).length;) {
|
|
2014
|
+
await idleTick();
|
|
2015
|
+
const deadline = performance.now() + DEFER_BUDGET;
|
|
2016
|
+
mounting = true;
|
|
2017
|
+
try {
|
|
2018
|
+
for (const f of frames) if (!f.mountDeferred(deadline) || performance.now() > deadline) break;
|
|
2019
|
+
} finally {
|
|
2020
|
+
mounting = false;
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
idlePass = undefined;
|
|
2024
|
+
deferDone();
|
|
2025
|
+
})();
|
|
2026
|
+
}
|
|
2027
|
+
function deferDone() {
|
|
2028
|
+
if (deferredFrames().length) return;
|
|
2029
|
+
if (deferring) {
|
|
2030
|
+
deferring = false;
|
|
2031
|
+
edgeIndex = driftReads = undefined;
|
|
2032
|
+
setWriteHook(null);
|
|
2033
|
+
DEFER_EVENTS.forEach(t => document.removeEventListener(t, wakeAt, true));
|
|
2034
|
+
}
|
|
2035
|
+
releaseDeferHolds();
|
|
2036
|
+
}
|
|
2037
|
+
let deferHydration = true;
|
|
2038
|
+
function setDeferredHydration(on) {
|
|
2039
|
+
deferHydration = on;
|
|
2040
|
+
setDeferDriver(on && typeof document !== "undefined" ? deferFrame : null);
|
|
2041
|
+
setSignalIdentities(on && typeof document !== "undefined");
|
|
2042
|
+
setDeferMountWatch(on ? watchDeferredMount : null);
|
|
2043
|
+
}
|
|
2044
|
+
let deferring = false;
|
|
2045
|
+
function deferFrame(frame) {
|
|
2046
|
+
if (!deferring) {
|
|
2047
|
+
deferring = true;
|
|
2048
|
+
setWriteHook(mountForWrite);
|
|
2049
|
+
DEFER_EVENTS.forEach(t => document.addEventListener(t, wakeAt, true));
|
|
2050
|
+
}
|
|
2051
|
+
const queued = sharedConfig.events;
|
|
2052
|
+
if (queued && queued.length) for (const [el, e] of queued) if (frame.el.contains(el)) wakeAt({
|
|
2053
|
+
target: e.target ?? el
|
|
2054
|
+
});
|
|
2055
|
+
mountIdle();
|
|
2056
|
+
}
|
|
2057
|
+
function installServerComponents(host = getFrameHost(), options) {
|
|
1974
2058
|
const g = globalThis;
|
|
2059
|
+
Object.assign(tierLoaders, options?.tiers);
|
|
2060
|
+
g._$HY?.r?.["sc:tiers"]?.forEach(prepareTier);
|
|
1975
2061
|
if (!g._$SC) {
|
|
1976
2062
|
g._$SC = {
|
|
1977
2063
|
c: {},
|
|
1978
2064
|
a: {},
|
|
2065
|
+
b: {},
|
|
1979
2066
|
r(i, a) {
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
return g._$SC.
|
|
2067
|
+
const c = g._$SC.c[i] || (g._$SC.c[i] = (p, b) => g._$SC.impl(i, p, b));
|
|
2068
|
+
if (!a) return c;
|
|
2069
|
+
g._$SC.a[a] = i;
|
|
2070
|
+
g._$SC.reg && g._$SC.reg(a, i);
|
|
2071
|
+
return g._$SC.b[a] || (g._$SC.b[a] = Object.assign(p => c(p, () => a), {
|
|
2072
|
+
[COMPONENT_BINDING]: {
|
|
2073
|
+
component: c,
|
|
2074
|
+
address: a
|
|
2075
|
+
}
|
|
2076
|
+
}));
|
|
1985
2077
|
}
|
|
1986
2078
|
};
|
|
1987
2079
|
}
|
|
1988
2080
|
g._$SC.impl = (id, props, binding) => documentBoundary(host, id, props, binding);
|
|
1989
2081
|
installRevealHook();
|
|
2082
|
+
if (typeof document !== "undefined" && deferHydration) {
|
|
2083
|
+
setDeferDriver(deferFrame);
|
|
2084
|
+
setSignalIdentities(true);
|
|
2085
|
+
setDeferMountWatch(watchDeferredMount);
|
|
2086
|
+
}
|
|
1990
2087
|
const handler = createServerComponentHandler({
|
|
1991
2088
|
host,
|
|
1992
2089
|
component: fnId => g._$SC.r(fnId),
|
|
1993
|
-
onStream: address => beginStream(address),
|
|
1994
2090
|
intercept: ({
|
|
1995
2091
|
id
|
|
1996
2092
|
}) => {
|
|
1997
|
-
if (
|
|
1998
|
-
|
|
2093
|
+
if (findBoundaryElement(id)) return true;
|
|
2094
|
+
if (claimedBoundaries.has(id) || !boundaryMayArrive()) return undefined;
|
|
2095
|
+
installRevealHook();
|
|
2096
|
+
return awaitBoundary(id);
|
|
1999
2097
|
}
|
|
2000
2098
|
});
|
|
2001
2099
|
const showing = (address, id) => handler.showing(address, id);
|
|
@@ -2007,4 +2105,4 @@ function installServerComponents(host = getFrameHost()) {
|
|
|
2007
2105
|
});
|
|
2008
2106
|
}
|
|
2009
2107
|
|
|
2010
|
-
export { FRAME_APPLIED_EVENT, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents, isFrameStreamResponse };
|
|
2108
|
+
export { FRAME_APPLIED_EVENT, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents, isFrameStreamResponse, setDeferredHydration };
|