@solidjs/web 2.0.0-rc.14 → 2.0.0-rc.16
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 +475 -591
- package/dist/server.js +459 -489
- package/dist/server.observe.js +459 -498
- package/dist/web.dev.js +206 -220
- package/dist/web.js +196 -208
- package/dist/web.observe.js +206 -213
- package/frames/dist/client.dev.js +664 -643
- package/frames/dist/client.js +593 -582
- package/frames/dist/client.observe.js +624 -589
- package/frames/dist/regions.js +43 -2
- package/frames/dist/server.dev.js +578 -450
- package/frames/dist/server.js +578 -397
- package/frames/dist/server.observe.js +578 -397
- package/frames/dist/trace.js +4 -1
- package/frames/dist/wire.js +371 -6
- package/package.json +13 -13
- package/serialization/dist/decode.js +11 -9
- package/serialization/dist/serialization.js +11 -9
- package/serialization/types/serializer-decode.d.ts +2 -2
- package/server-functions/dist/client.dev.js +5 -2
- package/server-functions/dist/client.js +3 -2
- package/server-functions/dist/client.observe.js +5 -2
- package/server-functions/dist/rich-args.js +33 -1
- package/server-functions/dist/server.dev.js +218 -35
- package/server-functions/dist/server.js +218 -35
- package/server-functions/dist/server.observe.js +218 -35
- package/skills/server-components/SKILL.md +74 -185
- package/types/client.d.ts +112 -10
- package/types/constants.d.ts +2 -1
- package/types/frames/assets-tier.d.ts +2 -2
- package/types/frames/client.d.ts +8 -3
- package/types/frames/frame-client.d.ts +121 -157
- package/types/frames/frame-morph.d.ts +28 -0
- package/types/frames/frame-sink.d.ts +13 -9
- package/types/frames/frame-transport.d.ts +30 -1
- package/types/frames/regions-tier.d.ts +15 -0
- package/types/frames/serializer-decode.d.ts +2 -2
- package/types/frames/server.d.ts +1 -53
- package/types/frames/wire-tier.d.ts +54 -1
- package/types/head.d.ts +1 -0
- package/types/index.d.ts +57 -50
- package/types/index.server.d.ts +3 -27
- package/types/jsx.d.ts +14 -17
- package/types/observe.d.ts +14 -7
- package/types/render.d.ts +3 -1
- package/types/response.d.ts +31 -8
- package/types/serializer-decode.d.ts +2 -2
- package/types/server-functions/argument-codec.d.ts +21 -0
- package/types/server-functions/client.d.ts +18 -5
- package/types/server-functions/server.d.ts +6 -2
- package/types/server-functions/shared.d.ts +19 -0
- package/types/server-mock.d.ts +9 -2
- package/types/server-observe.d.ts +3 -2
- package/types/server.d.ts +124 -67
- package/frames/dist/bind.dev.js +0 -326
- package/frames/dist/bind.js +0 -295
- package/types/frames/bind-tier.d.ts +0 -60
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import * as core from 'solid-js';
|
|
2
|
-
import { getOwner, onCleanup, createMemo, runWithOwner, untrack, createRenderEffect, createSignal, createOwner } from 'solid-js';
|
|
3
|
-
import { insert } from '@solidjs/web';
|
|
2
|
+
import { OBSERVE, getOwner, onCleanup, createMemo, runWithOwner, untrack, createRenderEffect, onHydrationEnd, createSignal, createOwner } from 'solid-js';
|
|
3
|
+
import { installServerComponentHydration, insert } from '@solidjs/web';
|
|
4
4
|
import { frameAddress, SINGLE_FLIGHT_HEADER, LIVE_WIRE, deserializeStream, getServerFunctionsCodec, createChunk, deliverFlightData, ERROR_HEADER, hasFlightMetadata, ChunkReader, configureServerFunctionsClient } from '@solidjs/web/server-functions/client';
|
|
5
5
|
|
|
6
6
|
const ELEMENT_NODE = 1;
|
|
7
|
-
const TEXT_NODE = 3;
|
|
8
7
|
const COMMENT_NODE = 8;
|
|
9
8
|
const CLAIM_SEAM = Symbol.for("solid.element-claims");
|
|
10
9
|
const CLAIMED_ELEMENTS = "a[href], form[action]";
|
|
@@ -12,110 +11,29 @@ function claimHandlers() {
|
|
|
12
11
|
const handlers = globalThis[CLAIM_SEAM];
|
|
13
12
|
return handlers !== undefined && handlers.length !== 0 ? handlers : undefined;
|
|
14
13
|
}
|
|
15
|
-
function claimNode(handlers, 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);
|
|
19
|
+
}
|
|
16
20
|
for (let i = 0; i < handlers.length; i++) handlers[i](el);
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
function claimTree(handlers, root) {
|
|
22
|
+
function claimTree(handlers, root, adopter) {
|
|
20
23
|
const isElement = root.nodeType === ELEMENT_NODE;
|
|
21
24
|
if (!isElement && root.nodeType !== 11 ) return;
|
|
22
|
-
if (isElement && root.matches(CLAIMED_ELEMENTS)) claimNode(handlers, root);
|
|
25
|
+
if (isElement && root.matches(CLAIMED_ELEMENTS)) claimNode(handlers, root, adopter);
|
|
23
26
|
const found = root.querySelectorAll(CLAIMED_ELEMENTS);
|
|
24
|
-
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);
|
|
25
28
|
}
|
|
29
|
+
const adoptedBy = new WeakMap();
|
|
26
30
|
const placeholderId = name => `pl-${name}`;
|
|
27
31
|
const SLOT_START = /^slot:(.+):start$/;
|
|
28
32
|
const SLOT_END = /^slot:(.+):end$/;
|
|
29
33
|
const slotEnd = id => `slot:${id}:end`;
|
|
30
|
-
const SLOT_MARKER = "_s:";
|
|
31
|
-
const SLOT_TEXT = SLOT_MARKER + "t=";
|
|
32
|
-
const SLOT_TEXT_END = "/" + SLOT_MARKER + "t";
|
|
33
|
-
const isTextStart = n => n.nodeType === COMMENT_NODE && n.data.startsWith(SLOT_TEXT);
|
|
34
|
-
function hasSlotMarker(el) {
|
|
35
|
-
const attrs = el.attributes;
|
|
36
|
-
for (let i = 0; i < attrs.length; i++) if (attrs[i].name.startsWith(SLOT_MARKER)) return true;
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
34
|
function isAsyncValue(v) {
|
|
40
35
|
return v !== null && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
|
|
41
36
|
}
|
|
42
|
-
function chunkToRecords(chunk) {
|
|
43
|
-
switch (chunk.type) {
|
|
44
|
-
case "start":
|
|
45
|
-
case "data":
|
|
46
|
-
return {};
|
|
47
|
-
case "html":
|
|
48
|
-
return {
|
|
49
|
-
"": {
|
|
50
|
-
kind: "html",
|
|
51
|
-
value: chunk.html,
|
|
52
|
-
digest: chunk.digest,
|
|
53
|
-
holes: chunk.holes
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
case "fragment":
|
|
57
|
-
return {
|
|
58
|
-
[`seg:${chunk.key}`]: {
|
|
59
|
-
kind: "html",
|
|
60
|
-
value: chunk.html,
|
|
61
|
-
digest: chunk.digest,
|
|
62
|
-
holes: chunk.holes
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
case "reveal":
|
|
66
|
-
{
|
|
67
|
-
const records = {};
|
|
68
|
-
const gate = chunk.fallback ? "fallback" : "reveal";
|
|
69
|
-
for (const key of chunk.keys) records[`seg:${key}:${gate}`] = true;
|
|
70
|
-
return records;
|
|
71
|
-
}
|
|
72
|
-
case "assets":
|
|
73
|
-
return {
|
|
74
|
-
[`seg:${chunk.key}:assets`]: chunk
|
|
75
|
-
};
|
|
76
|
-
case "slot":
|
|
77
|
-
return {
|
|
78
|
-
[`slot:${chunk.key}`]: {
|
|
79
|
-
kind: "slot",
|
|
80
|
-
args: chunk.args
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
case "hole":
|
|
84
|
-
return {
|
|
85
|
-
[`hole:${chunk.key}`]: {
|
|
86
|
-
kind: "html",
|
|
87
|
-
value: chunk.html,
|
|
88
|
-
digest: chunk.digest,
|
|
89
|
-
holes: chunk.holes
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
case "attr":
|
|
93
|
-
return {
|
|
94
|
-
[`attr:${chunk.key}`]: {
|
|
95
|
-
kind: "attrs",
|
|
96
|
-
value: chunk.attrs,
|
|
97
|
-
removed: chunk.removed,
|
|
98
|
-
digest: chunk.digest
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
case "ops":
|
|
102
|
-
return Object.assign({}, ...chunk.ops.map(chunkToRecords));
|
|
103
|
-
case "complete":
|
|
104
|
-
return {
|
|
105
|
-
":complete": true,
|
|
106
|
-
":bound": chunk.bound
|
|
107
|
-
};
|
|
108
|
-
case "error":
|
|
109
|
-
if (!chunk.key) return {
|
|
110
|
-
":error": chunk.error
|
|
111
|
-
};
|
|
112
|
-
return {
|
|
113
|
-
[`${/^lha?:/.test(chunk.key) ? "hole" : "seg"}:${chunk.key}:error`]: chunk.error
|
|
114
|
-
};
|
|
115
|
-
default:
|
|
116
|
-
return {};
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
37
|
function createFrameHost(options = {}) {
|
|
120
38
|
const frames = new Map();
|
|
121
39
|
const stores = new Map();
|
|
@@ -144,15 +62,16 @@ function createFrameHost(options = {}) {
|
|
|
144
62
|
}
|
|
145
63
|
const assets = records["seg::assets"];
|
|
146
64
|
const previous = assets && store.records["seg::assets"];
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
65
|
+
Object.assign(store.records, records);
|
|
66
|
+
if (previous && previous !== assets) {
|
|
67
|
+
const merged = {
|
|
68
|
+
...previous
|
|
69
|
+
};
|
|
150
70
|
for (const name in assets) {
|
|
151
71
|
const values = assets[name];
|
|
152
|
-
if (Array.isArray(values))
|
|
153
|
-
previous[name] ? previous[name].push(...values) : previous[name] = values;
|
|
154
|
-
}
|
|
72
|
+
if (Array.isArray(values)) merged[name] = previous[name] ? previous[name].concat(values) : values;
|
|
155
73
|
}
|
|
74
|
+
store.records["seg::assets"] = merged;
|
|
156
75
|
}
|
|
157
76
|
return true;
|
|
158
77
|
};
|
|
@@ -225,34 +144,47 @@ function createFrameHost(options = {}) {
|
|
|
225
144
|
landings.delete(id);
|
|
226
145
|
}
|
|
227
146
|
},
|
|
228
|
-
apply(
|
|
229
|
-
if (
|
|
230
|
-
const store = stores.get(
|
|
147
|
+
apply(msg) {
|
|
148
|
+
if (msg.type === "data") {
|
|
149
|
+
const store = stores.get(msg.id);
|
|
231
150
|
const current = store && store.version;
|
|
232
|
-
if (store &&
|
|
233
|
-
options.applyData && options.applyData(
|
|
151
|
+
if (store && msg.version < current) return;
|
|
152
|
+
options.applyData && options.applyData(msg, current);
|
|
234
153
|
return;
|
|
235
154
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
+
};
|
|
242
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);
|
|
243
169
|
let r = records;
|
|
244
|
-
if (
|
|
170
|
+
if (msg.type === "start") {
|
|
171
|
+
store.open = true;
|
|
172
|
+
if (store.startedVersion !== msg.version) {
|
|
173
|
+
store.startedVersion = msg.version;
|
|
174
|
+
store.startedAt = msg.startedAt ?? performance.now();
|
|
175
|
+
}
|
|
176
|
+
} else if (lands(records)) {
|
|
245
177
|
store.open = false;
|
|
246
178
|
store.shown = r = store.records;
|
|
247
|
-
store.shownVersion =
|
|
248
|
-
const landed = landings.get(
|
|
179
|
+
store.shownVersion = msg.version;
|
|
180
|
+
const landed = landings.get(msg.id);
|
|
249
181
|
if (landed && !(":complete" in records && ":error" in r)) {
|
|
250
|
-
landings.delete(
|
|
182
|
+
landings.delete(msg.id);
|
|
251
183
|
":error" in records ? landed.j(records[":error"]) : landed.r();
|
|
252
184
|
}
|
|
253
185
|
}
|
|
254
|
-
applyTo(
|
|
255
|
-
if (":complete" in records || ":error" in records) options.closeData && options.closeData(
|
|
186
|
+
applyTo(msg.id, msg.version, r);
|
|
187
|
+
if (":complete" in records || ":error" in records) options.closeData && options.closeData(msg.id, msg.version, records[":error"]);
|
|
256
188
|
},
|
|
257
189
|
landing(id) {
|
|
258
190
|
const store = stores.get(id);
|
|
@@ -262,17 +194,21 @@ function createFrameHost(options = {}) {
|
|
|
262
194
|
if (!wait) {
|
|
263
195
|
landings.set(id, wait = {});
|
|
264
196
|
wait.p = new Promise((r, j) => (wait.r = r, wait.j = j));
|
|
197
|
+
if (store.open) OBSERVE.attribution.markFlight(wait.p, store.startedAt);
|
|
265
198
|
}
|
|
266
199
|
return wait.p;
|
|
267
200
|
},
|
|
268
|
-
preview(
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
201
|
+
preview(msg) {
|
|
202
|
+
const set = frames.get(msg.id);
|
|
203
|
+
if (!set || !msg.r) return;
|
|
204
|
+
let records;
|
|
205
|
+
for (const key in msg.r) if (key.startsWith("slot:")) {
|
|
206
|
+
const record = (records ??= {})[key] = {
|
|
207
|
+
...msg.r[key]
|
|
208
|
+
};
|
|
209
|
+
settleArgs(storeFor(msg.id), key, record, msg);
|
|
210
|
+
}
|
|
211
|
+
if (records) for (const frame of set) frame.preview && frame.preview(records);
|
|
276
212
|
},
|
|
277
213
|
get(id) {
|
|
278
214
|
const set = frames.get(id);
|
|
@@ -290,6 +226,26 @@ const FRAME_APPLIED_EVENT = "frame:applied";
|
|
|
290
226
|
const tierLoaders = {};
|
|
291
227
|
const tierLoads = {};
|
|
292
228
|
const liveFrames = new Set();
|
|
229
|
+
let deferDriver = null;
|
|
230
|
+
function setDeferDriver(driver) {
|
|
231
|
+
deferDriver = driver;
|
|
232
|
+
}
|
|
233
|
+
function deferredFrames() {
|
|
234
|
+
return [...liveFrames].filter(f => f.deferred);
|
|
235
|
+
}
|
|
236
|
+
function releaseDeferHolds() {
|
|
237
|
+
for (const f of liveFrames) f.releaseDeferHold();
|
|
238
|
+
}
|
|
239
|
+
function hasSlotRange(root) {
|
|
240
|
+
const w = root.ownerDocument.createTreeWalker(root, 0x80);
|
|
241
|
+
for (let n; n = w.nextNode();) if (n.data.startsWith("slot:")) return true;
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
function liveFrameAt(node) {
|
|
245
|
+
let hit;
|
|
246
|
+
for (const f of liveFrames) if (f.el.contains(node) && (!hit || hit.el.contains(f.el))) hit = f;
|
|
247
|
+
return hit;
|
|
248
|
+
}
|
|
293
249
|
function prepareTier(name) {
|
|
294
250
|
let load = tierLoads[name];
|
|
295
251
|
if (!load) {
|
|
@@ -305,6 +261,7 @@ function prepareTier(name) {
|
|
|
305
261
|
}
|
|
306
262
|
return load;
|
|
307
263
|
}
|
|
264
|
+
const prepareMorph = () => liveFrames.size && prepareTier("wire");
|
|
308
265
|
const tierReady = name => !tierLoaders[name] || prepareTier(name).r;
|
|
309
266
|
const needsRegions = record => record.regions && !tierReady("regions");
|
|
310
267
|
const carriesTrace = value => value != null && typeof value === "object" && (value.$tr != null || Object.values(value).some(carriesTrace));
|
|
@@ -315,10 +272,14 @@ class FrameImpl {
|
|
|
315
272
|
#outer;
|
|
316
273
|
#version;
|
|
317
274
|
#store = Object.create(null);
|
|
275
|
+
#content = new Set();
|
|
318
276
|
#appliedRoot;
|
|
319
277
|
#appliedError;
|
|
320
278
|
#hasContent = false;
|
|
321
279
|
#appliedHoles = new Map();
|
|
280
|
+
#liveTargets = new Map();
|
|
281
|
+
#shows = {};
|
|
282
|
+
#liveMount;
|
|
322
283
|
#slots;
|
|
323
284
|
#mountedSlots = new Set();
|
|
324
285
|
#slotCleanups = new Map();
|
|
@@ -326,11 +287,19 @@ class FrameImpl {
|
|
|
326
287
|
#slotUpdaters = new Map();
|
|
327
288
|
#hold;
|
|
328
289
|
#heldRecords = new Map();
|
|
290
|
+
#found;
|
|
291
|
+
#waiting = new Set();
|
|
329
292
|
#disposed = false;
|
|
330
|
-
#
|
|
293
|
+
#defers = false;
|
|
294
|
+
#deferred = false;
|
|
295
|
+
#deferFound;
|
|
296
|
+
#deferWaiting = false;
|
|
297
|
+
#deferMounted = new Map();
|
|
298
|
+
#deferHold;
|
|
299
|
+
#claimTree = (node, direct, adopter) => {
|
|
331
300
|
const handlers = claimHandlers();
|
|
332
301
|
if (!handlers) return;
|
|
333
|
-
this.#scoped(() => direct ? claimNode(handlers, node) : claimTree(handlers, node));
|
|
302
|
+
this.#scoped(() => direct ? claimNode(handlers, node) : claimTree(handlers, node, adopter));
|
|
334
303
|
};
|
|
335
304
|
#scoped(fn) {
|
|
336
305
|
const scope = this.#options.ownerScope;
|
|
@@ -345,11 +314,16 @@ class FrameImpl {
|
|
|
345
314
|
if (options.adopt) {
|
|
346
315
|
this.#hasContent = true;
|
|
347
316
|
this.#claimContent();
|
|
317
|
+
this.#defers = !!deferDriver && !!(options.defer || this.#outer?.defers);
|
|
318
|
+
this.#deferred = this.#defers && !!(this.#slots || this.#outer) && hasSlotRange(element);
|
|
348
319
|
}
|
|
349
320
|
if (options.host && options.id !== undefined) {
|
|
350
321
|
options.host.register(options.id, this);
|
|
351
322
|
}
|
|
352
|
-
if (
|
|
323
|
+
if (this.#deferred) {
|
|
324
|
+
this.#deferHold = options.hold?.();
|
|
325
|
+
deferDriver(this);
|
|
326
|
+
} else if (options.adopt && this.#version === undefined) this.#syncSlots();
|
|
353
327
|
}
|
|
354
328
|
#applied(version, reason) {
|
|
355
329
|
this.#options.onApply?.({
|
|
@@ -389,8 +363,15 @@ class FrameImpl {
|
|
|
389
363
|
this.#version = v;
|
|
390
364
|
this.#resetStreamState();
|
|
391
365
|
}
|
|
392
|
-
|
|
393
|
-
|
|
366
|
+
let only = [];
|
|
367
|
+
for (const key in write.r) {
|
|
368
|
+
const prev = this.#store[key];
|
|
369
|
+
const occurrence = key.slice(5);
|
|
370
|
+
if (this.#deferred && prev?.kind === "slot" && !prev.pending && !this.#mountedSlots.has(occurrence)) this.#heldRecords.has(occurrence) || this.#heldRecords.set(occurrence, prev);
|
|
371
|
+
this.#store[key] = write.r[key];
|
|
372
|
+
if (key.startsWith("slot:")) only?.push(occurrence);else this.#content.add(key), only = undefined;
|
|
373
|
+
}
|
|
374
|
+
this.#flush(only?.length ? only : undefined);
|
|
394
375
|
}
|
|
395
376
|
preview(records, inherited) {
|
|
396
377
|
const adopted = new Set();
|
|
@@ -412,17 +393,25 @@ class FrameImpl {
|
|
|
412
393
|
return adopted;
|
|
413
394
|
}
|
|
414
395
|
#resetStreamState() {
|
|
396
|
+
if (this.#hasContent) prepareTier("wire");
|
|
397
|
+
this.#found = undefined;
|
|
415
398
|
this.#store = Object.create(null);
|
|
399
|
+
this.#content.clear();
|
|
416
400
|
this.#appliedRoot = this.#appliedError = undefined;
|
|
417
401
|
this.#appliedHoles.clear();
|
|
402
|
+
this.#liveTargets.clear();
|
|
403
|
+
this.#shows = {};
|
|
418
404
|
}
|
|
419
|
-
#flush() {
|
|
405
|
+
#flush(only) {
|
|
420
406
|
if (this.#disposed) return;
|
|
421
407
|
const version = this.#version;
|
|
422
408
|
const root = this.#store[""];
|
|
409
|
+
const applied = this.#appliedRoot;
|
|
423
410
|
if (root && root.kind === "html" && root !== this.#appliedRoot) {
|
|
424
|
-
const
|
|
425
|
-
|
|
411
|
+
const wire = this.#hasContent ? tierReady("wire") : null;
|
|
412
|
+
if (wire === undefined) return;
|
|
413
|
+
const reason = wire ? "morph" : "materialize";
|
|
414
|
+
this.#applyRoot(root.value, wire);
|
|
426
415
|
this.#appliedRoot = root;
|
|
427
416
|
this.#recordHave("", root);
|
|
428
417
|
this.#applied(version, reason);
|
|
@@ -432,7 +421,7 @@ class FrameImpl {
|
|
|
432
421
|
this.#appliedError = error;
|
|
433
422
|
this.#applied(version, "error");
|
|
434
423
|
}
|
|
435
|
-
for (const key
|
|
424
|
+
for (const key of this.#content) {
|
|
436
425
|
const record = this.#store[key];
|
|
437
426
|
if (!key.endsWith(":assets") || !record || this.#appliedHoles.get(key) === record) continue;
|
|
438
427
|
const tier = tierReady("assets");
|
|
@@ -440,28 +429,57 @@ class FrameImpl {
|
|
|
440
429
|
this.#appliedHoles.set(key, record);
|
|
441
430
|
tier.apply(record);
|
|
442
431
|
}
|
|
443
|
-
this.#revealSegments();
|
|
432
|
+
const revealed = this.#revealSegments();
|
|
444
433
|
let morphed = false;
|
|
445
|
-
|
|
434
|
+
const index = {};
|
|
435
|
+
let wire;
|
|
436
|
+
for (const key of this.#content) {
|
|
446
437
|
const record = this.#store[key];
|
|
447
438
|
if (!record || this.#appliedHoles.get(key) === record) continue;
|
|
448
439
|
if (key.startsWith("hole:")) {
|
|
449
440
|
if (key.endsWith(":error")) {
|
|
450
441
|
this.#appliedHoles.set(key, record);
|
|
451
|
-
|
|
452
|
-
this.#appliedHoles.set(key, record);
|
|
453
|
-
this.#recordHave(key.slice(5), record);
|
|
454
|
-
morphed = true;
|
|
455
|
-
}
|
|
456
|
-
} else if (key.startsWith("attr:")) {
|
|
457
|
-
if (this.#applyAttrs(key.slice(5), record.value, record.removed)) {
|
|
458
|
-
this.#appliedHoles.set(key, record);
|
|
459
|
-
this.#recordHave("lha:" + key.slice(5), record);
|
|
460
|
-
morphed = true;
|
|
442
|
+
continue;
|
|
461
443
|
}
|
|
444
|
+
} else if (!key.startsWith("attr:")) continue;
|
|
445
|
+
if (!this.#hasContent || !(wire ??= tierReady("wire"))) continue;
|
|
446
|
+
const name = key.slice(5);
|
|
447
|
+
const attr = key[0] === "a";
|
|
448
|
+
if (!attr) this.#found = undefined;
|
|
449
|
+
if (attr ? wire.attrs(this.#live, name, record) : wire.hole(this.#live, name, record, index)) {
|
|
450
|
+
this.#appliedHoles.set(key, record);
|
|
451
|
+
this.#recordHave(attr ? "lha:" + name : name, record);
|
|
452
|
+
morphed = true;
|
|
462
453
|
}
|
|
463
454
|
}
|
|
455
|
+
if (index.r?.size) wire.graft(index.g, index.r);
|
|
464
456
|
if (morphed) this.#applied(version, "morph");
|
|
457
|
+
if (this.#deferred) {
|
|
458
|
+
if (!morphed && this.#appliedRoot === applied) {
|
|
459
|
+
if (revealed || !only) this.#deferFound = undefined;
|
|
460
|
+
const mounted = only ? new Map() : new Map(this.#deferMounted);
|
|
461
|
+
if (only) for (const id of only) {
|
|
462
|
+
const start = this.#deferMounted.get(id);
|
|
463
|
+
if (start) mounted.set(id, start);else if (!this.#deferFound?.has(id)) this.#deferFound = undefined;
|
|
464
|
+
}
|
|
465
|
+
if (mounted.size) this.#deferWaiting = this.#mountFound(mounted) || this.#deferWaiting;
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
this.#deferred = false;
|
|
469
|
+
this.#deferFound = undefined;
|
|
470
|
+
this.#deferMounted.clear();
|
|
471
|
+
}
|
|
472
|
+
const found = this.#found;
|
|
473
|
+
if (only && found && this.#appliedRoot === applied) {
|
|
474
|
+
const sub = new Map();
|
|
475
|
+
for (const id of only) {
|
|
476
|
+
const start = found.get(id);
|
|
477
|
+
if (!start?.isConnected) return this.#syncSlots();
|
|
478
|
+
sub.set(id, start);
|
|
479
|
+
}
|
|
480
|
+
this.#mountFound(sub);
|
|
481
|
+
return this.#holdIf(this.#waiting.size);
|
|
482
|
+
}
|
|
465
483
|
this.#syncSlots();
|
|
466
484
|
}
|
|
467
485
|
#resolveSlot(prop) {
|
|
@@ -481,25 +499,36 @@ class FrameImpl {
|
|
|
481
499
|
#syncSlots(root) {
|
|
482
500
|
if (!this.#slots && !this.#outer) return;
|
|
483
501
|
const found = new Map();
|
|
484
|
-
|
|
502
|
+
this.#collectSlots(found, root);
|
|
503
|
+
if (root) this.#found = undefined;else this.#found = found, this.#waiting.clear();
|
|
504
|
+
const waiting = this.#mountFound(found);
|
|
505
|
+
if (!root) {
|
|
506
|
+
for (const occurrence of [...this.#mountedSlots]) {
|
|
507
|
+
if (!found.has(occurrence)) this.#unmountSlot(occurrence);
|
|
508
|
+
}
|
|
509
|
+
this.#holdIf(waiting);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
#holdIf(waiting) {
|
|
513
|
+
if (waiting && !this.#hold) this.#hold = this.#options.hold?.();else if (!waiting && this.#hold) this.#releaseHold();
|
|
514
|
+
}
|
|
515
|
+
#mountFound(found) {
|
|
485
516
|
let waiting = false;
|
|
486
517
|
const R = tierLoads.regions?.r;
|
|
487
|
-
const B = tierLoads.bind?.r;
|
|
488
518
|
for (const [occurrence, start] of found) {
|
|
519
|
+
this.#waiting.delete(occurrence);
|
|
489
520
|
const callback = this.#resolveSlot(propOf(occurrence));
|
|
490
|
-
|
|
491
|
-
if (!callback) {
|
|
492
|
-
continue;
|
|
493
|
-
}
|
|
521
|
+
if (!callback) continue;
|
|
494
522
|
const record = this.#resolveSlotRecord(occurrence);
|
|
495
523
|
const mounted = this.#mountedSlots.has(occurrence);
|
|
496
524
|
if (record === undefined && isCalled(occurrence)) {
|
|
497
|
-
waiting
|
|
525
|
+
if (!mounted) waiting = true, this.#waiting.add(occurrence);
|
|
498
526
|
continue;
|
|
499
527
|
}
|
|
500
528
|
if (!mounted && record && (record.pending || needsRegions(record) || needsTrace(record.args))) {
|
|
501
529
|
waiting = true;
|
|
502
|
-
|
|
530
|
+
this.#waiting.add(occurrence);
|
|
531
|
+
if (this.#options.adopt) this.#heldRecords.has(occurrence) || this.#heldRecords.set(occurrence, record);
|
|
503
532
|
continue;
|
|
504
533
|
}
|
|
505
534
|
if (!mounted) {
|
|
@@ -507,12 +536,10 @@ class FrameImpl {
|
|
|
507
536
|
this.#heldRecords.delete(occurrence);
|
|
508
537
|
const mountRecord = held || record;
|
|
509
538
|
this.#invokeSlot(occurrence, callback, mountRecord, start, this.#options.adopt);
|
|
510
|
-
if (consumers) B.sync(this, occurrence, consumers);
|
|
511
539
|
this.#mountedSlots.add(occurrence);
|
|
512
540
|
R?.bind(this, occurrence);
|
|
513
541
|
if (mountRecord === record || !record || record.kind !== "slot") continue;
|
|
514
542
|
}
|
|
515
|
-
if (consumers) B.sync(this, occurrence, consumers);
|
|
516
543
|
if (record !== this.#slotArgs.get(occurrence)) {
|
|
517
544
|
if (needsRegions(record) || needsTrace(record.args)) continue;
|
|
518
545
|
const update = this.#slotUpdaters.get(occurrence);
|
|
@@ -527,13 +554,77 @@ class FrameImpl {
|
|
|
527
554
|
R?.bind(this, occurrence);
|
|
528
555
|
}
|
|
529
556
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
557
|
+
return waiting;
|
|
558
|
+
}
|
|
559
|
+
get el() {
|
|
560
|
+
return this.#element;
|
|
561
|
+
}
|
|
562
|
+
get defers() {
|
|
563
|
+
return this.#defers;
|
|
564
|
+
}
|
|
565
|
+
get deferred() {
|
|
566
|
+
return this.#deferred;
|
|
567
|
+
}
|
|
568
|
+
mountEnclosing(target) {
|
|
569
|
+
if (!this.#deferred) return false;
|
|
570
|
+
const root = this.#element;
|
|
571
|
+
let outer;
|
|
572
|
+
for (let node = target; node && node !== root; node = node.parentNode) {
|
|
573
|
+
let depth = 0;
|
|
574
|
+
for (let s = node.previousSibling; s; s = s.previousSibling) {
|
|
575
|
+
if (s.nodeType !== COMMENT_NODE || !s.data.startsWith("slot:")) continue;
|
|
576
|
+
if (SLOT_END.test(s.data)) depth++;else if (depth) depth--;else outer = s;
|
|
534
577
|
}
|
|
535
|
-
if (waiting && !this.#hold) this.#hold = this.#options.hold?.();else if (!waiting && this.#hold) this.#releaseHold();
|
|
536
578
|
}
|
|
579
|
+
const id = outer && slotStartId(outer);
|
|
580
|
+
if (!id || this.#mountedSlots.has(id)) return false;
|
|
581
|
+
return this.#mountOne(id, outer);
|
|
582
|
+
}
|
|
583
|
+
#mountOne(id, start) {
|
|
584
|
+
const mount = () => {
|
|
585
|
+
this.#deferWaiting = this.#mountFound(new Map([[id, start]])) || this.#deferWaiting;
|
|
586
|
+
};
|
|
587
|
+
mount();
|
|
588
|
+
if (!this.#mountedSlots.has(id)) return false;
|
|
589
|
+
this.#deferMounted.set(id, start);
|
|
590
|
+
return true;
|
|
591
|
+
}
|
|
592
|
+
mountDeferred(deadline) {
|
|
593
|
+
if (!this.#deferred) return true;
|
|
594
|
+
let found = this.#deferFound;
|
|
595
|
+
if (!found) {
|
|
596
|
+
found = this.#deferFound = new Map();
|
|
597
|
+
this.#collectSlots(found);
|
|
598
|
+
}
|
|
599
|
+
for (const [id, start] of found) {
|
|
600
|
+
found.delete(id);
|
|
601
|
+
if (this.#mountedSlots.has(id)) this.#deferWaiting = this.#mountFound(new Map([[id, start]])) || this.#deferWaiting;else this.#mountOne(id, start);
|
|
602
|
+
if (deadline !== undefined && found.size && performance.now() > deadline) return false;
|
|
603
|
+
}
|
|
604
|
+
this.#deferred = false;
|
|
605
|
+
this.#deferFound = undefined;
|
|
606
|
+
this.#deferMounted.clear();
|
|
607
|
+
if (this.#deferWaiting && !this.#hold) this.#hold = this.#options.hold?.();
|
|
608
|
+
return true;
|
|
609
|
+
}
|
|
610
|
+
mountOccurrence(id) {
|
|
611
|
+
if (!this.#deferred) return false;
|
|
612
|
+
if (this.#mountedSlots.has(id)) return true;
|
|
613
|
+
let found = this.#deferFound;
|
|
614
|
+
if (!found) {
|
|
615
|
+
found = this.#deferFound = new Map();
|
|
616
|
+
this.#collectSlots(found);
|
|
617
|
+
}
|
|
618
|
+
const start = found.get(id);
|
|
619
|
+
if (!start) return false;
|
|
620
|
+
found.delete(id);
|
|
621
|
+
this.#mountOne(id, start);
|
|
622
|
+
return true;
|
|
623
|
+
}
|
|
624
|
+
releaseDeferHold() {
|
|
625
|
+
const release = this.#deferHold;
|
|
626
|
+
this.#deferHold = undefined;
|
|
627
|
+
release && release();
|
|
537
628
|
}
|
|
538
629
|
#releaseHold() {
|
|
539
630
|
const release = this.#hold;
|
|
@@ -545,8 +636,7 @@ class FrameImpl {
|
|
|
545
636
|
const cleanups = this.#slotCleanups.get(occurrence) ?? [];
|
|
546
637
|
let existing = [];
|
|
547
638
|
let end = null;
|
|
548
|
-
|
|
549
|
-
if (start && !positions) end = eachInRange(start, occurrence, n => existing.push(n));
|
|
639
|
+
if (start) end = eachInRange(start, occurrence, n => existing.push(n));
|
|
550
640
|
const ctx = {
|
|
551
641
|
frame: this.#options.claimScope ?? this.#options.id,
|
|
552
642
|
key: occurrence,
|
|
@@ -558,9 +648,7 @@ class FrameImpl {
|
|
|
558
648
|
range: end ? {
|
|
559
649
|
start,
|
|
560
650
|
end
|
|
561
|
-
} : undefined
|
|
562
|
-
positions,
|
|
563
|
-
onRebind: positions ? fn => tierLoads.bind.r.rebinder(this, occurrence, fn) : undefined
|
|
651
|
+
} : undefined
|
|
564
652
|
};
|
|
565
653
|
const props = record && record.kind === "slot" ? this.#resolveArgs(occurrence, record, adopted, start) : {};
|
|
566
654
|
this.#scoped(() => callback(props, ctx));
|
|
@@ -575,7 +663,6 @@ class FrameImpl {
|
|
|
575
663
|
this.#removeSlotRecord(key);
|
|
576
664
|
this.#runSlotCleanups(key);
|
|
577
665
|
tierLoads.regions?.r?.unmount(this, key);
|
|
578
|
-
tierLoads.bind?.r?.unmount(this, key);
|
|
579
666
|
}
|
|
580
667
|
#runSlotCleanups(key) {
|
|
581
668
|
const cleanups = this.#slotCleanups.get(key);
|
|
@@ -602,8 +689,8 @@ class FrameImpl {
|
|
|
602
689
|
if (regions) tierLoads.regions.r.resolve(this, slotKey, regions, props, claiming && start);
|
|
603
690
|
return props;
|
|
604
691
|
}
|
|
605
|
-
#collectSlots(found,
|
|
606
|
-
collectSlots(this.#element
|
|
692
|
+
#collectSlots(found, root) {
|
|
693
|
+
collectSlots(root || this.#element, found);
|
|
607
694
|
}
|
|
608
695
|
#findPlaceholder(name, root) {
|
|
609
696
|
return findPlaceholder((root || this.#element).firstChild, null, placeholderId(name));
|
|
@@ -630,7 +717,23 @@ class FrameImpl {
|
|
|
630
717
|
this.#resetStreamState();
|
|
631
718
|
if (host) host.register(id, this);
|
|
632
719
|
}
|
|
720
|
+
get #live() {
|
|
721
|
+
return this.#liveMount ??= {
|
|
722
|
+
e: this.#element,
|
|
723
|
+
t: this.#liveTargets,
|
|
724
|
+
c: this.#claimTree,
|
|
725
|
+
k: found => this.#collectSlots(found),
|
|
726
|
+
s: () => this.#shows,
|
|
727
|
+
x: (key, record) => (this.#appliedHoles.set(key, record), tierLoads.wire.r.cancel(this.#options.host, this.#options.id)),
|
|
728
|
+
w: false
|
|
729
|
+
};
|
|
730
|
+
}
|
|
633
731
|
#recordHave(key, record) {
|
|
732
|
+
this.#shows = key ? Object.assign(this.#shows, {
|
|
733
|
+
[key]: record.digest
|
|
734
|
+
}, record.holes) : {
|
|
735
|
+
...record.holes
|
|
736
|
+
};
|
|
634
737
|
tierLoads.wire?.r?.have(this, key, record);
|
|
635
738
|
}
|
|
636
739
|
dispose() {
|
|
@@ -643,12 +746,16 @@ class FrameImpl {
|
|
|
643
746
|
this.#disposed = true;
|
|
644
747
|
liveFrames.delete(this);
|
|
645
748
|
this.#releaseHold();
|
|
749
|
+
this.releaseDeferHold();
|
|
646
750
|
for (const key of [...this.#slotCleanups.keys()]) this.#runSlotCleanups(key);
|
|
647
751
|
for (const key of this.#mountedSlots) this.#removeSlotRecord(key);
|
|
648
752
|
tierLoads.regions?.r?.unmount(this);
|
|
649
753
|
this.#mountedSlots.clear();
|
|
650
754
|
}
|
|
651
|
-
#applyRoot(html) {
|
|
755
|
+
#applyRoot(html, wire) {
|
|
756
|
+
this.#found = undefined;
|
|
757
|
+
this.#liveTargets.clear();
|
|
758
|
+
this.#shows = {};
|
|
652
759
|
const fragment = parseFragment(html);
|
|
653
760
|
const parent = this.#element;
|
|
654
761
|
if (!this.#hasContent) {
|
|
@@ -660,62 +767,16 @@ class FrameImpl {
|
|
|
660
767
|
const claim = this.#claimTree;
|
|
661
768
|
const ranges = new Map();
|
|
662
769
|
this.#collectSlots(ranges);
|
|
663
|
-
|
|
664
|
-
reconcileChildren(parent, fragment, null, null, claim, ranges, grafts);
|
|
665
|
-
if (ranges.size) for (const root of grafts) flushGrafts(root, ranges);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
#applyHole(marker, html) {
|
|
669
|
-
if (!this.#hasContent) return false;
|
|
670
|
-
const open = findLiveTarget(this.#element.firstChild, null, n => n.nodeType === COMMENT_NODE && n.data === marker);
|
|
671
|
-
if (!open) return false;
|
|
672
|
-
const close = rangeClose(open, "lh:/" + marker.slice(3));
|
|
673
|
-
if (!close) {
|
|
674
|
-
return false;
|
|
675
|
-
}
|
|
676
|
-
reconcileChildren(open.parentNode, parseFragment(html), open, close, this.#claimTree);
|
|
677
|
-
return true;
|
|
678
|
-
}
|
|
679
|
-
#applyAttrs(addr, text, removed) {
|
|
680
|
-
if (!this.#hasContent) return false;
|
|
681
|
-
const el = findLiveTarget(this.#element.firstChild, null, n => n.nodeType === ELEMENT_NODE && n.getAttribute("data-lha") === addr);
|
|
682
|
-
if (!el) return false;
|
|
683
|
-
const parsed = parseFragment(`<i${text}></i>`).firstChild;
|
|
684
|
-
const keepOpen = preservesOpen(el);
|
|
685
|
-
const owned = parsed ? ownedPositions(parsed) : null;
|
|
686
|
-
const current = el.attributes;
|
|
687
|
-
for (let i = current.length - 1; i >= 0; i--) {
|
|
688
|
-
const name = current[i].name;
|
|
689
|
-
if (name === "data-lha" || keepOpen && name === "open") continue;
|
|
690
|
-
if (!parsed || !parsed.hasAttribute(name)) {
|
|
691
|
-
if (applyOwned(el, name, "", owned) !== undefined) continue;
|
|
692
|
-
el.removeAttribute(name);
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
if (parsed) {
|
|
696
|
-
for (let i = 0; i < parsed.attributes.length; i++) {
|
|
697
|
-
const {
|
|
698
|
-
name,
|
|
699
|
-
value
|
|
700
|
-
} = parsed.attributes[i];
|
|
701
|
-
if (keepOpen && name === "open") continue;
|
|
702
|
-
if (applyOwned(el, name, value, owned) !== undefined) continue;
|
|
703
|
-
if (el.getAttribute(name) !== value) el.setAttribute(name, value);
|
|
704
|
-
}
|
|
770
|
+
wire.morph(parent, fragment, claim, ranges);
|
|
705
771
|
}
|
|
706
|
-
if (removed) for (const name of removed) {
|
|
707
|
-
if (keepOpen && name === "open") continue;
|
|
708
|
-
if (applyOwned(el, name, "", owned) !== undefined) continue;
|
|
709
|
-
el.removeAttribute(name);
|
|
710
|
-
}
|
|
711
|
-
return true;
|
|
712
772
|
}
|
|
713
773
|
#claimContent() {
|
|
714
|
-
for (let n = this.#element.firstChild; n; n = n.nextSibling) this.#claimTree(n);
|
|
774
|
+
for (let n = this.#element.firstChild; n; n = n.nextSibling) this.#claimTree(n, false, this);
|
|
715
775
|
}
|
|
716
776
|
#revealSegments(root) {
|
|
717
777
|
const version = this.#version;
|
|
718
|
-
|
|
778
|
+
let revealed = false;
|
|
779
|
+
for (const key of this.#content) {
|
|
719
780
|
const record = this.#store[key];
|
|
720
781
|
const name = segmentName(key);
|
|
721
782
|
if (name === null || !record || this.#appliedHoles.get(key) === record) continue;
|
|
@@ -723,9 +784,10 @@ class FrameImpl {
|
|
|
723
784
|
this.#appliedHoles.set(key, record);
|
|
724
785
|
this.#revealSegment(name, root);
|
|
725
786
|
this.#applied(version, "reveal");
|
|
787
|
+
revealed = true;
|
|
726
788
|
}
|
|
727
789
|
}
|
|
728
|
-
for (const key
|
|
790
|
+
for (const key of this.#content) {
|
|
729
791
|
const m = /^seg:([^:]+):fallback$/.exec(key);
|
|
730
792
|
if (!m || this.#appliedHoles.has(key) || this.#appliedHoles.has(`seg:${m[1]}`)) continue;
|
|
731
793
|
if (this.#showFallback(m[1], root)) {
|
|
@@ -733,6 +795,7 @@ class FrameImpl {
|
|
|
733
795
|
this.#applied(version, "reveal");
|
|
734
796
|
}
|
|
735
797
|
}
|
|
798
|
+
return revealed;
|
|
736
799
|
}
|
|
737
800
|
#segmentReady(name, root) {
|
|
738
801
|
const content = this.#store[`seg:${name}`];
|
|
@@ -745,6 +808,7 @@ class FrameImpl {
|
|
|
745
808
|
#revealSegment(name, root) {
|
|
746
809
|
const tpl = this.#findPlaceholder(name, root);
|
|
747
810
|
if (!tpl) return;
|
|
811
|
+
this.#found = undefined;
|
|
748
812
|
const content = this.#store[`seg:${name}`];
|
|
749
813
|
const closing = rangeClose(tpl, placeholderId(name));
|
|
750
814
|
if (!closing) {
|
|
@@ -804,9 +868,6 @@ function makeFrameElement(id) {
|
|
|
804
868
|
if (id !== undefined) el.setAttribute(FRAME_ID_ATTR, id);
|
|
805
869
|
return el;
|
|
806
870
|
}
|
|
807
|
-
function isFrameElement(node) {
|
|
808
|
-
return node.nodeType === ELEMENT_NODE && node.hasAttribute(FRAME_ID_ATTR);
|
|
809
|
-
}
|
|
810
871
|
function segmentName(key) {
|
|
811
872
|
const m = /^seg:([^:]+)$/.exec(key);
|
|
812
873
|
return m ? m[1] : null;
|
|
@@ -845,20 +906,6 @@ function rangeClose(start, id) {
|
|
|
845
906
|
}
|
|
846
907
|
return null;
|
|
847
908
|
}
|
|
848
|
-
function findLiveTarget(n, end, test) {
|
|
849
|
-
while (n && n !== end) {
|
|
850
|
-
if (n.nodeType === ELEMENT_NODE) {
|
|
851
|
-
const fid = isFrameElement(n) ? n.getAttribute(FRAME_ID_ATTR) : null;
|
|
852
|
-
if (fid === null || fid.includes(".")) {
|
|
853
|
-
if (test(n)) return n;
|
|
854
|
-
const found = findLiveTarget(n.firstChild, null, test);
|
|
855
|
-
if (found) return found;
|
|
856
|
-
}
|
|
857
|
-
} else if (test(n)) return n;
|
|
858
|
-
n = n.nextSibling;
|
|
859
|
-
}
|
|
860
|
-
return null;
|
|
861
|
-
}
|
|
862
909
|
function findPlaceholder(n, end, id) {
|
|
863
910
|
while (n && n !== end) {
|
|
864
911
|
if (isPlaceholderStart(n, id)) return n;
|
|
@@ -870,26 +917,25 @@ function findPlaceholder(n, end, id) {
|
|
|
870
917
|
}
|
|
871
918
|
return null;
|
|
872
919
|
}
|
|
873
|
-
function collectSlots(
|
|
874
|
-
|
|
920
|
+
function collectSlots(root, out) {
|
|
921
|
+
const w = root.ownerDocument.createTreeWalker(root, 0x80);
|
|
922
|
+
let n, p;
|
|
923
|
+
while (n = w.nextNode()) {
|
|
924
|
+
if (!n.data.startsWith("slot:")) continue;
|
|
875
925
|
const id = slotStartId(n);
|
|
876
|
-
if (id
|
|
877
|
-
|
|
878
|
-
|
|
926
|
+
if (!id) continue;
|
|
927
|
+
for (p = n.parentNode; p !== root; p = p.parentNode) if (p.hasAttribute(FRAME_ID_ATTR)) break;
|
|
928
|
+
if (p !== root) continue;
|
|
929
|
+
if (!out.has(id)) out.set(id, n);
|
|
930
|
+
const end = findMarker(n, slotEnd(id));
|
|
931
|
+
if (end) {
|
|
932
|
+
w.currentNode = end;
|
|
879
933
|
continue;
|
|
880
934
|
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
if (n.nodeType === ELEMENT_NODE && !isFrameElement(n)) {
|
|
886
|
-
if (elements !== undefined && n.hasAttributes()) {
|
|
887
|
-
const B = tierLoads.bind?.r;
|
|
888
|
-
B ? B.positions(n, elements) : hasSlotMarker(n) && (elements.b = true);
|
|
889
|
-
}
|
|
890
|
-
collectSlots(n.firstChild, null, out, elements);
|
|
891
|
-
}
|
|
892
|
-
n = n.nextSibling;
|
|
935
|
+
p = n.parentNode;
|
|
936
|
+
if (p === root) return;
|
|
937
|
+
while (p.lastChild) p = p.lastChild;
|
|
938
|
+
w.currentNode = p;
|
|
893
939
|
}
|
|
894
940
|
}
|
|
895
941
|
function eachInRange(start, key, cb) {
|
|
@@ -907,237 +953,12 @@ function slotStartId(node) {
|
|
|
907
953
|
const m = SLOT_START.exec(node.data);
|
|
908
954
|
return m ? m[1] : null;
|
|
909
955
|
}
|
|
910
|
-
function
|
|
911
|
-
if (node.nodeType !== COMMENT_NODE) return false;
|
|
912
|
-
const data = node.data;
|
|
913
|
-
return SLOT_START.test(data) || SLOT_END.test(data);
|
|
914
|
-
}
|
|
915
|
-
function compatible(a, b) {
|
|
916
|
-
if (a.nodeType !== b.nodeType) return false;
|
|
917
|
-
if (a.nodeType === ELEMENT_NODE) return a.nodeName === b.nodeName && a.getAttribute("_key") === b.getAttribute("_key");
|
|
918
|
-
return a.nodeType === TEXT_NODE || a.nodeType === COMMENT_NODE;
|
|
919
|
-
}
|
|
920
|
-
function preservesOpen(el) {
|
|
921
|
-
const t = el.tagName;
|
|
922
|
-
return t === "DETAILS" || t === "DIALOG";
|
|
923
|
-
}
|
|
924
|
-
const ownedPositions = el => {
|
|
925
|
-
const B = tierLoads.bind?.r;
|
|
926
|
-
return B ? B.owned(el) : null;
|
|
927
|
-
};
|
|
928
|
-
const applyOwned = (oldEl, name, value, owned) => owned === null ? undefined : tierLoads.bind.r.apply(oldEl, name, value, owned);
|
|
929
|
-
function morphAttributes(oldEl, newEl, claim) {
|
|
930
|
-
let reclaim = false;
|
|
931
|
-
let changed = false;
|
|
932
|
-
const keepOpen = preservesOpen(oldEl);
|
|
933
|
-
const owned = ownedPositions(newEl);
|
|
934
|
-
const oldAttrs = oldEl.attributes;
|
|
935
|
-
for (let i = oldAttrs.length - 1; i >= 0; i--) {
|
|
936
|
-
const name = oldAttrs[i].name;
|
|
937
|
-
if (keepOpen && name === "open") continue;
|
|
938
|
-
if (!newEl.hasAttribute(name)) {
|
|
939
|
-
const handled = applyOwned(oldEl, name, "", owned);
|
|
940
|
-
if (handled !== undefined) {
|
|
941
|
-
changed = handled || changed;
|
|
942
|
-
continue;
|
|
943
|
-
}
|
|
944
|
-
oldEl.removeAttribute(name);
|
|
945
|
-
changed = true;
|
|
946
|
-
reclaim ||= claimedAttr(name);
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
const newAttrs = newEl.attributes;
|
|
950
|
-
for (let i = 0; i < newAttrs.length; i++) {
|
|
951
|
-
const attr = newAttrs[i];
|
|
952
|
-
const name = attr.name;
|
|
953
|
-
if (keepOpen && name === "open") continue;
|
|
954
|
-
const handled = applyOwned(oldEl, name, attr.value, owned);
|
|
955
|
-
if (handled !== undefined) {
|
|
956
|
-
changed = handled || changed;
|
|
957
|
-
continue;
|
|
958
|
-
}
|
|
959
|
-
if (oldEl.getAttribute(name) !== attr.value) {
|
|
960
|
-
oldEl.setAttribute(name, attr.value);
|
|
961
|
-
changed = true;
|
|
962
|
-
reclaim ||= claimedAttr(name);
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
if (claim && (reclaim || changed && oldEl.matches(CLAIMED_ELEMENTS))) claim(oldEl, true);
|
|
966
|
-
}
|
|
967
|
-
function morphNode(oldNode, newNode, claim, ranges, grafts) {
|
|
968
|
-
if (oldNode.nodeType === ELEMENT_NODE) {
|
|
969
|
-
if (oldNode.hasAttribute("data-preserve")) return;
|
|
970
|
-
morphAttributes(oldNode, newNode, claim);
|
|
971
|
-
reconcileChildren(oldNode, newNode, null, null, claim, ranges, grafts);
|
|
972
|
-
} else if (oldNode.data !== newNode.data) {
|
|
973
|
-
oldNode.data = newNode.data;
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
const afterRange = (start, id) => afterMarker(start, slotEnd(id));
|
|
977
|
-
const afterText = start => afterMarker(start, SLOT_TEXT_END);
|
|
978
|
-
function afterMarker(start, end) {
|
|
956
|
+
function findMarker(start, end) {
|
|
979
957
|
let n = start.nextSibling;
|
|
980
958
|
while (n) {
|
|
981
|
-
if (n.nodeType === COMMENT_NODE && n.data === end) return n
|
|
982
|
-
n = n.nextSibling;
|
|
983
|
-
}
|
|
984
|
-
return null;
|
|
985
|
-
}
|
|
986
|
-
function findRangeStart(from, id, bound) {
|
|
987
|
-
const target = `slot:${id}:start`;
|
|
988
|
-
let n = from;
|
|
989
|
-
while (n && n !== bound) {
|
|
990
|
-
if (n.nodeType === COMMENT_NODE && n.data === target) return n;
|
|
991
|
-
n = n.nextSibling;
|
|
992
|
-
}
|
|
993
|
-
return null;
|
|
994
|
-
}
|
|
995
|
-
function moveRangeBefore(parent, start, id, ref) {
|
|
996
|
-
const end = slotEnd(id);
|
|
997
|
-
let n = start;
|
|
998
|
-
while (n) {
|
|
999
|
-
const next = n.nextSibling;
|
|
1000
|
-
const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
|
|
1001
|
-
parent.insertBefore(n, ref);
|
|
1002
|
-
if (isEnd) break;
|
|
1003
|
-
n = next;
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
function placeRange(parent, range, id, ref) {
|
|
1007
|
-
if (range.nodeType === 11 ) {
|
|
1008
|
-
parent.insertBefore(range, ref);
|
|
1009
|
-
} else {
|
|
1010
|
-
moveRangeBefore(parent, range, id, ref);
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
function adoptRange(parent, start, id, ref, claim) {
|
|
1014
|
-
const end = slotEnd(id);
|
|
1015
|
-
let n = start;
|
|
1016
|
-
let after = null;
|
|
1017
|
-
while (n) {
|
|
1018
|
-
const next = n.nextSibling;
|
|
1019
|
-
const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
|
|
1020
|
-
parent.insertBefore(n, ref);
|
|
1021
|
-
if (claim) claim(n);
|
|
1022
|
-
if (isEnd) {
|
|
1023
|
-
after = next;
|
|
1024
|
-
break;
|
|
1025
|
-
}
|
|
1026
|
-
n = next;
|
|
1027
|
-
}
|
|
1028
|
-
return after;
|
|
1029
|
-
}
|
|
1030
|
-
function reconcileChildren(parent, source, boundStart = null, boundEnd = null, claim = null, ranges = null, grafts = null) {
|
|
1031
|
-
let oldChild = boundStart ? boundStart.nextSibling : parent.firstChild;
|
|
1032
|
-
let newChild = source.firstChild;
|
|
1033
|
-
while (newChild) {
|
|
1034
|
-
const nextNew = newChild.nextSibling;
|
|
1035
|
-
const pid = slotStartId(newChild);
|
|
1036
|
-
const old = oldChild === boundEnd ? null : oldChild;
|
|
1037
|
-
if (old && isTextStart(newChild) && old.nodeType === COMMENT_NODE && old.data === newChild.data) {
|
|
1038
|
-
oldChild = afterText(old);
|
|
1039
|
-
newChild = afterText(newChild);
|
|
1040
|
-
continue;
|
|
1041
|
-
}
|
|
1042
|
-
if (pid !== null) {
|
|
1043
|
-
if (old && slotStartId(old) === pid) {
|
|
1044
|
-
oldChild = afterRange(old, pid);
|
|
1045
|
-
newChild = afterRange(newChild, pid);
|
|
1046
|
-
} else {
|
|
1047
|
-
const displaced = ranges && ranges.get(pid);
|
|
1048
|
-
const existing = displaced || findRangeStart(old, pid, boundEnd);
|
|
1049
|
-
if (existing) {
|
|
1050
|
-
if (ranges) ranges.delete(pid);
|
|
1051
|
-
placeRange(parent, existing, pid, old ?? boundEnd);
|
|
1052
|
-
newChild = afterRange(newChild, pid);
|
|
1053
|
-
} else {
|
|
1054
|
-
newChild = adoptRange(parent, newChild, pid, old ?? boundEnd, claim);
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
continue;
|
|
1058
|
-
}
|
|
1059
|
-
if (!old) {
|
|
1060
|
-
parent.insertBefore(newChild, boundEnd);
|
|
1061
|
-
if (claim) claim(newChild);
|
|
1062
|
-
if (grafts) grafts.push(newChild);
|
|
1063
|
-
newChild = nextNew;
|
|
1064
|
-
continue;
|
|
1065
|
-
}
|
|
1066
|
-
if (isSlotMarker(old)) {
|
|
1067
|
-
parent.insertBefore(newChild, old);
|
|
1068
|
-
if (claim) claim(newChild);
|
|
1069
|
-
if (grafts) grafts.push(newChild);
|
|
1070
|
-
newChild = nextNew;
|
|
1071
|
-
continue;
|
|
1072
|
-
}
|
|
1073
|
-
if (compatible(old, newChild)) {
|
|
1074
|
-
morphNode(old, newChild, claim, ranges, grafts);
|
|
1075
|
-
oldChild = old.nextSibling;
|
|
1076
|
-
newChild = nextNew;
|
|
1077
|
-
continue;
|
|
1078
|
-
}
|
|
1079
|
-
if (newChild.nodeType === 1) {
|
|
1080
|
-
let ahead = old.nextSibling;
|
|
1081
|
-
while (ahead && ahead !== boundEnd && !compatible(ahead, newChild)) {
|
|
1082
|
-
const aheadPid = slotStartId(ahead);
|
|
1083
|
-
ahead = aheadPid !== null ? afterRange(ahead, aheadPid) : ahead.nextSibling;
|
|
1084
|
-
}
|
|
1085
|
-
if (ahead && ahead !== boundEnd) {
|
|
1086
|
-
parent.insertBefore(ahead, old);
|
|
1087
|
-
morphNode(ahead, newChild, claim, ranges, grafts);
|
|
1088
|
-
newChild = nextNew;
|
|
1089
|
-
continue;
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
parent.insertBefore(newChild, old);
|
|
1093
|
-
if (claim) claim(newChild);
|
|
1094
|
-
if (grafts) grafts.push(newChild);
|
|
1095
|
-
newChild = nextNew;
|
|
1096
|
-
}
|
|
1097
|
-
while (oldChild && oldChild !== boundEnd) {
|
|
1098
|
-
const next = oldChild.nextSibling;
|
|
1099
|
-
const pid = ranges ? slotStartId(oldChild) : null;
|
|
1100
|
-
if (pid !== null && ranges.get(pid) === oldChild) {
|
|
1101
|
-
const frag = document.createDocumentFragment();
|
|
1102
|
-
const after = stashRange(frag, oldChild, pid);
|
|
1103
|
-
ranges.set(pid, frag);
|
|
1104
|
-
oldChild = after;
|
|
1105
|
-
continue;
|
|
1106
|
-
}
|
|
1107
|
-
parent.removeChild(oldChild);
|
|
1108
|
-
oldChild = next;
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
function flushGrafts(node, ranges) {
|
|
1112
|
-
if (node.nodeType !== ELEMENT_NODE || isFrameElement(node)) return;
|
|
1113
|
-
let n = node.firstChild;
|
|
1114
|
-
while (n) {
|
|
1115
|
-
const id = slotStartId(n);
|
|
1116
|
-
if (id !== null) {
|
|
1117
|
-
const next = afterRange(n, id);
|
|
1118
|
-
const displaced = ranges.get(id);
|
|
1119
|
-
if (displaced) {
|
|
1120
|
-
ranges.delete(id);
|
|
1121
|
-
placeRange(node, displaced, id, n);
|
|
1122
|
-
stashRange(document.createDocumentFragment(), n, id);
|
|
1123
|
-
}
|
|
1124
|
-
n = next;
|
|
1125
|
-
continue;
|
|
1126
|
-
}
|
|
1127
|
-
flushGrafts(n, ranges);
|
|
959
|
+
if (n.nodeType === COMMENT_NODE && n.data === end) return n;
|
|
1128
960
|
n = n.nextSibling;
|
|
1129
961
|
}
|
|
1130
|
-
}
|
|
1131
|
-
function stashRange(frag, start, id) {
|
|
1132
|
-
const end = slotEnd(id);
|
|
1133
|
-
let n = start;
|
|
1134
|
-
while (n) {
|
|
1135
|
-
const next = n.nextSibling;
|
|
1136
|
-
const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
|
|
1137
|
-
frag.appendChild(n);
|
|
1138
|
-
if (isEnd) return next;
|
|
1139
|
-
n = next;
|
|
1140
|
-
}
|
|
1141
962
|
return null;
|
|
1142
963
|
}
|
|
1143
964
|
|
|
@@ -1145,8 +966,17 @@ const RECORDS = Symbol.for("@solidjs/signals/observe/records");
|
|
|
1145
966
|
function records() {
|
|
1146
967
|
return globalThis[RECORDS];
|
|
1147
968
|
}
|
|
1148
|
-
function
|
|
1149
|
-
|
|
969
|
+
function frameRecordCensus(event, message, own) {
|
|
970
|
+
const r = message.r;
|
|
971
|
+
let counted = !r;
|
|
972
|
+
for (const key in r) {
|
|
973
|
+
if (key === ":complete" || key === ":bound") continue;
|
|
974
|
+
counted = true;
|
|
975
|
+
countEvent(event, key === "" ? "html" : key.endsWith(":error") ? "error" : key.startsWith("slot:") ? "slot" : key.startsWith("seg:") && r[key] && r[key].kind === "html" ? "fragment" : key, own);
|
|
976
|
+
}
|
|
977
|
+
if (counted) event.chunks++;
|
|
978
|
+
}
|
|
979
|
+
function countEvent(event, type, own) {
|
|
1150
980
|
switch (type) {
|
|
1151
981
|
case "html":
|
|
1152
982
|
if (!own) event.regions++;else if (event.shellMs === undefined) event.shellMs = performance.now() - event.at;
|
|
@@ -1202,11 +1032,8 @@ function observeFrameApply(response) {
|
|
|
1202
1032
|
return;
|
|
1203
1033
|
}
|
|
1204
1034
|
if (current === undefined) return;
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
return;
|
|
1208
|
-
}
|
|
1209
|
-
frameCensus(current.event, chunk.type, chunk.id === current.applied);
|
|
1035
|
+
frameRecordCensus(current.event, chunk, chunk.id === current.applied);
|
|
1036
|
+
if (chunk.r && ":complete" in chunk.r && chunk.id === current.applied) close("complete");
|
|
1210
1037
|
},
|
|
1211
1038
|
end(error) {
|
|
1212
1039
|
if (current !== undefined) close(error !== undefined ? "error" : "truncated", error);
|
|
@@ -1233,6 +1060,11 @@ async function observedApplyFrameResponse(response, host, options = {}) {
|
|
|
1233
1060
|
observation.end();
|
|
1234
1061
|
return applied;
|
|
1235
1062
|
}
|
|
1063
|
+
const ends = msg => !!msg.r && (":complete" in msg.r || ":error" in msg.r);
|
|
1064
|
+
const readsData = msg => {
|
|
1065
|
+
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;
|
|
1066
|
+
return false;
|
|
1067
|
+
};
|
|
1236
1068
|
function applyFrames(response, host, options = {}, observation) {
|
|
1237
1069
|
const rootId = response.headers.get(FRAME_STREAM_HEADER) ?? "";
|
|
1238
1070
|
response.headers.get(FRAME_TIERS_HEADER)?.split(",").forEach(prepareTier);
|
|
@@ -1242,11 +1074,12 @@ function applyFrames(response, host, options = {}, observation) {
|
|
|
1242
1074
|
const reader = options[LIVE_WIRE] || new ChunkReader(response.body);
|
|
1243
1075
|
const open = new Map();
|
|
1244
1076
|
const errorRecord = (id, error) => ({
|
|
1245
|
-
type: "error",
|
|
1246
1077
|
id,
|
|
1247
1078
|
version: open.get(id),
|
|
1248
|
-
|
|
1249
|
-
|
|
1079
|
+
r: {
|
|
1080
|
+
":error": {
|
|
1081
|
+
message: String(error && error.message)
|
|
1082
|
+
}
|
|
1250
1083
|
}
|
|
1251
1084
|
});
|
|
1252
1085
|
const drain = async () => {
|
|
@@ -1263,10 +1096,10 @@ function applyFrames(response, host, options = {}, observation) {
|
|
|
1263
1096
|
if (v === undefined) perFrame.set(chunk.id, v = version(chunk.id));
|
|
1264
1097
|
chunk.version = v;
|
|
1265
1098
|
} else if (version !== undefined) chunk.version = version;
|
|
1266
|
-
if (chunk.type === "start") open.set(chunk.id, chunk.version);else if (chunk
|
|
1099
|
+
if (chunk.type === "start") open.set(chunk.id, chunk.version);else if (ends(chunk)) open.delete(chunk.id);
|
|
1267
1100
|
if (observation) observation.chunk(chunk, wireId);
|
|
1268
1101
|
const needs = chunk.tiers?.map(prepareTier) || [];
|
|
1269
|
-
if (chunk.type === "data" ||
|
|
1102
|
+
if (chunk.type === "data" || readsData(chunk)) await Promise.all([host.prepareData?.(), ...needs]);
|
|
1270
1103
|
host.apply(chunk);
|
|
1271
1104
|
}
|
|
1272
1105
|
result = await reader.next();
|
|
@@ -1426,7 +1259,7 @@ function createServerComponentHandler({
|
|
|
1426
1259
|
return {
|
|
1427
1260
|
intercept: intercept && (info => {
|
|
1428
1261
|
const hit = intercept(info);
|
|
1429
|
-
if (hit === undefined) return
|
|
1262
|
+
if (hit === undefined) return void prepareMorph();
|
|
1430
1263
|
const address = frameAddress(info.id, info.args);
|
|
1431
1264
|
if (!info.meta?.live) calls.set(address, info);
|
|
1432
1265
|
const binding = () => bindingFor(address, info.id);
|
|
@@ -1451,17 +1284,23 @@ function createServerComponentHandler({
|
|
|
1451
1284
|
calls.set(address, ctx);
|
|
1452
1285
|
const version = bump(address);
|
|
1453
1286
|
const entry = showing(address) ? stage(address, binding, version) : undefined;
|
|
1454
|
-
if (!entry)
|
|
1287
|
+
if (!entry) host.apply({
|
|
1288
|
+
type: "start",
|
|
1289
|
+
id: address,
|
|
1290
|
+
version,
|
|
1291
|
+
startedAt: ctx.startedAt
|
|
1292
|
+
}) ;
|
|
1455
1293
|
const target = entry || host;
|
|
1456
1294
|
const applied = applyFrameResponse(response, target, {
|
|
1457
1295
|
as: address,
|
|
1458
|
-
version
|
|
1296
|
+
version: frameId => frameId === address ? version : bump(frameId)
|
|
1459
1297
|
}).catch(err => target.apply({
|
|
1460
|
-
type: "error",
|
|
1461
1298
|
id: address,
|
|
1462
1299
|
version,
|
|
1463
|
-
|
|
1464
|
-
|
|
1300
|
+
r: {
|
|
1301
|
+
":error": {
|
|
1302
|
+
message: String(err && err.message)
|
|
1303
|
+
}
|
|
1465
1304
|
}
|
|
1466
1305
|
}));
|
|
1467
1306
|
return entry ? applied.then(() => settled(address, binding)) : binding;
|
|
@@ -1519,6 +1358,10 @@ function createServerComponentHandler({
|
|
|
1519
1358
|
}
|
|
1520
1359
|
}
|
|
1521
1360
|
|
|
1361
|
+
const setWriteHook = core.setWriteHook;
|
|
1362
|
+
const setSignalIdentities = core.setSignalIdentities;
|
|
1363
|
+
const signalName = core.signalName;
|
|
1364
|
+
const storeName = core.storeName;
|
|
1522
1365
|
const createLoadingBoundary = core.createLoadingBoundary;
|
|
1523
1366
|
const sharedConfig = core.sharedConfig;
|
|
1524
1367
|
|
|
@@ -1526,7 +1369,6 @@ const TRACE_STATE = Symbol.for("solid.container-trace-state");
|
|
|
1526
1369
|
tierLoaders.trace = () => import('@solidjs/web/frames/trace');
|
|
1527
1370
|
tierLoaders.regions = () => import('@solidjs/web/frames/regions');
|
|
1528
1371
|
tierLoaders.assets = () => import('@solidjs/web/frames/assets');
|
|
1529
|
-
tierLoaders.bind = () => import('@solidjs/web/frames/bind');
|
|
1530
1372
|
tierLoaders.wire = () => import('@solidjs/web/frames/wire');
|
|
1531
1373
|
function asyncArg(value) {
|
|
1532
1374
|
return value;
|
|
@@ -1558,23 +1400,26 @@ function followAddress(host, frame, binding) {
|
|
|
1558
1400
|
});
|
|
1559
1401
|
}
|
|
1560
1402
|
function landing(host, address, value, failed) {
|
|
1561
|
-
let thrown
|
|
1403
|
+
let frame, thrown;
|
|
1404
|
+
const errored = () => (frame = host.get(address))?.error !== undefined && (thrown === (thrown = frame.version) ? 1 : 2);
|
|
1405
|
+
errored();
|
|
1562
1406
|
return createMemo(() => {
|
|
1563
1407
|
failed();
|
|
1564
|
-
const
|
|
1565
|
-
if (
|
|
1566
|
-
thrown = error;
|
|
1567
|
-
throw error;
|
|
1568
|
-
}
|
|
1408
|
+
const state = errored();
|
|
1409
|
+
if (state > 1) throw frame.error;
|
|
1569
1410
|
const wait = host.landing(address);
|
|
1570
1411
|
if (!wait) return value;
|
|
1571
|
-
const
|
|
1572
|
-
|
|
1412
|
+
const landed = (state ? reask(address, wait) : wait).then(() => value);
|
|
1413
|
+
if (!state) {
|
|
1414
|
+
const origin = OBSERVE.attribution.flightOrigin(wait);
|
|
1415
|
+
if (origin !== undefined) OBSERVE.attribution.markFlight(landed, origin);
|
|
1416
|
+
}
|
|
1417
|
+
return landed;
|
|
1573
1418
|
});
|
|
1574
1419
|
}
|
|
1575
|
-
function reask(address) {
|
|
1420
|
+
function reask(address, wait) {
|
|
1576
1421
|
const call = callFor(address);
|
|
1577
|
-
return call
|
|
1422
|
+
return call ? call.retry().then(() => wait) : wait;
|
|
1578
1423
|
}
|
|
1579
1424
|
function failing() {
|
|
1580
1425
|
const [failed, setFailed] = createSignal(0, {
|
|
@@ -1593,15 +1438,36 @@ function getFrameHost() {
|
|
|
1593
1438
|
}
|
|
1594
1439
|
return sharedHost;
|
|
1595
1440
|
}
|
|
1596
|
-
function
|
|
1441
|
+
function claimScope(el) {
|
|
1442
|
+
const registry = sharedConfig.registry;
|
|
1443
|
+
const buckets = new Map();
|
|
1444
|
+
const bucketOf = key => key.slice(0, key.lastIndexOf("-") + 1);
|
|
1445
|
+
const index = root => {
|
|
1446
|
+
if (registry) for (const n of root.querySelectorAll("[_hk]")) {
|
|
1447
|
+
const p = bucketOf(n.getAttribute("_hk"));
|
|
1448
|
+
const b = buckets.get(p);
|
|
1449
|
+
b ? b.push(n) : buckets.set(p, [n]);
|
|
1450
|
+
}
|
|
1451
|
+
};
|
|
1452
|
+
index(el);
|
|
1453
|
+
return {
|
|
1454
|
+
registry,
|
|
1455
|
+
gather(id) {
|
|
1456
|
+
for (const n of buckets.get(bucketOf(id)) || []) {
|
|
1457
|
+
const k = n.getAttribute("_hk");
|
|
1458
|
+
if (k.startsWith(id) && n.isConnected && !registry.has(k)) registry.set(k, n);
|
|
1459
|
+
}
|
|
1460
|
+
},
|
|
1461
|
+
index
|
|
1462
|
+
};
|
|
1463
|
+
}
|
|
1464
|
+
function claimRender(prefix, owner, existing, render, scope, bound) {
|
|
1597
1465
|
const sc = sharedConfig;
|
|
1598
|
-
if (!sc.hydrateWindow || !sc.registry) return render
|
|
1466
|
+
if (!sc.hydrateWindow || !sc.registry) return runWithOwner(owner, render);
|
|
1599
1467
|
const prevRoots = sc.claimRoots;
|
|
1600
1468
|
sc.claimRoots = existing;
|
|
1601
1469
|
try {
|
|
1602
|
-
return runWithOwner(
|
|
1603
|
-
id: prefix
|
|
1604
|
-
}), () => sc.hydrateWindow(bound ? undefined : prefix, render, scope));
|
|
1470
|
+
return runWithOwner(owner, () => sc.hydrateWindow(bound ? undefined : prefix, render, scope));
|
|
1605
1471
|
} finally {
|
|
1606
1472
|
sc.claimRoots = prevRoots;
|
|
1607
1473
|
}
|
|
@@ -1652,6 +1518,7 @@ function slotArgsProxy(args) {
|
|
|
1652
1518
|
reads.set(key, read);
|
|
1653
1519
|
}
|
|
1654
1520
|
const v = read();
|
|
1521
|
+
if (v instanceof Element) tierLoads.regions.r.place(v);
|
|
1655
1522
|
return v instanceof Boxed ? v.c : v;
|
|
1656
1523
|
},
|
|
1657
1524
|
has: (_, key) => key in args(),
|
|
@@ -1667,40 +1534,24 @@ function slotsFor(props, scope) {
|
|
|
1667
1534
|
return new Proxy({}, {
|
|
1668
1535
|
get(_, prop) {
|
|
1669
1536
|
if (typeof prop !== "string" || !(prop in props)) return undefined;
|
|
1670
|
-
|
|
1537
|
+
const mount = (slotProps, ctx) => {
|
|
1671
1538
|
const key = ctx && ctx.key;
|
|
1672
1539
|
const prevFill = key !== undefined && fillScopes.get(key);
|
|
1673
1540
|
if (prevFill) {
|
|
1674
1541
|
fillScopes.delete(key);
|
|
1675
1542
|
prevFill.dispose();
|
|
1676
1543
|
}
|
|
1677
|
-
if (ctx && ctx.positions) {
|
|
1678
|
-
const fill = props[prop];
|
|
1679
|
-
if (typeof fill !== "function") {
|
|
1680
|
-
return undefined;
|
|
1681
|
-
}
|
|
1682
|
-
const owner = createOwner();
|
|
1683
|
-
fillScopes.set(key, owner);
|
|
1684
|
-
ctx.onCleanup(() => {
|
|
1685
|
-
if (fillScopes.get(key) === owner) fillScopes.delete(key);
|
|
1686
|
-
owner.dispose();
|
|
1687
|
-
});
|
|
1688
|
-
runWithOwner(owner, () => {
|
|
1689
|
-
const args = ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotArgsProxy(() => slotProps);
|
|
1690
|
-
tierLoads.bind.r.bind(fill, args, ctx, undefined);
|
|
1691
|
-
});
|
|
1692
|
-
return undefined;
|
|
1693
|
-
}
|
|
1694
1544
|
const range = ctx && ctx.range;
|
|
1695
1545
|
if (!range) return undefined;
|
|
1696
1546
|
const fillOwner = streamInvoke ? createOwner() : null;
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1547
|
+
const owner = fillOwner || createOwner({
|
|
1548
|
+
transparent: true
|
|
1549
|
+
});
|
|
1550
|
+
fillScopes.set(key, owner);
|
|
1551
|
+
ctx.onCleanup(() => {
|
|
1552
|
+
if (fillScopes.get(key) === owner) fillScopes.delete(key);
|
|
1553
|
+
owner.dispose();
|
|
1554
|
+
});
|
|
1704
1555
|
const evaluate = () => {
|
|
1705
1556
|
const v = props[prop];
|
|
1706
1557
|
if (typeof v === "function" && ctx && ctx.invoked) {
|
|
@@ -1711,22 +1562,19 @@ function slotsFor(props, scope) {
|
|
|
1711
1562
|
};
|
|
1712
1563
|
const adopted = !!(ctx && ctx.frame && ctx.adopted && ctx.existing && ctx.existing.length);
|
|
1713
1564
|
const prefix = ctx && ctx.frame ? `sc-${ctx.frame}-${ctx.key}-` : "";
|
|
1714
|
-
const
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
if (!fillOwner) {
|
|
1719
|
-
fillScopes.set(key, owner);
|
|
1720
|
-
ctx.onCleanup(() => {
|
|
1721
|
-
if (fillScopes.get(key) === owner) fillScopes.delete(key);
|
|
1722
|
-
owner.dispose();
|
|
1723
|
-
});
|
|
1724
|
-
}
|
|
1565
|
+
const claim = adopted && runWithOwner(owner, () => createOwner({
|
|
1566
|
+
id: prefix
|
|
1567
|
+
}));
|
|
1568
|
+
const value = adopted ? claimRender(prefix, claim, ctx.existing, evaluate, scope) : fillOwner ? runWithOwner(fillOwner, evaluate) : evaluate();
|
|
1725
1569
|
const end = range.end;
|
|
1726
1570
|
const bind = () => insert(end.parentNode, value, end, [...ctx.existing]);
|
|
1727
|
-
|
|
1571
|
+
adopted ? claimRender(prefix, claim, ctx.existing, bind, scope, true) : runWithOwner(owner, bind);
|
|
1728
1572
|
return undefined;
|
|
1729
1573
|
};
|
|
1574
|
+
return (slotProps, ctx) => {
|
|
1575
|
+
const R = tierLoads.regions?.r;
|
|
1576
|
+
R ? R.nest(mount, slotProps, ctx) : mount(slotProps, ctx);
|
|
1577
|
+
};
|
|
1730
1578
|
}
|
|
1731
1579
|
});
|
|
1732
1580
|
}
|
|
@@ -1780,7 +1628,12 @@ function pumpLiveChannel() {
|
|
|
1780
1628
|
const pump = () => reader.read().then(r => {
|
|
1781
1629
|
if (r.done) return;
|
|
1782
1630
|
const op = r.value;
|
|
1783
|
-
for (const
|
|
1631
|
+
for (const key in op.r) liveOps.set(`${op.fid || ""}:${key}`, {
|
|
1632
|
+
fid: op.fid,
|
|
1633
|
+
r: {
|
|
1634
|
+
[key]: op.r[key]
|
|
1635
|
+
}
|
|
1636
|
+
});
|
|
1784
1637
|
for (const apply of liveAppliers) apply(op);
|
|
1785
1638
|
return pump();
|
|
1786
1639
|
});
|
|
@@ -1795,12 +1648,19 @@ function indexBoundaries(root) {
|
|
|
1795
1648
|
if (key && isBoundaryId(key) && !boundaryIndex.has(key)) boundaryIndex.set(key, el);
|
|
1796
1649
|
});
|
|
1797
1650
|
}
|
|
1798
|
-
function findBoundaryElement(id) {
|
|
1651
|
+
function findBoundaryElement(id, address) {
|
|
1799
1652
|
if (!boundaryIndex) {
|
|
1800
1653
|
boundaryIndex = new Map();
|
|
1801
1654
|
if (typeof document !== "undefined" && document.body) indexBoundaries(document.body);
|
|
1802
1655
|
}
|
|
1803
|
-
|
|
1656
|
+
const args = address && address.slice(id.length + 1);
|
|
1657
|
+
let first, el;
|
|
1658
|
+
for (let n = 0;; n++) {
|
|
1659
|
+
const key = n ? id + "~" + (n + 1) : id;
|
|
1660
|
+
if (claimedBoundaries.has(key)) continue;
|
|
1661
|
+
if (!(el = boundaryIndex.get(key)) || !args || el.dataset.fa == args) return el || first;
|
|
1662
|
+
first = first || el;
|
|
1663
|
+
}
|
|
1804
1664
|
}
|
|
1805
1665
|
const arrivals = new Map();
|
|
1806
1666
|
const FRAME_SELECTOR = `[${FRAME_ID_ATTR}]`;
|
|
@@ -1810,19 +1670,32 @@ function awaitBoundary(id) {
|
|
|
1810
1670
|
if (!arrival) {
|
|
1811
1671
|
let resolve;
|
|
1812
1672
|
const promise = new Promise(r => resolve = r);
|
|
1673
|
+
if (!resolve) return promise;
|
|
1813
1674
|
arrivals.set(id, arrival = {
|
|
1814
1675
|
promise,
|
|
1815
1676
|
resolve
|
|
1816
1677
|
});
|
|
1678
|
+
onHydrationEnd(releaseArrivals);
|
|
1817
1679
|
}
|
|
1818
1680
|
return arrival.promise;
|
|
1819
1681
|
}
|
|
1682
|
+
function releaseArrivals() {
|
|
1683
|
+
if (!arrivals.size) return;
|
|
1684
|
+
const exhausted = !boundaryMayArrive();
|
|
1685
|
+
for (const [id, arrival] of arrivals) {
|
|
1686
|
+
const el = boundaryIndex && boundaryIndex.get(id);
|
|
1687
|
+
if (!el && !exhausted) continue;
|
|
1688
|
+
arrivals.delete(id);
|
|
1689
|
+
arrival.resolve(!!el);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1820
1692
|
function boundaryMayArrive() {
|
|
1821
1693
|
const hy = globalThis._$HY;
|
|
1822
1694
|
if (!hy) return false;
|
|
1823
|
-
return !hy.done || !!(hy.fr && hy.fr.pending());
|
|
1695
|
+
return !(hy.done || sharedConfig.done) || !!(hy.fr && hy.fr.pending());
|
|
1824
1696
|
}
|
|
1825
1697
|
function installRevealHook() {
|
|
1698
|
+
installServerComponentHydration();
|
|
1826
1699
|
const hy = globalThis._$HY;
|
|
1827
1700
|
if (!hy || hy.$sc || !hy.fr) return;
|
|
1828
1701
|
hy.$sc = true;
|
|
@@ -1834,51 +1707,49 @@ function installRevealHook() {
|
|
|
1834
1707
|
if (!boundaryIndex) return;
|
|
1835
1708
|
const root = parent || (typeof document !== "undefined" ? document.body : null);
|
|
1836
1709
|
if (root) indexBoundaries(root);
|
|
1837
|
-
|
|
1838
|
-
const exhausted = hy.done && !hy.fr.pending();
|
|
1839
|
-
for (const [id, arrival] of arrivals) {
|
|
1840
|
-
const el = boundaryIndex && boundaryIndex.get(id);
|
|
1841
|
-
if (!el && !exhausted) continue;
|
|
1842
|
-
arrivals.delete(id);
|
|
1843
|
-
arrival.resolve(!!el);
|
|
1844
|
-
}
|
|
1710
|
+
releaseArrivals();
|
|
1845
1711
|
});
|
|
1846
1712
|
}
|
|
1847
1713
|
function documentBoundary(host, id, props, binding) {
|
|
1848
1714
|
installRevealHook();
|
|
1849
|
-
const
|
|
1850
|
-
const el =
|
|
1715
|
+
const address = binding && contentAddress(binding());
|
|
1716
|
+
const el = findBoundaryElement(id, address);
|
|
1851
1717
|
if (el) return adoptBoundary(host, id, el, props, binding);
|
|
1852
|
-
if (!
|
|
1718
|
+
if (!claimedBoundaries.has(id) && boundaryMayArrive()) {
|
|
1853
1719
|
const owner = getOwner();
|
|
1854
1720
|
let live = true;
|
|
1855
1721
|
onCleanup(() => live = false);
|
|
1856
1722
|
return createMemo(() => awaitBoundary(id).then(() => live && runWithOwner(owner, () => {
|
|
1857
|
-
const node =
|
|
1723
|
+
const node = findBoundaryElement(id, address);
|
|
1858
1724
|
return node ? adoptBoundary(host, id, node, props, binding) : boundaryComponent(host, id)(props, binding);
|
|
1859
1725
|
})));
|
|
1860
1726
|
}
|
|
1861
1727
|
return boundaryComponent(host, id)(props, binding);
|
|
1862
1728
|
}
|
|
1863
1729
|
function adoptBoundary(host, id, el, props, binding) {
|
|
1864
|
-
|
|
1730
|
+
const siteId = el.getAttribute(FRAME_ID_ATTR);
|
|
1731
|
+
claimedBoundaries.add(siteId);
|
|
1732
|
+
edgeRoots.set(siteId, el);
|
|
1865
1733
|
const address = binding ? contentAddress(binding()) : id;
|
|
1866
1734
|
const appliedRecords = new Set();
|
|
1867
1735
|
const drainRecords = () => {
|
|
1868
1736
|
const hy = globalThis._$HY;
|
|
1869
1737
|
if (!hy || !hy.r) return;
|
|
1870
1738
|
pumpLiveChannel();
|
|
1871
|
-
const slotPrefix = `sc:slot:${
|
|
1739
|
+
const slotPrefix = `sc:slot:${siteId}:`;
|
|
1872
1740
|
for (const key of Object.keys(hy.r)) {
|
|
1873
1741
|
if (appliedRecords.has(key)) continue;
|
|
1874
1742
|
if (key.startsWith(slotPrefix)) {
|
|
1875
1743
|
appliedRecords.add(key);
|
|
1876
1744
|
const apply = args => host.apply({
|
|
1877
|
-
type: "slot",
|
|
1878
1745
|
id: address,
|
|
1879
1746
|
version: 0,
|
|
1880
|
-
|
|
1881
|
-
|
|
1747
|
+
r: {
|
|
1748
|
+
[`slot:${key.slice(slotPrefix.length)}`]: {
|
|
1749
|
+
kind: "slot",
|
|
1750
|
+
args
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1882
1753
|
});
|
|
1883
1754
|
const value = hy.r[key];
|
|
1884
1755
|
if (value && typeof value.then === "function") {
|
|
@@ -1886,24 +1757,30 @@ function adoptBoundary(host, id, el, props, binding) {
|
|
|
1886
1757
|
} else apply(value);
|
|
1887
1758
|
} else if (key.startsWith("sc:region:")) {
|
|
1888
1759
|
const childId = key.slice("sc:region:".length);
|
|
1889
|
-
if (childId.startsWith(
|
|
1760
|
+
if (childId.startsWith(siteId + ".")) {
|
|
1890
1761
|
appliedRecords.add(key);
|
|
1891
1762
|
const val = hy.r[key];
|
|
1892
1763
|
const apply = html => host.apply({
|
|
1893
|
-
type: "html",
|
|
1894
1764
|
id: childId,
|
|
1895
1765
|
version: 0,
|
|
1896
|
-
|
|
1766
|
+
r: {
|
|
1767
|
+
"": {
|
|
1768
|
+
kind: "html",
|
|
1769
|
+
value: html
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1897
1772
|
});
|
|
1898
1773
|
val && typeof val.then === "function" ? val.then(apply) : apply(val);
|
|
1899
1774
|
}
|
|
1900
1775
|
}
|
|
1901
1776
|
}
|
|
1902
1777
|
};
|
|
1778
|
+
const scope = claimScope(el);
|
|
1903
1779
|
const fr = globalThis._$HY?.fr;
|
|
1904
1780
|
let frame;
|
|
1905
1781
|
const unsubscribe = fr ? fr.subscribe((_fragId, parent) => {
|
|
1906
1782
|
const inside = !!parent && el.contains(parent);
|
|
1783
|
+
inside && scope.index(parent);
|
|
1907
1784
|
drainRecords();
|
|
1908
1785
|
if (inside && frame) frame.apply({
|
|
1909
1786
|
version: frame.version ?? 0,
|
|
@@ -1911,11 +1788,11 @@ function adoptBoundary(host, id, el, props, binding) {
|
|
|
1911
1788
|
});
|
|
1912
1789
|
}) : undefined;
|
|
1913
1790
|
const applyLiveOp = op => {
|
|
1914
|
-
if (op.fid && op.fid !==
|
|
1791
|
+
if (op.fid && op.fid !== siteId) return;
|
|
1915
1792
|
host.apply({
|
|
1916
|
-
...op,
|
|
1917
1793
|
id: address,
|
|
1918
|
-
version: 0
|
|
1794
|
+
version: 0,
|
|
1795
|
+
r: op.r
|
|
1919
1796
|
});
|
|
1920
1797
|
};
|
|
1921
1798
|
liveAppliers.add(applyLiveOp);
|
|
@@ -1930,18 +1807,16 @@ function adoptBoundary(host, id, el, props, binding) {
|
|
|
1930
1807
|
const [failed, onApply] = failing();
|
|
1931
1808
|
frame = createFrame(el, {
|
|
1932
1809
|
adopt: true,
|
|
1810
|
+
defer: true,
|
|
1933
1811
|
host,
|
|
1934
1812
|
id: address,
|
|
1935
|
-
slots: slotsFor(props,
|
|
1936
|
-
registry: sc.registry,
|
|
1937
|
-
gather: sc.gather
|
|
1938
|
-
}),
|
|
1813
|
+
slots: slotsFor(props, scope),
|
|
1939
1814
|
ownerScope: boundaryScope(owner),
|
|
1940
1815
|
reveal: revealSeam(owner),
|
|
1941
1816
|
onApply,
|
|
1942
|
-
hold: () => sc.isHydrationInProgress?.() ? runWithOwner(owner, () => untrack(() => sc.holdBoundary("sc:" +
|
|
1817
|
+
hold: () => sc.isHydrationInProgress?.() ? runWithOwner(owner, () => untrack(() => sc.holdBoundary("sc:" + siteId))) : () => {},
|
|
1943
1818
|
...{
|
|
1944
|
-
claimScope:
|
|
1819
|
+
claimScope: siteId
|
|
1945
1820
|
}
|
|
1946
1821
|
});
|
|
1947
1822
|
if (binding) {
|
|
@@ -1956,6 +1831,163 @@ function adoptBoundary(host, id, el, props, binding) {
|
|
|
1956
1831
|
});
|
|
1957
1832
|
return el;
|
|
1958
1833
|
}
|
|
1834
|
+
const DEFER_EVENTS = ["click", "input", "change", "keydown", "pointerdown", "submit", "focusin"];
|
|
1835
|
+
const DEFER_BUDGET = 8;
|
|
1836
|
+
let mounting = false;
|
|
1837
|
+
const idleTick = () => new Promise(r => typeof requestIdleCallback === "function" ? requestIdleCallback(() => r(), {
|
|
1838
|
+
timeout: 100
|
|
1839
|
+
}) : setTimeout(r, 0));
|
|
1840
|
+
function wakeAt(e) {
|
|
1841
|
+
const target = e.target;
|
|
1842
|
+
if (!target || mounting) return;
|
|
1843
|
+
mounting = true;
|
|
1844
|
+
try {
|
|
1845
|
+
for (let f; (f = liveFrameAt(target)) && f.mountEnclosing(target););
|
|
1846
|
+
} finally {
|
|
1847
|
+
mounting = false;
|
|
1848
|
+
}
|
|
1849
|
+
deferDone();
|
|
1850
|
+
}
|
|
1851
|
+
function mountAllDeferred() {
|
|
1852
|
+
if (mounting || sharedConfig.hydrating) return;
|
|
1853
|
+
mounting = true;
|
|
1854
|
+
try {
|
|
1855
|
+
for (let frames; (frames = deferredFrames()).length;) for (const f of frames) f.mountDeferred();
|
|
1856
|
+
} finally {
|
|
1857
|
+
mounting = false;
|
|
1858
|
+
}
|
|
1859
|
+
deferDone();
|
|
1860
|
+
}
|
|
1861
|
+
const edgeRoots = new Map();
|
|
1862
|
+
let edgeIndex;
|
|
1863
|
+
const DEPS = "sc:deps:";
|
|
1864
|
+
function buildEdgeIndex() {
|
|
1865
|
+
const r = globalThis._$HY?.r;
|
|
1866
|
+
if (!r) return undefined;
|
|
1867
|
+
const idx = {
|
|
1868
|
+
readers: new Map(),
|
|
1869
|
+
wide: new Set(),
|
|
1870
|
+
untracked: [],
|
|
1871
|
+
sites: new Set(),
|
|
1872
|
+
starts: new Map()
|
|
1873
|
+
};
|
|
1874
|
+
for (const site of edgeRoots.keys()) for (let n = 0, batch; batch = r[DEPS + site + ":" + n]; n++) {
|
|
1875
|
+
if (typeof batch !== "object") return undefined;
|
|
1876
|
+
idx.sites.add(site);
|
|
1877
|
+
for (const sid in batch) {
|
|
1878
|
+
const occs = unpackOccurrences(batch[sid]);
|
|
1879
|
+
if (sid === "*") occs.forEach(w => idx.wide.add(w));else if (sid === "!") occs.forEach(o => idx.untracked.push([site, o]));else {
|
|
1880
|
+
let list = idx.readers.get(sid);
|
|
1881
|
+
if (!list) idx.readers.set(sid, list = []);
|
|
1882
|
+
for (const o of occs) list.push([site, o]);
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
return idx;
|
|
1887
|
+
}
|
|
1888
|
+
function unpackOccurrences(packed) {
|
|
1889
|
+
const out = [];
|
|
1890
|
+
for (const part of packed.split(" ")) {
|
|
1891
|
+
const m = /^(.*)#(\d+)-(\d+)$/.exec(part);
|
|
1892
|
+
if (!m) part && out.push(part);else for (let i = +m[2]; i <= +m[3]; i++) out.push(m[1] + "#" + i);
|
|
1893
|
+
}
|
|
1894
|
+
return out;
|
|
1895
|
+
}
|
|
1896
|
+
function startOf(idx, site, occ) {
|
|
1897
|
+
let m = idx.starts.get(site);
|
|
1898
|
+
if (!m) {
|
|
1899
|
+
idx.starts.set(site, m = new Map());
|
|
1900
|
+
const root = edgeRoots.get(site);
|
|
1901
|
+
if (root) {
|
|
1902
|
+
const w = document.createTreeWalker(root, 128 );
|
|
1903
|
+
for (let c = w.nextNode(); c; c = w.nextNode()) {
|
|
1904
|
+
const d = c.data;
|
|
1905
|
+
if (d.startsWith("slot:") && d.endsWith(":start")) m.set(d.slice(5, -6), c);
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
return m.get(occ);
|
|
1910
|
+
}
|
|
1911
|
+
function edgesCover(idx) {
|
|
1912
|
+
outer: for (const f of deferredFrames()) {
|
|
1913
|
+
for (const [site, root] of edgeRoots) if (idx.sites.has(site) && root.contains(f.el)) continue outer;
|
|
1914
|
+
return false;
|
|
1915
|
+
}
|
|
1916
|
+
return true;
|
|
1917
|
+
}
|
|
1918
|
+
function mountForWrite(node) {
|
|
1919
|
+
if (mounting || sharedConfig.hydrating) return;
|
|
1920
|
+
const sid = signalName(node) ?? storeName(node);
|
|
1921
|
+
if (sid === undefined || document.readyState === "loading") return mountAllDeferred();
|
|
1922
|
+
const idx = edgeIndex ||= buildEdgeIndex();
|
|
1923
|
+
if (!idx || idx.wide.has(sid) || !edgesCover(idx)) return mountAllDeferred();
|
|
1924
|
+
const readers = idx.readers.get(sid);
|
|
1925
|
+
if (!readers && !idx.untracked.length) return;
|
|
1926
|
+
mounting = true;
|
|
1927
|
+
try {
|
|
1928
|
+
for (const list of [readers || [], idx.untracked]) for (const [site, occ] of list) {
|
|
1929
|
+
const root = edgeRoots.get(site);
|
|
1930
|
+
if (root && deferredFrames().some(f => root.contains(f.el) && f.mountOccurrence(occ))) continue;
|
|
1931
|
+
const start = startOf(idx, site, occ);
|
|
1932
|
+
const target = start && (start.nextSibling || start);
|
|
1933
|
+
if (target) for (let f; (f = liveFrameAt(target)) && f.mountEnclosing(target););
|
|
1934
|
+
}
|
|
1935
|
+
} finally {
|
|
1936
|
+
mounting = false;
|
|
1937
|
+
}
|
|
1938
|
+
deferDone();
|
|
1939
|
+
}
|
|
1940
|
+
let idlePass;
|
|
1941
|
+
function mountIdle() {
|
|
1942
|
+
return idlePass ||= (async () => {
|
|
1943
|
+
if (document.readyState !== "complete") await new Promise(r => addEventListener("load", r, {
|
|
1944
|
+
once: true
|
|
1945
|
+
}));
|
|
1946
|
+
globalThis._$HY?.r?.["sc:tiers"]?.forEach(prepareTier);
|
|
1947
|
+
await Promise.all(Object.values(tierLoads)).catch(() => {});
|
|
1948
|
+
for (let frames; (frames = deferredFrames()).length;) {
|
|
1949
|
+
await idleTick();
|
|
1950
|
+
const deadline = performance.now() + DEFER_BUDGET;
|
|
1951
|
+
mounting = true;
|
|
1952
|
+
try {
|
|
1953
|
+
for (const f of frames) if (!f.mountDeferred(deadline) || performance.now() > deadline) break;
|
|
1954
|
+
} finally {
|
|
1955
|
+
mounting = false;
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
idlePass = undefined;
|
|
1959
|
+
deferDone();
|
|
1960
|
+
})();
|
|
1961
|
+
}
|
|
1962
|
+
function deferDone() {
|
|
1963
|
+
if (deferredFrames().length) return;
|
|
1964
|
+
if (deferring) {
|
|
1965
|
+
deferring = false;
|
|
1966
|
+
edgeIndex = undefined;
|
|
1967
|
+
setWriteHook(null);
|
|
1968
|
+
DEFER_EVENTS.forEach(t => document.removeEventListener(t, wakeAt, true));
|
|
1969
|
+
}
|
|
1970
|
+
releaseDeferHolds();
|
|
1971
|
+
}
|
|
1972
|
+
let deferHydration = true;
|
|
1973
|
+
function setDeferredHydration(on) {
|
|
1974
|
+
deferHydration = on;
|
|
1975
|
+
setDeferDriver(on && typeof document !== "undefined" ? deferFrame : null);
|
|
1976
|
+
setSignalIdentities(on && typeof document !== "undefined");
|
|
1977
|
+
}
|
|
1978
|
+
let deferring = false;
|
|
1979
|
+
function deferFrame(frame) {
|
|
1980
|
+
if (!deferring) {
|
|
1981
|
+
deferring = true;
|
|
1982
|
+
setWriteHook(mountForWrite);
|
|
1983
|
+
DEFER_EVENTS.forEach(t => document.addEventListener(t, wakeAt, true));
|
|
1984
|
+
}
|
|
1985
|
+
const queued = sharedConfig.events;
|
|
1986
|
+
if (queued && queued.length) for (const [el, e] of queued) if (frame.el.contains(el)) wakeAt({
|
|
1987
|
+
target: e.target ?? el
|
|
1988
|
+
});
|
|
1989
|
+
mountIdle();
|
|
1990
|
+
}
|
|
1959
1991
|
function installServerComponents(host = getFrameHost(), options) {
|
|
1960
1992
|
const g = globalThis;
|
|
1961
1993
|
Object.assign(tierLoaders, options?.tiers);
|
|
@@ -1981,15 +2013,18 @@ function installServerComponents(host = getFrameHost(), options) {
|
|
|
1981
2013
|
}
|
|
1982
2014
|
g._$SC.impl = (id, props, binding) => documentBoundary(host, id, props, binding);
|
|
1983
2015
|
installRevealHook();
|
|
2016
|
+
if (typeof document !== "undefined" && deferHydration) {
|
|
2017
|
+
setDeferDriver(deferFrame);
|
|
2018
|
+
setSignalIdentities(true);
|
|
2019
|
+
}
|
|
1984
2020
|
const handler = createServerComponentHandler({
|
|
1985
2021
|
host,
|
|
1986
2022
|
component: fnId => g._$SC.r(fnId),
|
|
1987
2023
|
intercept: ({
|
|
1988
2024
|
id
|
|
1989
2025
|
}) => {
|
|
1990
|
-
if (claimedBoundaries.has(id)) return undefined;
|
|
1991
2026
|
if (findBoundaryElement(id)) return true;
|
|
1992
|
-
if (!boundaryMayArrive()) return undefined;
|
|
2027
|
+
if (claimedBoundaries.has(id) || !boundaryMayArrive()) return undefined;
|
|
1993
2028
|
installRevealHook();
|
|
1994
2029
|
return awaitBoundary(id);
|
|
1995
2030
|
}
|
|
@@ -2003,4 +2038,4 @@ function installServerComponents(host = getFrameHost(), options) {
|
|
|
2003
2038
|
});
|
|
2004
2039
|
}
|
|
2005
2040
|
|
|
2006
|
-
export { FRAME_APPLIED_EVENT, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents,
|
|
2041
|
+
export { FRAME_APPLIED_EVENT, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents, isFrameStreamResponse, setDeferredHydration };
|