@solidjs/web 2.0.0-rc.13 → 2.0.0-rc.14
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/dist/server.dev.js +200 -73
- package/dist/server.js +182 -59
- package/dist/server.observe.js +183 -60
- package/dist/web.dev.js +70 -35
- package/dist/web.js +43 -31
- package/dist/web.observe.js +43 -33
- package/frames/dist/assets.js +92 -0
- package/frames/dist/bind.dev.js +326 -0
- package/frames/dist/bind.js +295 -0
- package/frames/dist/client.dev.js +605 -1086
- package/frames/dist/client.js +572 -1066
- package/frames/dist/client.observe.js +571 -1066
- package/frames/dist/regions.js +130 -0
- package/frames/dist/server.dev.js +339 -177
- package/frames/dist/server.js +335 -173
- package/frames/dist/server.observe.js +335 -173
- package/frames/dist/trace.js +42 -0
- package/frames/dist/wire.js +133 -0
- package/package.json +28 -2
- package/performance-tracks/dist/performance-tracks.dev.js +2 -1
- package/performance-tracks/dist/performance-tracks.observe.js +2 -1
- package/performance-tracks/types/index.d.ts +8 -6
- package/serialization/dist/decode.js +37 -8
- package/serialization/dist/serialization.js +39 -10
- package/serialization/types/serializer-decode.d.ts +24 -2
- package/server-functions/dist/client.dev.js +99 -61
- package/server-functions/dist/client.js +99 -61
- package/server-functions/dist/client.observe.js +99 -61
- package/server-functions/dist/server.dev.js +87 -50
- package/server-functions/dist/server.js +87 -50
- package/server-functions/dist/server.observe.js +87 -50
- package/skills/server-components/SKILL.md +65 -43
- package/types/client.d.ts +20 -0
- package/types/constants.d.ts +2 -1
- package/types/diagnostics.d.ts +8 -0
- package/types/frames/assets-tier.d.ts +78 -0
- package/types/frames/bind-tier.d.ts +60 -0
- package/types/frames/client.d.ts +37 -3
- package/types/frames/frame-client.d.ts +249 -78
- package/types/frames/frame-container-plugin.d.ts +2 -2
- package/types/frames/frame-sink.d.ts +33 -0
- package/types/frames/frame-transport.d.ts +66 -18
- package/types/frames/regions-tier.d.ts +45 -0
- package/types/frames/serializer-decode.d.ts +24 -2
- package/types/frames/server.d.ts +32 -8
- package/types/frames/trace-tier.d.ts +2 -0
- package/types/frames/wire-tier.d.ts +116 -0
- package/types/index.d.ts +38 -0
- package/types/index.server.d.ts +9 -0
- package/types/jsx.d.ts +1 -1
- package/types/observe.d.ts +4 -2
- package/types/serializer-decode.d.ts +24 -2
- package/types/server-functions/client.d.ts +26 -0
- package/types/server-functions/registry.d.ts +4 -1
- package/types/server-functions/shared.d.ts +12 -8
- package/types/server-mock.d.ts +13 -1
- package/types/server.d.ts +34 -8
package/frames/dist/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getOwner, onCleanup, createMemo, runWithOwner,
|
|
2
|
-
import { insert
|
|
3
|
-
import { LIVE_WIRE,
|
|
4
|
-
import {
|
|
1
|
+
import { getOwner, onCleanup, createMemo, runWithOwner, untrack, createRenderEffect, createSignal, createOwner } from 'solid-js';
|
|
2
|
+
import { insert } from '@solidjs/web';
|
|
3
|
+
import { LIVE_WIRE, ChunkReader, frameAddress, SINGLE_FLIGHT_HEADER, deserializeStream, getServerFunctionsCodec, createChunk, deliverFlightData, ERROR_HEADER, hasFlightMetadata, configureServerFunctionsClient } from '@solidjs/web/server-functions/client';
|
|
4
|
+
import { sharedConfig, createLoadingBoundary } from 'solid-js/internal';
|
|
5
5
|
|
|
6
6
|
const ELEMENT_NODE = 1;
|
|
7
7
|
const TEXT_NODE = 3;
|
|
@@ -28,43 +28,16 @@ const SLOT_START = /^slot:(.+):start$/;
|
|
|
28
28
|
const SLOT_END = /^slot:(.+):end$/;
|
|
29
29
|
const slotEnd = id => `slot:${id}:end`;
|
|
30
30
|
const SLOT_MARKER = "_s:";
|
|
31
|
-
|
|
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) {
|
|
32
35
|
const attrs = el.attributes;
|
|
33
|
-
let
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
for (const entry of attr.value.split(",")) {
|
|
39
|
-
const colon = entry.indexOf(":");
|
|
40
|
-
if (colon < 1) continue;
|
|
41
|
-
const occurrence = entry.slice(0, colon);
|
|
42
|
-
const eq = entry.indexOf("=", colon);
|
|
43
|
-
const key = decodeURIComponent(eq === -1 ? entry.slice(colon + 1) : entry.slice(colon + 1, eq));
|
|
44
|
-
const name = eq === -1 ? undefined : decodeURIComponent(entry.slice(eq + 1));
|
|
45
|
-
out || (out = Object.create(null));
|
|
46
|
-
(out[occurrence] || (out[occurrence] = [])).push({
|
|
47
|
-
pos,
|
|
48
|
-
key,
|
|
49
|
-
name
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return out;
|
|
54
|
-
}
|
|
55
|
-
function consumersEqual(a, b) {
|
|
56
|
-
if (a.length !== b.length) return false;
|
|
57
|
-
for (let i = 0; i < a.length; i++) {
|
|
58
|
-
const x = a[i];
|
|
59
|
-
const y = b[i];
|
|
60
|
-
if (x.element !== y.element || x.positions.length !== y.positions.length) return false;
|
|
61
|
-
for (let j = 0; j < x.positions.length; j++) {
|
|
62
|
-
const p = x.positions[j];
|
|
63
|
-
const q = y.positions[j];
|
|
64
|
-
if (p.pos !== q.pos || p.key !== q.key || p.name !== q.name) return false;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return true;
|
|
36
|
+
for (let i = 0; i < attrs.length; i++) if (attrs[i].name.startsWith(SLOT_MARKER)) return true;
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
function isAsyncValue(v) {
|
|
40
|
+
return v !== null && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
|
|
68
41
|
}
|
|
69
42
|
function chunkToRecords(chunk) {
|
|
70
43
|
switch (chunk.type) {
|
|
@@ -125,9 +98,12 @@ function chunkToRecords(chunk) {
|
|
|
125
98
|
digest: chunk.digest
|
|
126
99
|
}
|
|
127
100
|
};
|
|
101
|
+
case "ops":
|
|
102
|
+
return Object.assign({}, ...chunk.ops.map(chunkToRecords));
|
|
128
103
|
case "complete":
|
|
129
104
|
return {
|
|
130
|
-
":complete": true
|
|
105
|
+
":complete": true,
|
|
106
|
+
":bound": chunk.bound
|
|
131
107
|
};
|
|
132
108
|
case "error":
|
|
133
109
|
if (!chunk.key) return {
|
|
@@ -151,11 +127,20 @@ function createFrameHost(options = {}) {
|
|
|
151
127
|
});
|
|
152
128
|
return store;
|
|
153
129
|
};
|
|
130
|
+
const landings = new Map();
|
|
131
|
+
const lands = records => "" in records || ":error" in records || ":complete" in records;
|
|
132
|
+
const applyTo = (id, version, r) => {
|
|
133
|
+
const set = frames.get(id);
|
|
134
|
+
if (set) for (const frame of set) frame.apply({
|
|
135
|
+
version,
|
|
136
|
+
r
|
|
137
|
+
});
|
|
138
|
+
};
|
|
154
139
|
const write = (store, version, records) => {
|
|
155
140
|
if (store.version !== undefined && version < store.version) return false;
|
|
156
141
|
if (store.version === undefined || version > store.version) {
|
|
157
142
|
store.version = version;
|
|
158
|
-
|
|
143
|
+
store.records = {};
|
|
159
144
|
}
|
|
160
145
|
const assets = records["seg::assets"];
|
|
161
146
|
const previous = assets && store.records["seg::assets"];
|
|
@@ -171,6 +156,33 @@ function createFrameHost(options = {}) {
|
|
|
171
156
|
}
|
|
172
157
|
return true;
|
|
173
158
|
};
|
|
159
|
+
const settleArgs = (store, recordKey, record, chunk) => {
|
|
160
|
+
const args = record.args;
|
|
161
|
+
const out = {};
|
|
162
|
+
let regions, decoded;
|
|
163
|
+
const settle = () => {
|
|
164
|
+
if (! --record.pending && store.records[recordKey] === record) applyTo(chunk.id, store.version, {
|
|
165
|
+
[recordKey]: record
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
for (const key in args) {
|
|
169
|
+
const value = args[key];
|
|
170
|
+
if (value && typeof value.$ref === "string") {
|
|
171
|
+
const resolved = out[key] = options.resolve && options.resolve(value, chunk.id, chunk.version, store.version);
|
|
172
|
+
(decoded ??= {})[key] = true;
|
|
173
|
+
if (resolved instanceof Promise && resolved.s === 0) {
|
|
174
|
+
record.pending = (record.pending || 0) + 1;
|
|
175
|
+
resolved.c.push(settle);
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
if (value && typeof value.$frame === "string") (regions ??= {})[key] = value.$frame;
|
|
179
|
+
out[key] = value;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
record.args = out;
|
|
183
|
+
record.regions = regions;
|
|
184
|
+
record.decoded = decoded;
|
|
185
|
+
};
|
|
174
186
|
return {
|
|
175
187
|
register(id, frame) {
|
|
176
188
|
let set = frames.get(id);
|
|
@@ -178,11 +190,13 @@ function createFrameHost(options = {}) {
|
|
|
178
190
|
set.add(frame);
|
|
179
191
|
const store = stores.get(id);
|
|
180
192
|
if (store && store.version !== undefined) {
|
|
181
|
-
frame.apply({
|
|
193
|
+
if (!store.open) frame.apply({
|
|
182
194
|
version: store.version,
|
|
183
195
|
r: store.records
|
|
196
|
+
});else if (store.shown) frame.apply({
|
|
197
|
+
version: store.shownVersion,
|
|
198
|
+
r: store.shown
|
|
184
199
|
});
|
|
185
|
-
frame.rebase && frame.rebase();
|
|
186
200
|
}
|
|
187
201
|
},
|
|
188
202
|
unregister(id, frame) {
|
|
@@ -200,26 +214,65 @@ function createFrameHost(options = {}) {
|
|
|
200
214
|
value: html
|
|
201
215
|
};
|
|
202
216
|
if (store.version === undefined) store.version = 0;
|
|
217
|
+
store.shown = store.records;
|
|
218
|
+
store.shownVersion = store.version;
|
|
203
219
|
}
|
|
204
220
|
}
|
|
205
221
|
}
|
|
206
222
|
}
|
|
207
|
-
if (!frame)
|
|
223
|
+
if (!frame) {
|
|
224
|
+
stores.delete(id);
|
|
225
|
+
landings.delete(id);
|
|
226
|
+
}
|
|
208
227
|
},
|
|
209
228
|
apply(chunk) {
|
|
210
229
|
if (chunk.type === "data") {
|
|
211
|
-
|
|
230
|
+
const store = stores.get(chunk.id);
|
|
231
|
+
const current = store && store.version;
|
|
232
|
+
if (store && chunk.version < current) return;
|
|
233
|
+
options.applyData && options.applyData(chunk, current);
|
|
212
234
|
return;
|
|
213
235
|
}
|
|
214
236
|
const records = chunkToRecords(chunk);
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
237
|
+
const store = storeFor(chunk.id);
|
|
238
|
+
if (!write(store, chunk.version, records)) return;
|
|
239
|
+
if (chunk.type === "slot") {
|
|
240
|
+
const key = `slot:${chunk.key}`;
|
|
241
|
+
settleArgs(store, key, records[key], chunk);
|
|
242
|
+
}
|
|
243
|
+
let r = records;
|
|
244
|
+
if (chunk.type === "start") store.open = true;else if (lands(records)) {
|
|
245
|
+
store.open = false;
|
|
246
|
+
store.shown = r = store.records;
|
|
247
|
+
store.shownVersion = chunk.version;
|
|
248
|
+
const landed = landings.get(chunk.id);
|
|
249
|
+
if (landed && !(":complete" in records && ":error" in r)) {
|
|
250
|
+
landings.delete(chunk.id);
|
|
251
|
+
":error" in records ? landed.j(records[":error"]) : landed.r();
|
|
252
|
+
}
|
|
222
253
|
}
|
|
254
|
+
applyTo(chunk.id, chunk.version, r);
|
|
255
|
+
if (":complete" in records || ":error" in records) options.closeData && options.closeData(chunk.id, chunk.version, records[":error"]);
|
|
256
|
+
},
|
|
257
|
+
landing(id) {
|
|
258
|
+
const store = stores.get(id);
|
|
259
|
+
if (!store || !store.open && !store.shown) return undefined;
|
|
260
|
+
if (store.shown && !(":error" in store.shown)) return undefined;
|
|
261
|
+
let wait = landings.get(id);
|
|
262
|
+
if (!wait) {
|
|
263
|
+
landings.set(id, wait = {});
|
|
264
|
+
wait.p = new Promise((r, j) => (wait.r = r, wait.j = j));
|
|
265
|
+
}
|
|
266
|
+
return wait.p;
|
|
267
|
+
},
|
|
268
|
+
preview(chunk) {
|
|
269
|
+
if (chunk.type !== "slot") return;
|
|
270
|
+
const set = frames.get(chunk.id);
|
|
271
|
+
if (!set) return;
|
|
272
|
+
const records = chunkToRecords(chunk);
|
|
273
|
+
const key = `slot:${chunk.key}`;
|
|
274
|
+
settleArgs(storeFor(chunk.id), key, records[key], chunk);
|
|
275
|
+
for (const frame of set) frame.preview && frame.preview(records);
|
|
223
276
|
},
|
|
224
277
|
get(id) {
|
|
225
278
|
const set = frames.get(id);
|
|
@@ -229,45 +282,51 @@ function createFrameHost(options = {}) {
|
|
|
229
282
|
if (!options.serialize) throw new Error("host has no serializer");
|
|
230
283
|
return options.serialize(value);
|
|
231
284
|
},
|
|
232
|
-
resolve(ref, frameId) {
|
|
233
|
-
return options.resolve ? options.resolve(ref, frameId) : undefined;
|
|
234
|
-
},
|
|
235
285
|
revive: options.revive,
|
|
236
|
-
isContainer: options.isContainer,
|
|
237
286
|
prepareData: options.prepareData
|
|
238
287
|
};
|
|
239
288
|
}
|
|
240
289
|
const FRAME_APPLIED_EVENT = "frame:applied";
|
|
290
|
+
const tierLoaders = {};
|
|
291
|
+
const tierLoads = {};
|
|
292
|
+
const liveFrames = new Set();
|
|
293
|
+
function prepareTier(name) {
|
|
294
|
+
let load = tierLoads[name];
|
|
295
|
+
if (!load) {
|
|
296
|
+
const loader = tierLoaders[name];
|
|
297
|
+
tierLoads[name] = load = loader ? loader().then(module => {
|
|
298
|
+
load.r = module;
|
|
299
|
+
module.install?.();
|
|
300
|
+
for (const frame of liveFrames) frame.apply({
|
|
301
|
+
version: frame.version,
|
|
302
|
+
r: {}
|
|
303
|
+
});
|
|
304
|
+
}) : Promise.resolve();
|
|
305
|
+
}
|
|
306
|
+
return load;
|
|
307
|
+
}
|
|
308
|
+
const tierReady = name => !tierLoaders[name] || prepareTier(name).r;
|
|
309
|
+
const needsRegions = record => record.regions && !tierReady("regions");
|
|
310
|
+
const carriesTrace = value => value != null && typeof value === "object" && (value.$tr != null || Object.values(value).some(carriesTrace));
|
|
311
|
+
const needsTrace = args => !tierLoads.trace?.r && carriesTrace(args) && !tierReady("trace");
|
|
241
312
|
class FrameImpl {
|
|
242
313
|
#element;
|
|
243
|
-
#start;
|
|
244
|
-
#end;
|
|
245
314
|
#options;
|
|
315
|
+
#outer;
|
|
246
316
|
#version;
|
|
247
317
|
#store = Object.create(null);
|
|
248
|
-
#
|
|
318
|
+
#appliedRoot;
|
|
319
|
+
#appliedError;
|
|
249
320
|
#hasContent = false;
|
|
250
|
-
#errorNotified = false;
|
|
251
|
-
#revealed = new Set();
|
|
252
|
-
#fallbackShown = new Set();
|
|
253
321
|
#appliedHoles = new Map();
|
|
254
|
-
#have;
|
|
255
322
|
#slots;
|
|
256
323
|
#mountedSlots = new Set();
|
|
257
324
|
#slotCleanups = new Map();
|
|
258
325
|
#slotArgs = new Map();
|
|
259
326
|
#slotUpdaters = new Map();
|
|
260
|
-
#
|
|
261
|
-
#
|
|
262
|
-
#slotNodes = new Map();
|
|
263
|
-
#slotConsumers = new Map();
|
|
264
|
-
#slotRebinders = new Map();
|
|
265
|
-
#processedAssets = new WeakSet();
|
|
266
|
-
#recordRefresh = null;
|
|
327
|
+
#hold;
|
|
328
|
+
#heldRecords = new Map();
|
|
267
329
|
#disposed = false;
|
|
268
|
-
#styleFlush = () => {
|
|
269
|
-
if (!this.#disposed) this.#flush();
|
|
270
|
-
};
|
|
271
330
|
#claimTree = (node, direct) => {
|
|
272
331
|
const handlers = claimHandlers();
|
|
273
332
|
if (!handlers) return;
|
|
@@ -277,12 +336,12 @@ class FrameImpl {
|
|
|
277
336
|
const scope = this.#options.ownerScope;
|
|
278
337
|
return scope ? scope(fn) : fn();
|
|
279
338
|
}
|
|
280
|
-
constructor(element,
|
|
339
|
+
constructor(element, options = {}) {
|
|
281
340
|
this.#element = element;
|
|
282
|
-
this.#start = start;
|
|
283
|
-
this.#end = end;
|
|
284
341
|
this.#options = options;
|
|
285
342
|
this.#slots = options.slots;
|
|
343
|
+
this.#outer = options.parent;
|
|
344
|
+
liveFrames.add(this);
|
|
286
345
|
if (options.adopt) {
|
|
287
346
|
this.#hasContent = true;
|
|
288
347
|
this.#claimContent();
|
|
@@ -292,15 +351,12 @@ class FrameImpl {
|
|
|
292
351
|
}
|
|
293
352
|
if (options.adopt && this.#version === undefined) this.#syncSlots();
|
|
294
353
|
}
|
|
295
|
-
#parent() {
|
|
296
|
-
return this.#element ?? this.#start.parentNode;
|
|
297
|
-
}
|
|
298
354
|
#applied(version, reason) {
|
|
299
355
|
this.#options.onApply?.({
|
|
300
356
|
version,
|
|
301
357
|
reason
|
|
302
358
|
});
|
|
303
|
-
const parent = this.#
|
|
359
|
+
const parent = this.#element;
|
|
304
360
|
const Ev = parent && (parent.ownerDocument || parent).defaultView?.CustomEvent;
|
|
305
361
|
if (Ev) {
|
|
306
362
|
parent.dispatchEvent(new Ev(FRAME_APPLIED_EVENT, {
|
|
@@ -313,18 +369,12 @@ class FrameImpl {
|
|
|
313
369
|
}));
|
|
314
370
|
}
|
|
315
371
|
}
|
|
316
|
-
#firstContent() {
|
|
317
|
-
return this.#start ? this.#start.nextSibling : this.#parent().firstChild;
|
|
318
|
-
}
|
|
319
372
|
get version() {
|
|
320
373
|
return this.#version;
|
|
321
374
|
}
|
|
322
375
|
get store() {
|
|
323
376
|
return this.#store;
|
|
324
377
|
}
|
|
325
|
-
isRevealed(segment) {
|
|
326
|
-
return this.#revealed.has(segment);
|
|
327
|
-
}
|
|
328
378
|
get error() {
|
|
329
379
|
return this.#store[":error"];
|
|
330
380
|
}
|
|
@@ -339,68 +389,59 @@ class FrameImpl {
|
|
|
339
389
|
this.#version = v;
|
|
340
390
|
this.#resetStreamState();
|
|
341
391
|
}
|
|
342
|
-
for (const key in write.r)
|
|
343
|
-
const incoming = write.r[key];
|
|
344
|
-
if (incoming && incoming.kind === "slot" && key.charCodeAt(0) === 115 && key.startsWith("slot:")) {
|
|
345
|
-
const existing = this.#store[key];
|
|
346
|
-
if (existing && existing.kind === "slot" && argsEquivalent(existing.args, incoming.args)) {
|
|
347
|
-
continue;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
this.#store[key] = incoming;
|
|
351
|
-
}
|
|
392
|
+
for (const key in write.r) this.#store[key] = write.r[key];
|
|
352
393
|
this.#flush();
|
|
353
394
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
this.#
|
|
395
|
+
preview(records, inherited) {
|
|
396
|
+
const adopted = new Set();
|
|
397
|
+
if (this.#disposed) return adopted;
|
|
398
|
+
const R = tierLoads.regions?.r;
|
|
399
|
+
for (const key in records) {
|
|
400
|
+
const record = records[key];
|
|
401
|
+
if (!record || record.kind !== "slot" || !key.startsWith("slot:")) continue;
|
|
402
|
+
if (inherited && key in this.#store) continue;
|
|
403
|
+
const occurrence = key.slice(5);
|
|
404
|
+
const update = this.#mountedSlots.has(occurrence) && this.#slotUpdaters.get(occurrence);
|
|
405
|
+
if (!update || (R ? R.changed(this, occurrence, record) : record.regions)) continue;
|
|
406
|
+
this.#slotArgs.set(occurrence, record);
|
|
407
|
+
adopted.add(key);
|
|
408
|
+
update(this.#resolveArgs(occurrence, record));
|
|
409
|
+
}
|
|
410
|
+
if (R) for (const frame of R.frames(this)) for (const key of frame.preview(records, true)) adopted.add(key);
|
|
411
|
+
if (!inherited) for (const key of adopted) this.#store[key] = records[key];
|
|
412
|
+
return adopted;
|
|
413
|
+
}
|
|
414
|
+
#resetStreamState() {
|
|
415
|
+
this.#store = Object.create(null);
|
|
416
|
+
this.#appliedRoot = this.#appliedError = undefined;
|
|
357
417
|
this.#appliedHoles.clear();
|
|
358
|
-
this.#processedAssets = new WeakSet();
|
|
359
|
-
this.#errorNotified = false;
|
|
360
|
-
clearStreamRecords(this.#store, root);
|
|
361
418
|
}
|
|
362
419
|
#flush() {
|
|
363
420
|
if (this.#disposed) return;
|
|
364
421
|
const version = this.#version;
|
|
365
422
|
const root = this.#store[""];
|
|
366
|
-
if (root && root.kind === "html" && root
|
|
423
|
+
if (root && root.kind === "html" && root !== this.#appliedRoot) {
|
|
367
424
|
const reason = this.#hasContent ? "morph" : "materialize";
|
|
368
425
|
this.#applyRoot(root.value);
|
|
369
|
-
this.#
|
|
370
|
-
this.#
|
|
371
|
-
"": root.digest,
|
|
372
|
-
...root.holes
|
|
373
|
-
};
|
|
426
|
+
this.#appliedRoot = root;
|
|
427
|
+
this.#recordHave("", root);
|
|
374
428
|
this.#applied(version, reason);
|
|
375
429
|
}
|
|
376
|
-
|
|
377
|
-
|
|
430
|
+
const error = this.#store[":error"];
|
|
431
|
+
if (error && error !== this.#appliedError) {
|
|
432
|
+
this.#appliedError = error;
|
|
378
433
|
this.#applied(version, "error");
|
|
379
434
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
for (const key in this.#store) {
|
|
393
|
-
const m = /^seg:([^:]+):fallback$/.exec(key);
|
|
394
|
-
if (!m) continue;
|
|
395
|
-
const name = m[1];
|
|
396
|
-
if (this.#revealed.has(name) || this.#fallbackShown.has(name)) continue;
|
|
397
|
-
if (this.#showFallback(name)) {
|
|
398
|
-
this.#fallbackShown.add(name);
|
|
399
|
-
this.#applied(version, "reveal");
|
|
400
|
-
progressed = true;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
435
|
+
for (const key in this.#store) {
|
|
436
|
+
const record = this.#store[key];
|
|
437
|
+
if (!key.endsWith(":assets") || !record || this.#appliedHoles.get(key) === record) continue;
|
|
438
|
+
const tier = tierReady("assets");
|
|
439
|
+
if (!tier) break;
|
|
440
|
+
this.#appliedHoles.set(key, record);
|
|
441
|
+
tier.apply(record);
|
|
442
|
+
}
|
|
443
|
+
this.#revealSegments();
|
|
444
|
+
let morphed = false;
|
|
404
445
|
for (const key in this.#store) {
|
|
405
446
|
const record = this.#store[key];
|
|
406
447
|
if (!record || this.#appliedHoles.get(key) === record) continue;
|
|
@@ -410,49 +451,40 @@ class FrameImpl {
|
|
|
410
451
|
} else if (this.#applyHole(key.slice(5), record.value)) {
|
|
411
452
|
this.#appliedHoles.set(key, record);
|
|
412
453
|
this.#recordHave(key.slice(5), record);
|
|
413
|
-
|
|
454
|
+
morphed = true;
|
|
414
455
|
}
|
|
415
456
|
} else if (key.startsWith("attr:")) {
|
|
416
457
|
if (this.#applyAttrs(key.slice(5), record.value, record.removed)) {
|
|
417
458
|
this.#appliedHoles.set(key, record);
|
|
418
459
|
this.#recordHave("lha:" + key.slice(5), record);
|
|
419
|
-
|
|
460
|
+
morphed = true;
|
|
420
461
|
}
|
|
421
462
|
}
|
|
422
463
|
}
|
|
423
|
-
|
|
424
|
-
const record = this.#store[key];
|
|
425
|
-
if (!key.endsWith(":assets") || !record || this.#processedAssets.has(record)) {
|
|
426
|
-
continue;
|
|
427
|
-
}
|
|
428
|
-
this.#processedAssets.add(record);
|
|
429
|
-
if (record.modules) {
|
|
430
|
-
for (const href of record.modules) ensureModulePreload(href);
|
|
431
|
-
}
|
|
432
|
-
if (record.preloads) {
|
|
433
|
-
for (const entry of record.preloads) ensurePreload(entry);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
464
|
+
if (morphed) this.#applied(version, "morph");
|
|
436
465
|
this.#syncSlots();
|
|
437
466
|
}
|
|
438
467
|
#resolveSlot(prop) {
|
|
439
|
-
return this.#slots?.[prop] ?? this.#
|
|
468
|
+
return this.#slots?.[prop] ?? (this.#outer && this.#outer.#resolveSlot(prop));
|
|
440
469
|
}
|
|
441
470
|
#resolveSlotRecord(occurrence) {
|
|
442
471
|
const record = this.#store[`slot:${occurrence}`];
|
|
443
472
|
if (record !== undefined) return record;
|
|
444
|
-
return this.#
|
|
473
|
+
return this.#outer && this.#outer.#resolveSlotRecord(occurrence);
|
|
445
474
|
}
|
|
446
475
|
#removeSlotRecord(occurrence) {
|
|
447
476
|
const key = `slot:${occurrence}`;
|
|
448
477
|
if (key in this.#store) {
|
|
449
478
|
if (!this.#mountedSlots.has(occurrence)) delete this.#store[key];
|
|
450
|
-
} else this.#
|
|
479
|
+
} else this.#outer && this.#outer.#removeSlotRecord(occurrence);
|
|
451
480
|
}
|
|
452
481
|
#syncSlots(root) {
|
|
453
|
-
if (!this.#slots && !this.#
|
|
482
|
+
if (!this.#slots && !this.#outer) return;
|
|
454
483
|
const found = new Map();
|
|
455
484
|
if (root) collectSlots(root.firstChild, null, found, found);else this.#collectSlots(found, found);
|
|
485
|
+
let waiting = false;
|
|
486
|
+
const R = tierLoads.regions?.r;
|
|
487
|
+
const B = tierLoads.bind?.r;
|
|
456
488
|
for (const [occurrence, start] of found) {
|
|
457
489
|
const callback = this.#resolveSlot(propOf(occurrence));
|
|
458
490
|
const consumers = Array.isArray(start) ? start : null;
|
|
@@ -460,75 +492,56 @@ class FrameImpl {
|
|
|
460
492
|
continue;
|
|
461
493
|
}
|
|
462
494
|
const record = this.#resolveSlotRecord(occurrence);
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
if (zombie) {
|
|
468
|
-
this.#mountedSlots.delete(occurrence);
|
|
469
|
-
this.#runSlotCleanups(occurrence);
|
|
495
|
+
const mounted = this.#mountedSlots.has(occurrence);
|
|
496
|
+
if (record === undefined && isCalled(occurrence)) {
|
|
497
|
+
waiting ||= !mounted;
|
|
498
|
+
continue;
|
|
470
499
|
}
|
|
471
|
-
if (!
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
this.#recordRefresh = null;
|
|
475
|
-
if (this.#disposed) return;
|
|
476
|
-
this.#options.drainRecords?.();
|
|
477
|
-
this.#syncSlots();
|
|
478
|
-
});
|
|
479
|
-
continue;
|
|
480
|
-
}
|
|
481
|
-
if (this.#options.adopt) this.#discoverRegions(occurrence, start);
|
|
482
|
-
const nodes = this.#invokeSlot(occurrence, callback, record, start, this.#options.adopt);
|
|
483
|
-
if (consumers) {
|
|
484
|
-
this.#slotNodes.set(occurrence, consumers.map(c => c.element));
|
|
485
|
-
this.#slotConsumers.set(occurrence, consumers);
|
|
486
|
-
} else {
|
|
487
|
-
if (nodes) this.#replaceRange(occurrence, start, nodes);
|
|
488
|
-
this.#slotNodes.set(occurrence, nodes);
|
|
489
|
-
}
|
|
490
|
-
this.#mountedSlots.add(occurrence);
|
|
491
|
-
if (!this.#options.adopt || nodes) this.#discoverRegions(occurrence, start);
|
|
492
|
-
this.#bindRegions(occurrence);
|
|
500
|
+
if (!mounted && record && (record.pending || needsRegions(record) || needsTrace(record.args))) {
|
|
501
|
+
waiting = true;
|
|
502
|
+
if (this.#options.adopt && !consumers) this.#heldRecords.has(occurrence) || this.#heldRecords.set(occurrence, record);
|
|
493
503
|
continue;
|
|
494
504
|
}
|
|
495
|
-
if (
|
|
496
|
-
this.#
|
|
497
|
-
this.#
|
|
498
|
-
const
|
|
499
|
-
|
|
505
|
+
if (!mounted) {
|
|
506
|
+
const held = this.#heldRecords.get(occurrence);
|
|
507
|
+
this.#heldRecords.delete(occurrence);
|
|
508
|
+
const mountRecord = held || record;
|
|
509
|
+
this.#invokeSlot(occurrence, callback, mountRecord, start, this.#options.adopt);
|
|
510
|
+
if (consumers) B.sync(this, occurrence, consumers);
|
|
511
|
+
this.#mountedSlots.add(occurrence);
|
|
512
|
+
R?.bind(this, occurrence);
|
|
513
|
+
if (mountRecord === record || !record || record.kind !== "slot") continue;
|
|
500
514
|
}
|
|
515
|
+
if (consumers) B.sync(this, occurrence, consumers);
|
|
501
516
|
if (record !== this.#slotArgs.get(occurrence)) {
|
|
502
|
-
if (
|
|
503
|
-
this.#slotArgs.set(occurrence, record);
|
|
504
|
-
this.#reconcileRegions(occurrence, record);
|
|
505
|
-
continue;
|
|
506
|
-
}
|
|
517
|
+
if (needsRegions(record) || needsTrace(record.args)) continue;
|
|
507
518
|
const update = this.#slotUpdaters.get(occurrence);
|
|
508
519
|
if (update) {
|
|
509
|
-
const props = this.#resolveArgs(occurrence, record
|
|
520
|
+
const props = this.#resolveArgs(occurrence, record);
|
|
510
521
|
this.#slotArgs.set(occurrence, record);
|
|
511
522
|
update(props);
|
|
512
|
-
this
|
|
523
|
+
R?.bind(this, occurrence);
|
|
513
524
|
continue;
|
|
514
525
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
if (nodes) this.#replaceRange(occurrence, start, nodes);
|
|
518
|
-
this.#slotNodes.set(occurrence, nodes);
|
|
519
|
-
}
|
|
520
|
-
this.#bindRegions(occurrence);
|
|
526
|
+
this.#invokeSlot(occurrence, callback, record, start);
|
|
527
|
+
R?.bind(this, occurrence);
|
|
521
528
|
}
|
|
522
529
|
}
|
|
530
|
+
if (found.b && !tierReady("bind")) waiting = true;
|
|
523
531
|
if (!root) {
|
|
524
532
|
for (const occurrence of [...this.#mountedSlots]) {
|
|
525
533
|
if (!found.has(occurrence)) this.#unmountSlot(occurrence);
|
|
526
534
|
}
|
|
535
|
+
if (waiting && !this.#hold) this.#hold = this.#options.hold?.();else if (!waiting && this.#hold) this.#releaseHold();
|
|
527
536
|
}
|
|
528
537
|
}
|
|
538
|
+
#releaseHold() {
|
|
539
|
+
const release = this.#hold;
|
|
540
|
+
this.#hold = undefined;
|
|
541
|
+
release && release();
|
|
542
|
+
}
|
|
529
543
|
#invokeSlot(occurrence, callback, record, start, adopted) {
|
|
530
544
|
this.#slotUpdaters.delete(occurrence);
|
|
531
|
-
this.#slotRebinders.delete(occurrence);
|
|
532
545
|
const cleanups = this.#slotCleanups.get(occurrence) ?? [];
|
|
533
546
|
let existing = [];
|
|
534
547
|
let end = null;
|
|
@@ -547,35 +560,22 @@ class FrameImpl {
|
|
|
547
560
|
end
|
|
548
561
|
} : undefined,
|
|
549
562
|
positions,
|
|
550
|
-
onRebind: positions ? fn =>
|
|
563
|
+
onRebind: positions ? fn => tierLoads.bind.r.rebinder(this, occurrence, fn) : undefined
|
|
551
564
|
};
|
|
552
|
-
const props = record && record.kind === "slot" ? this.#resolveArgs(occurrence, record
|
|
553
|
-
|
|
565
|
+
const props = record && record.kind === "slot" ? this.#resolveArgs(occurrence, record, adopted, start) : {};
|
|
566
|
+
this.#scoped(() => callback(props, ctx));
|
|
554
567
|
this.#slotArgs.set(occurrence, record);
|
|
555
568
|
if (cleanups.length) this.#slotCleanups.set(occurrence, cleanups);
|
|
556
|
-
if (content == null) return null;
|
|
557
|
-
return Array.isArray(content) ? content : [content];
|
|
558
|
-
}
|
|
559
|
-
#replaceRange(key, start, nodes) {
|
|
560
|
-
const parent = start.parentNode;
|
|
561
|
-
const end = eachInRange(start, key, n => parent.removeChild(n));
|
|
562
|
-
for (const node of nodes) parent.insertBefore(node, end);
|
|
563
569
|
}
|
|
564
570
|
#unmountSlot(key) {
|
|
565
571
|
this.#mountedSlots.delete(key);
|
|
566
|
-
this.#slotNodes.delete(key);
|
|
567
|
-
this.#slotConsumers.delete(key);
|
|
568
572
|
this.#slotArgs.delete(key);
|
|
569
573
|
this.#slotUpdaters.delete(key);
|
|
570
|
-
this.#
|
|
571
|
-
this.#slotResolvedRefs.delete(key);
|
|
574
|
+
this.#heldRecords.delete(key);
|
|
572
575
|
this.#removeSlotRecord(key);
|
|
573
576
|
this.#runSlotCleanups(key);
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
disposeRegions(regions);
|
|
577
|
-
this.#slotRegions.delete(key);
|
|
578
|
-
}
|
|
577
|
+
tierLoads.regions?.r?.unmount(this, key);
|
|
578
|
+
tierLoads.bind?.r?.unmount(this, key);
|
|
579
579
|
}
|
|
580
580
|
#runSlotCleanups(key) {
|
|
581
581
|
const cleanups = this.#slotCleanups.get(key);
|
|
@@ -583,129 +583,33 @@ class FrameImpl {
|
|
|
583
583
|
this.#slotCleanups.delete(key);
|
|
584
584
|
for (const fn of cleanups) fn();
|
|
585
585
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
host,
|
|
589
|
-
id
|
|
590
|
-
} = this.#options;
|
|
591
|
-
if (host) for (const key in args) {
|
|
592
|
-
if (isDataRef(args[key]) && host.resolve(args[key], id) === undefined) return true;
|
|
593
|
-
}
|
|
594
|
-
return false;
|
|
595
|
-
}
|
|
596
|
-
#regionsFor(slotKey) {
|
|
597
|
-
let regions = this.#slotRegions.get(slotKey);
|
|
598
|
-
if (!regions) this.#slotRegions.set(slotKey, regions = new Map());
|
|
599
|
-
return regions;
|
|
586
|
+
get options() {
|
|
587
|
+
return this.#options;
|
|
600
588
|
}
|
|
601
|
-
#resolveArgs(slotKey,
|
|
602
|
-
const
|
|
603
|
-
|
|
589
|
+
#resolveArgs(slotKey, record, claiming, start) {
|
|
590
|
+
const {
|
|
591
|
+
args,
|
|
592
|
+
regions,
|
|
593
|
+
decoded
|
|
594
|
+
} = record;
|
|
595
|
+
const revive = this.#options.host && this.#options.host.revive;
|
|
604
596
|
const props = {};
|
|
605
597
|
for (const key in args) {
|
|
598
|
+
if (regions && key in regions) continue;
|
|
606
599
|
const value = args[key];
|
|
607
|
-
|
|
608
|
-
const resolved = host ? host.resolve(value, this.#options.id) : undefined;
|
|
609
|
-
let cache = this.#slotResolvedRefs.get(slotKey);
|
|
610
|
-
if (!cache) this.#slotResolvedRefs.set(slotKey, cache = {});
|
|
611
|
-
cache[key] = resolved;
|
|
612
|
-
props[key] = resolved;
|
|
613
|
-
} else if (isFrameRef(value)) {
|
|
614
|
-
let entry = regions.get(key);
|
|
615
|
-
if (!entry) {
|
|
616
|
-
const element = makeFrameElement(value.$frame);
|
|
617
|
-
entry = {
|
|
618
|
-
childId: value.$frame,
|
|
619
|
-
element,
|
|
620
|
-
frame: undefined
|
|
621
|
-
};
|
|
622
|
-
regions.set(key, entry);
|
|
623
|
-
} else if (entry.childId !== value.$frame) {
|
|
624
|
-
renameRegion(entry, value.$frame);
|
|
625
|
-
}
|
|
626
|
-
props[key] = entry.element;
|
|
627
|
-
} else {
|
|
628
|
-
props[key] = host && host.revive ? host.revive(value) : value;
|
|
629
|
-
}
|
|
600
|
+
props[key] = revive && !(decoded && key in decoded) ? revive(value, claiming) : value;
|
|
630
601
|
}
|
|
602
|
+
if (regions) tierLoads.regions.r.resolve(this, slotKey, regions, props, claiming && start);
|
|
631
603
|
return props;
|
|
632
604
|
}
|
|
633
|
-
#discoverRegions(slotKey, start) {
|
|
634
|
-
if (!start || Array.isArray(start)) return;
|
|
635
|
-
const regions = this.#regionsFor(slotKey);
|
|
636
|
-
eachInRange(start, slotKey, n => collectRegionElements(n, regions));
|
|
637
|
-
}
|
|
638
|
-
#refArgsUnchanged(occurrence, record) {
|
|
639
|
-
const old = this.#slotArgs.get(occurrence);
|
|
640
|
-
if (!record || record.kind !== "slot") return false;
|
|
641
|
-
if (old && old.kind !== "slot") return false;
|
|
642
|
-
const a = old && old.args || {};
|
|
643
|
-
const b = record.args || {};
|
|
644
|
-
const ka = Object.keys(a);
|
|
645
|
-
const kb = Object.keys(b);
|
|
646
|
-
if (kb.length !== ka.length) return false;
|
|
647
|
-
const cache = this.#slotResolvedRefs.get(occurrence);
|
|
648
|
-
for (const key of ka) {
|
|
649
|
-
const va = a[key];
|
|
650
|
-
const vb = b[key];
|
|
651
|
-
if (va === vb) continue;
|
|
652
|
-
if (isFrameRef(va) && isFrameRef(vb)) continue;
|
|
653
|
-
if (isDataRef(va) && isDataRef(vb) && cache && key in cache) {
|
|
654
|
-
const host = this.#options.host;
|
|
655
|
-
const next = host ? host.resolve(vb, this.#options.id) : undefined;
|
|
656
|
-
if (host && host.isContainer && (host.isContainer(next) || host.isContainer(cache[key]))) {
|
|
657
|
-
if (next === cache[key]) continue;
|
|
658
|
-
return false;
|
|
659
|
-
}
|
|
660
|
-
if (isAsyncLike(next) || isAsyncLike(cache[key])) return false;
|
|
661
|
-
try {
|
|
662
|
-
if (JSON.stringify(next) === JSON.stringify(cache[key])) continue;
|
|
663
|
-
} catch (e) {
|
|
664
|
-
return false;
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
return false;
|
|
668
|
-
}
|
|
669
|
-
return true;
|
|
670
|
-
}
|
|
671
|
-
#reconcileRegions(occurrence, record) {
|
|
672
|
-
const args = record && record.args;
|
|
673
|
-
if (!args) return;
|
|
674
|
-
const regions = this.#slotRegions.get(occurrence);
|
|
675
|
-
if (!regions) return;
|
|
676
|
-
for (const key in args) {
|
|
677
|
-
const value = args[key];
|
|
678
|
-
if (!isFrameRef(value)) continue;
|
|
679
|
-
const entry = regions.get(key);
|
|
680
|
-
if (entry && entry.childId !== value.$frame) renameRegion(entry, value.$frame);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
#bindRegions(slotKey) {
|
|
684
|
-
const regions = this.#slotRegions.get(slotKey);
|
|
685
|
-
if (!regions) return;
|
|
686
|
-
for (const entry of regions.values()) {
|
|
687
|
-
if (!entry.frame) {
|
|
688
|
-
entry.frame = new FrameImpl(entry.element, null, null, {
|
|
689
|
-
id: entry.childId,
|
|
690
|
-
host: this.#options.host,
|
|
691
|
-
adopt: entry.adopt,
|
|
692
|
-
claimScope: this.#options.claimScope ?? this.#options.id,
|
|
693
|
-
ownerScope: this.#options.ownerScope,
|
|
694
|
-
resolveSlot: prop => this.#resolveSlot(prop),
|
|
695
|
-
resolveSlotRecord: occurrence => this.#resolveSlotRecord(occurrence),
|
|
696
|
-
removeSlotRecord: occurrence => this.#removeSlotRecord(occurrence)
|
|
697
|
-
});
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
605
|
#collectSlots(found, elements) {
|
|
702
|
-
collectSlots(this.#
|
|
606
|
+
collectSlots(this.#element.firstChild, null, found, elements);
|
|
703
607
|
}
|
|
704
|
-
#findPlaceholder(name) {
|
|
705
|
-
return findPlaceholder(this.#
|
|
608
|
+
#findPlaceholder(name, root) {
|
|
609
|
+
return findPlaceholder((root || this.#element).firstChild, null, placeholderId(name));
|
|
706
610
|
}
|
|
707
611
|
contentHTML() {
|
|
708
|
-
if (this.#disposed || !this.#
|
|
612
|
+
if (this.#disposed || !this.#hasContent) return null;
|
|
709
613
|
return this.#element.innerHTML;
|
|
710
614
|
}
|
|
711
615
|
rebind(id) {
|
|
@@ -723,20 +627,11 @@ class FrameImpl {
|
|
|
723
627
|
this.#element.setAttribute(FRAME_ID_ATTR, id);
|
|
724
628
|
}
|
|
725
629
|
this.#version = undefined;
|
|
726
|
-
this.#
|
|
727
|
-
this.#resetStreamState(true);
|
|
630
|
+
this.#resetStreamState();
|
|
728
631
|
if (host) host.register(id, this);
|
|
729
632
|
}
|
|
730
|
-
rebase() {
|
|
731
|
-
this.#version = undefined;
|
|
732
|
-
}
|
|
733
|
-
have() {
|
|
734
|
-
return this.#have;
|
|
735
|
-
}
|
|
736
633
|
#recordHave(key, record) {
|
|
737
|
-
|
|
738
|
-
this.#have[key] = record.digest;
|
|
739
|
-
if (record.holes) Object.assign(this.#have, record.holes);
|
|
634
|
+
tierLoads.wire?.r?.have(this, key, record);
|
|
740
635
|
}
|
|
741
636
|
dispose() {
|
|
742
637
|
if (this.#disposed) return;
|
|
@@ -746,36 +641,33 @@ class FrameImpl {
|
|
|
746
641
|
} = this.#options;
|
|
747
642
|
if (host && id !== undefined) host.unregister(id, this);
|
|
748
643
|
this.#disposed = true;
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
this.#recordRefresh = null;
|
|
752
|
-
}
|
|
644
|
+
liveFrames.delete(this);
|
|
645
|
+
this.#releaseHold();
|
|
753
646
|
for (const key of [...this.#slotCleanups.keys()]) this.#runSlotCleanups(key);
|
|
754
647
|
for (const key of this.#mountedSlots) this.#removeSlotRecord(key);
|
|
755
|
-
|
|
756
|
-
this.#slotRegions.clear();
|
|
648
|
+
tierLoads.regions?.r?.unmount(this);
|
|
757
649
|
this.#mountedSlots.clear();
|
|
758
650
|
}
|
|
759
651
|
#applyRoot(html) {
|
|
760
652
|
const fragment = parseFragment(html);
|
|
761
|
-
const parent = this.#
|
|
653
|
+
const parent = this.#element;
|
|
762
654
|
if (!this.#hasContent) {
|
|
763
|
-
|
|
655
|
+
parent.textContent = "";
|
|
764
656
|
this.#claimTree(fragment);
|
|
765
|
-
parent.
|
|
657
|
+
parent.appendChild(fragment);
|
|
766
658
|
this.#hasContent = true;
|
|
767
659
|
} else {
|
|
768
660
|
const claim = this.#claimTree;
|
|
769
661
|
const ranges = new Map();
|
|
770
662
|
this.#collectSlots(ranges);
|
|
771
663
|
const grafts = [];
|
|
772
|
-
reconcileChildren(parent, fragment,
|
|
664
|
+
reconcileChildren(parent, fragment, null, null, claim, ranges, grafts);
|
|
773
665
|
if (ranges.size) for (const root of grafts) flushGrafts(root, ranges);
|
|
774
666
|
}
|
|
775
667
|
}
|
|
776
668
|
#applyHole(marker, html) {
|
|
777
669
|
if (!this.#hasContent) return false;
|
|
778
|
-
const open = findLiveTarget(this.#
|
|
670
|
+
const open = findLiveTarget(this.#element.firstChild, null, n => n.nodeType === COMMENT_NODE && n.data === marker);
|
|
779
671
|
if (!open) return false;
|
|
780
672
|
const close = rangeClose(open, "lh:/" + marker.slice(3));
|
|
781
673
|
if (!close) {
|
|
@@ -786,7 +678,7 @@ class FrameImpl {
|
|
|
786
678
|
}
|
|
787
679
|
#applyAttrs(addr, text, removed) {
|
|
788
680
|
if (!this.#hasContent) return false;
|
|
789
|
-
const el = findLiveTarget(this.#
|
|
681
|
+
const el = findLiveTarget(this.#element.firstChild, null, n => n.nodeType === ELEMENT_NODE && n.getAttribute("data-lha") === addr);
|
|
790
682
|
if (!el) return false;
|
|
791
683
|
const parsed = parseFragment(`<i${text}></i>`).firstChild;
|
|
792
684
|
const keepOpen = preservesOpen(el);
|
|
@@ -818,66 +710,65 @@ class FrameImpl {
|
|
|
818
710
|
}
|
|
819
711
|
return true;
|
|
820
712
|
}
|
|
821
|
-
#clearContent() {
|
|
822
|
-
removeUntil(this.#parent(), this.#firstContent(), this.#end);
|
|
823
|
-
}
|
|
824
713
|
#claimContent() {
|
|
825
|
-
let n = this.#
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
714
|
+
for (let n = this.#element.firstChild; n; n = n.nextSibling) this.#claimTree(n);
|
|
715
|
+
}
|
|
716
|
+
#revealSegments(root) {
|
|
717
|
+
const version = this.#version;
|
|
718
|
+
for (const key in this.#store) {
|
|
719
|
+
const record = this.#store[key];
|
|
720
|
+
const name = segmentName(key);
|
|
721
|
+
if (name === null || !record || this.#appliedHoles.get(key) === record) continue;
|
|
722
|
+
if (this.#segmentReady(name, root)) {
|
|
723
|
+
this.#appliedHoles.set(key, record);
|
|
724
|
+
this.#revealSegment(name, root);
|
|
725
|
+
this.#applied(version, "reveal");
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
for (const key in this.#store) {
|
|
729
|
+
const m = /^seg:([^:]+):fallback$/.exec(key);
|
|
730
|
+
if (!m || this.#appliedHoles.has(key) || this.#appliedHoles.has(`seg:${m[1]}`)) continue;
|
|
731
|
+
if (this.#showFallback(m[1], root)) {
|
|
732
|
+
this.#appliedHoles.set(key, this.#store[key]);
|
|
733
|
+
this.#applied(version, "reveal");
|
|
734
|
+
}
|
|
829
735
|
}
|
|
830
736
|
}
|
|
831
|
-
#segmentReady(name) {
|
|
737
|
+
#segmentReady(name, root) {
|
|
832
738
|
const content = this.#store[`seg:${name}`];
|
|
833
739
|
if (!content || content.kind !== "html") return false;
|
|
834
740
|
if (!this.#store[`seg:${name}:reveal`]) return false;
|
|
835
741
|
const assets = this.#store[`seg:${name}:assets`];
|
|
836
|
-
if (assets && assets.styles)
|
|
837
|
-
|
|
838
|
-
for (const entry of assets.styles) ready = ensureStylesheet(entry, this.#styleFlush) && ready;
|
|
839
|
-
if (!ready) return false;
|
|
840
|
-
}
|
|
841
|
-
if (!this.#findPlaceholder(name)) return false;
|
|
842
|
-
return true;
|
|
742
|
+
if (assets && (assets.styles || assets.inlineStyles) && !tierReady("assets")?.gate(assets.styles || [], this)) return false;
|
|
743
|
+
return !!this.#findPlaceholder(name, root);
|
|
843
744
|
}
|
|
844
|
-
#revealSegment(name) {
|
|
845
|
-
const tpl = this.#findPlaceholder(name);
|
|
745
|
+
#revealSegment(name, root) {
|
|
746
|
+
const tpl = this.#findPlaceholder(name, root);
|
|
846
747
|
if (!tpl) return;
|
|
847
|
-
const assets = this.#store[`seg:${name}:assets`];
|
|
848
|
-
if (assets && assets.inlineStyles) applyInlineStyles(assets.inlineStyles);
|
|
849
748
|
const content = this.#store[`seg:${name}`];
|
|
850
749
|
const closing = rangeClose(tpl, placeholderId(name));
|
|
851
|
-
|
|
852
|
-
removeUntil(parent, tpl.nextSibling, closing);
|
|
853
|
-
if (this.#options.reveal) {
|
|
854
|
-
const fallbackFrag = tpl.content.cloneNode(true);
|
|
855
|
-
this.#claimTree(fallbackFrag);
|
|
856
|
-
this.#options.reveal({
|
|
857
|
-
before: closing,
|
|
858
|
-
fallback: [...fallbackFrag.childNodes],
|
|
859
|
-
content: () => {
|
|
860
|
-
const materialized = this.#materialize(content);
|
|
861
|
-
this.#syncSlots(materialized);
|
|
862
|
-
this.#claimTree(materialized);
|
|
863
|
-
return materialized;
|
|
864
|
-
}
|
|
865
|
-
});
|
|
866
|
-
tpl.remove();
|
|
867
|
-
this.#revealed.add(name);
|
|
868
|
-
this.#recordHave(name, content);
|
|
750
|
+
if (!closing) {
|
|
869
751
|
return;
|
|
870
752
|
}
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
753
|
+
removeUntil(tpl.parentNode, tpl.nextSibling, closing);
|
|
754
|
+
const fallbackFrag = tpl.content.cloneNode(true);
|
|
755
|
+
this.#claimTree(fallbackFrag);
|
|
756
|
+
(this.#options.reveal || revealAtOnce)({
|
|
757
|
+
before: closing,
|
|
758
|
+
fallback: [...fallbackFrag.childNodes],
|
|
759
|
+
content: () => {
|
|
760
|
+
const materialized = this.#materialize(content);
|
|
761
|
+
this.#syncSlots(materialized);
|
|
762
|
+
this.#claimTree(materialized);
|
|
763
|
+
this.#revealSegments(materialized);
|
|
764
|
+
return materialized;
|
|
765
|
+
}
|
|
766
|
+
});
|
|
874
767
|
tpl.remove();
|
|
875
|
-
closing && closing.remove();
|
|
876
|
-
this.#revealed.add(name);
|
|
877
768
|
this.#recordHave(name, content);
|
|
878
769
|
}
|
|
879
|
-
#showFallback(name) {
|
|
880
|
-
const tpl = this.#findPlaceholder(name);
|
|
770
|
+
#showFallback(name, root) {
|
|
771
|
+
const tpl = this.#findPlaceholder(name, root);
|
|
881
772
|
if (!tpl) return false;
|
|
882
773
|
const closing = rangeClose(tpl, placeholderId(name));
|
|
883
774
|
if (!closing) return false;
|
|
@@ -891,13 +782,13 @@ class FrameImpl {
|
|
|
891
782
|
}
|
|
892
783
|
}
|
|
893
784
|
function createFrame(boundary, options) {
|
|
894
|
-
return new FrameImpl(boundary,
|
|
785
|
+
return new FrameImpl(boundary, options);
|
|
895
786
|
}
|
|
896
787
|
const FRAME_TAG = "solid-frame";
|
|
897
788
|
const FRAME_ID_ATTR = "data-fid";
|
|
898
789
|
function createFrameElement(options) {
|
|
899
790
|
const el = makeFrameElement(options.id);
|
|
900
|
-
const frame = new FrameImpl(el,
|
|
791
|
+
const frame = new FrameImpl(el, options);
|
|
901
792
|
return {
|
|
902
793
|
element: el,
|
|
903
794
|
frame,
|
|
@@ -920,23 +811,16 @@ function segmentName(key) {
|
|
|
920
811
|
const m = /^seg:([^:]+)$/.exec(key);
|
|
921
812
|
return m ? m[1] : null;
|
|
922
813
|
}
|
|
923
|
-
function isAsyncLike(v) {
|
|
924
|
-
return !!v && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
|
|
925
|
-
}
|
|
926
814
|
function propOf(occurrence) {
|
|
927
815
|
const hash = occurrence.indexOf("#");
|
|
928
816
|
return hash === -1 ? occurrence : occurrence.slice(0, hash);
|
|
929
817
|
}
|
|
930
|
-
function
|
|
931
|
-
return
|
|
932
|
-
}
|
|
933
|
-
function isFrameRef(value) {
|
|
934
|
-
return !!value && typeof value.$frame === "string";
|
|
818
|
+
function isCalled(occurrence) {
|
|
819
|
+
return occurrence.indexOf("#") !== -1;
|
|
935
820
|
}
|
|
936
|
-
function
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
} of regions.values()) frame?.dispose();
|
|
821
|
+
function revealAtOnce(seam) {
|
|
822
|
+
seam.before.parentNode.insertBefore(seam.content(), seam.before);
|
|
823
|
+
seam.before.remove();
|
|
940
824
|
}
|
|
941
825
|
function removeUntil(parent, n, stop) {
|
|
942
826
|
while (n && n !== stop) {
|
|
@@ -950,80 +834,6 @@ function parseFragment(html) {
|
|
|
950
834
|
template.innerHTML = html;
|
|
951
835
|
return template.content;
|
|
952
836
|
}
|
|
953
|
-
const PRELOAD_QUALIFIERS = ["as", "crossorigin", "type", "media", "imagesrcset", "imagesizes"];
|
|
954
|
-
function qualifierValue(name, value) {
|
|
955
|
-
if (value == null) return null;
|
|
956
|
-
if (name === "imagesrcset" || name === "imagesizes") return value === "" ? null : value;
|
|
957
|
-
if (name === "as") return value.replace(/[A-Z]/g, c => String.fromCharCode(c.charCodeAt(0) + 32));
|
|
958
|
-
if (name !== "crossorigin") return value;
|
|
959
|
-
return value.length === 15 && value.toLowerCase() === "use-credentials" ? "use-credentials" : "anonymous";
|
|
960
|
-
}
|
|
961
|
-
function findHeadElement(selector, attr, value, qualifiers) {
|
|
962
|
-
candidate: for (const node of document.head.querySelectorAll(selector)) {
|
|
963
|
-
if (node.getAttribute(attr) !== value) continue;
|
|
964
|
-
if (!qualifiers) return node;
|
|
965
|
-
for (let i = 0; i < PRELOAD_QUALIFIERS.length; i++) {
|
|
966
|
-
const name = PRELOAD_QUALIFIERS[i];
|
|
967
|
-
if (qualifierValue(name, node.getAttribute(name)) !== qualifierValue(name, qualifiers[name] ?? null)) continue candidate;
|
|
968
|
-
}
|
|
969
|
-
return node;
|
|
970
|
-
}
|
|
971
|
-
return null;
|
|
972
|
-
}
|
|
973
|
-
function ensurePreload(entry) {
|
|
974
|
-
const attrs = entry.attrs;
|
|
975
|
-
const href = entry.href;
|
|
976
|
-
if (findHeadElement('link[rel="preload"]', "href", href || null, attrs)) return;
|
|
977
|
-
const link = document.createElement("link");
|
|
978
|
-
link.rel = "preload";
|
|
979
|
-
for (const name in attrs) link.setAttribute(name, attrs[name]);
|
|
980
|
-
if (href) link.setAttribute("href", href);
|
|
981
|
-
document.head.appendChild(link);
|
|
982
|
-
}
|
|
983
|
-
function ensureStylesheet(entry, onSettle) {
|
|
984
|
-
const href = typeof entry === "string" ? entry : entry.href;
|
|
985
|
-
let link = findHeadElement('link[rel="stylesheet"]', "href", href);
|
|
986
|
-
if (!link) {
|
|
987
|
-
link = document.createElement("link");
|
|
988
|
-
link.rel = "stylesheet";
|
|
989
|
-
if (typeof entry !== "string" && entry.attrs) {
|
|
990
|
-
for (const name in entry.attrs) link.setAttribute(name, entry.attrs[name]);
|
|
991
|
-
}
|
|
992
|
-
link.href = href;
|
|
993
|
-
const waiters = new Set();
|
|
994
|
-
link._$frWaiters = waiters;
|
|
995
|
-
const settle = () => {
|
|
996
|
-
link._$frWaiters = null;
|
|
997
|
-
for (const fn of waiters) fn();
|
|
998
|
-
};
|
|
999
|
-
link.addEventListener("load", settle);
|
|
1000
|
-
link.addEventListener("error", settle);
|
|
1001
|
-
document.head.appendChild(link);
|
|
1002
|
-
}
|
|
1003
|
-
const waiters = link._$frWaiters;
|
|
1004
|
-
if (waiters == null) return true;
|
|
1005
|
-
waiters.add(onSettle);
|
|
1006
|
-
return false;
|
|
1007
|
-
}
|
|
1008
|
-
function ensureModulePreload(href) {
|
|
1009
|
-
if (findHeadElement('link[rel="modulepreload"]', "href", href)) return;
|
|
1010
|
-
const link = document.createElement("link");
|
|
1011
|
-
link.rel = "modulepreload";
|
|
1012
|
-
link.href = href;
|
|
1013
|
-
document.head.appendChild(link);
|
|
1014
|
-
}
|
|
1015
|
-
function applyInlineStyles(inlineStyles) {
|
|
1016
|
-
for (const entry of inlineStyles) {
|
|
1017
|
-
if (findHeadElement("style[data-asset]", "data-asset", entry.id)) continue;
|
|
1018
|
-
const el = document.createElement("style");
|
|
1019
|
-
el.setAttribute("data-asset", entry.id);
|
|
1020
|
-
if (entry.attrs) {
|
|
1021
|
-
for (const name in entry.attrs) el.setAttribute(name, entry.attrs[name]);
|
|
1022
|
-
}
|
|
1023
|
-
el.textContent = entry.content || "";
|
|
1024
|
-
document.head.appendChild(el);
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
837
|
function isPlaceholderStart(node, id) {
|
|
1028
838
|
return node.tagName === "TEMPLATE" && node.id === id;
|
|
1029
839
|
}
|
|
@@ -1068,48 +878,20 @@ function collectSlots(n, end, out, elements) {
|
|
|
1068
878
|
n = afterRange(n, id);
|
|
1069
879
|
continue;
|
|
1070
880
|
}
|
|
881
|
+
if (elements !== undefined && isTextStart(n)) {
|
|
882
|
+
const B = tierLoads.bind?.r;
|
|
883
|
+
B ? B.text(n, elements) : elements.b = true;
|
|
884
|
+
}
|
|
1071
885
|
if (n.nodeType === ELEMENT_NODE && !isFrameElement(n)) {
|
|
1072
886
|
if (elements !== undefined && n.hasAttributes()) {
|
|
1073
|
-
const
|
|
1074
|
-
|
|
1075
|
-
for (const occurrence in byOccurrence) {
|
|
1076
|
-
let consumers = elements.get(occurrence);
|
|
1077
|
-
if (consumers === undefined) elements.set(occurrence, consumers = []);else if (!Array.isArray(consumers)) continue;
|
|
1078
|
-
consumers.push({
|
|
1079
|
-
element: n,
|
|
1080
|
-
positions: byOccurrence[occurrence]
|
|
1081
|
-
});
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
887
|
+
const B = tierLoads.bind?.r;
|
|
888
|
+
B ? B.positions(n, elements) : hasSlotMarker(n) && (elements.b = true);
|
|
1084
889
|
}
|
|
1085
890
|
collectSlots(n.firstChild, null, out, elements);
|
|
1086
891
|
}
|
|
1087
892
|
n = n.nextSibling;
|
|
1088
893
|
}
|
|
1089
894
|
}
|
|
1090
|
-
function collectRegionElements(node, regions) {
|
|
1091
|
-
if (node.nodeType !== ELEMENT_NODE) return;
|
|
1092
|
-
if (isFrameElement(node)) {
|
|
1093
|
-
const childId = node.getAttribute(FRAME_ID_ATTR);
|
|
1094
|
-
if (childId && childId.includes(".")) {
|
|
1095
|
-
const argKey = childId.slice(childId.lastIndexOf(".") + 1);
|
|
1096
|
-
if (!regions.has(argKey)) {
|
|
1097
|
-
regions.set(argKey, {
|
|
1098
|
-
childId,
|
|
1099
|
-
element: node,
|
|
1100
|
-
frame: undefined,
|
|
1101
|
-
adopt: true
|
|
1102
|
-
});
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
return;
|
|
1106
|
-
}
|
|
1107
|
-
for (let c = node.firstChild; c; c = c.nextSibling) collectRegionElements(c, regions);
|
|
1108
|
-
}
|
|
1109
|
-
function renameRegion(entry, childId) {
|
|
1110
|
-
entry.childId = childId;
|
|
1111
|
-
if (entry.frame) entry.frame.rebind(childId);else entry.element.setAttribute(FRAME_ID_ATTR, childId);
|
|
1112
|
-
}
|
|
1113
895
|
function eachInRange(start, key, cb) {
|
|
1114
896
|
const end = slotEnd(key);
|
|
1115
897
|
let n = start.nextSibling;
|
|
@@ -1120,28 +902,6 @@ function eachInRange(start, key, cb) {
|
|
|
1120
902
|
}
|
|
1121
903
|
return n;
|
|
1122
904
|
}
|
|
1123
|
-
function clearStreamRecords(records, root) {
|
|
1124
|
-
for (const key in records) {
|
|
1125
|
-
if (/^(seg|hole|attr):/.test(key) || key === ":error" || root && key === "") {
|
|
1126
|
-
delete records[key];
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
function argsEquivalent(a, b) {
|
|
1131
|
-
if (a === b) return true;
|
|
1132
|
-
if (!a || !b) return false;
|
|
1133
|
-
const ka = Object.keys(a);
|
|
1134
|
-
const kb = Object.keys(b);
|
|
1135
|
-
if (ka.length !== kb.length) return false;
|
|
1136
|
-
for (const key of ka) {
|
|
1137
|
-
const va = a[key];
|
|
1138
|
-
const vb = b[key];
|
|
1139
|
-
if (va === vb) continue;
|
|
1140
|
-
if (isFrameRef(va) && va.$frame === vb?.$frame) continue;
|
|
1141
|
-
return false;
|
|
1142
|
-
}
|
|
1143
|
-
return true;
|
|
1144
|
-
}
|
|
1145
905
|
function slotStartId(node) {
|
|
1146
906
|
if (node.nodeType !== COMMENT_NODE) return null;
|
|
1147
907
|
const m = SLOT_START.exec(node.data);
|
|
@@ -1161,62 +921,11 @@ function preservesOpen(el) {
|
|
|
1161
921
|
const t = el.tagName;
|
|
1162
922
|
return t === "DETAILS" || t === "DIALOG";
|
|
1163
923
|
}
|
|
1164
|
-
|
|
1165
|
-
const
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
if (!name.startsWith(SLOT_MARKER)) continue;
|
|
1170
|
-
const pos = name.slice(SLOT_MARKER.length);
|
|
1171
|
-
if (pos === "ref" || pos.startsWith("on:")) continue;
|
|
1172
|
-
out || (out = {
|
|
1173
|
-
attrs: new Set(),
|
|
1174
|
-
class: null,
|
|
1175
|
-
style: null
|
|
1176
|
-
});
|
|
1177
|
-
if (pos !== "class" && pos !== "style") {
|
|
1178
|
-
out.attrs.add(pos);
|
|
1179
|
-
continue;
|
|
1180
|
-
}
|
|
1181
|
-
for (const entry of attrs[i].value.split(",")) {
|
|
1182
|
-
const eq = entry.indexOf("=");
|
|
1183
|
-
if (eq === -1) {
|
|
1184
|
-
out.attrs.add(pos);
|
|
1185
|
-
continue;
|
|
1186
|
-
}
|
|
1187
|
-
(out[pos] || (out[pos] = [])).push(decodeURIComponent(entry.slice(eq + 1)));
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
return out;
|
|
1191
|
-
}
|
|
1192
|
-
function morphOwnedClass(oldEl, value, names) {
|
|
1193
|
-
const list = oldEl.classList;
|
|
1194
|
-
const set = new Set(value ? value.split(/\s+/) : []);
|
|
1195
|
-
set.delete("");
|
|
1196
|
-
for (const name of names) list.contains(name) ? set.add(name) : set.delete(name);
|
|
1197
|
-
const next = [...set].join(" ");
|
|
1198
|
-
if (next === (oldEl.getAttribute("class") || "")) return false;
|
|
1199
|
-
next ? oldEl.setAttribute("class", next) : oldEl.removeAttribute("class");
|
|
1200
|
-
return true;
|
|
1201
|
-
}
|
|
1202
|
-
function morphOwnedStyle(oldEl, value, names) {
|
|
1203
|
-
const style = oldEl.style;
|
|
1204
|
-
const saved = names.map(name => [name, style.getPropertyValue(name), style.getPropertyPriority(name)]);
|
|
1205
|
-
const before = oldEl.getAttribute("style");
|
|
1206
|
-
value ? oldEl.setAttribute("style", value) : oldEl.removeAttribute("style");
|
|
1207
|
-
for (const [name, v, priority] of saved) {
|
|
1208
|
-
v ? style.setProperty(name, v, priority) : style.removeProperty(name);
|
|
1209
|
-
}
|
|
1210
|
-
return oldEl.getAttribute("style") !== before;
|
|
1211
|
-
}
|
|
1212
|
-
function applyOwned(oldEl, name, value, owned) {
|
|
1213
|
-
if (owned === null) return undefined;
|
|
1214
|
-
if (owned.attrs.has(name)) return false;
|
|
1215
|
-
if ((name === "class" || name === "style") && owned[name] !== null) {
|
|
1216
|
-
return name === "class" ? morphOwnedClass(oldEl, value, owned.class) : morphOwnedStyle(oldEl, value, owned.style);
|
|
1217
|
-
}
|
|
1218
|
-
return undefined;
|
|
1219
|
-
}
|
|
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);
|
|
1220
929
|
function morphAttributes(oldEl, newEl, claim) {
|
|
1221
930
|
let reclaim = false;
|
|
1222
931
|
let changed = false;
|
|
@@ -1264,8 +973,9 @@ function morphNode(oldNode, newNode, claim, ranges, grafts) {
|
|
|
1264
973
|
oldNode.data = newNode.data;
|
|
1265
974
|
}
|
|
1266
975
|
}
|
|
1267
|
-
|
|
1268
|
-
|
|
976
|
+
const afterRange = (start, id) => afterMarker(start, slotEnd(id));
|
|
977
|
+
const afterText = start => afterMarker(start, SLOT_TEXT_END);
|
|
978
|
+
function afterMarker(start, end) {
|
|
1269
979
|
let n = start.nextSibling;
|
|
1270
980
|
while (n) {
|
|
1271
981
|
if (n.nodeType === COMMENT_NODE && n.data === end) return n.nextSibling;
|
|
@@ -1324,6 +1034,11 @@ function reconcileChildren(parent, source, boundStart = null, boundEnd = null, c
|
|
|
1324
1034
|
const nextNew = newChild.nextSibling;
|
|
1325
1035
|
const pid = slotStartId(newChild);
|
|
1326
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
|
+
}
|
|
1327
1042
|
if (pid !== null) {
|
|
1328
1043
|
if (old && slotStartId(old) === pid) {
|
|
1329
1044
|
oldChild = afterRange(old, pid);
|
|
@@ -1427,44 +1142,19 @@ function stashRange(frag, start, id) {
|
|
|
1427
1142
|
}
|
|
1428
1143
|
|
|
1429
1144
|
const FRAME_STREAM_HEADER = "X-Frame-Stream";
|
|
1430
|
-
const
|
|
1431
|
-
const FRAME_HAVE_BUDGET = 4096;
|
|
1432
|
-
function encodeHaveList(have) {
|
|
1433
|
-
let out = "";
|
|
1434
|
-
for (const key in have) {
|
|
1435
|
-
const digest = have[key];
|
|
1436
|
-
if (typeof digest !== "string") continue;
|
|
1437
|
-
out += (out ? "," : "") + key + "=" + digest;
|
|
1438
|
-
if (out.length > FRAME_HAVE_BUDGET) return undefined;
|
|
1439
|
-
}
|
|
1440
|
-
return out || undefined;
|
|
1441
|
-
}
|
|
1145
|
+
const FRAME_TIERS_HEADER = "X-Frame-Tiers";
|
|
1442
1146
|
function isFrameStreamResponse(response) {
|
|
1443
1147
|
return response.headers.has(FRAME_STREAM_HEADER);
|
|
1444
1148
|
}
|
|
1445
1149
|
const applyFrameResponse = applyFrames;
|
|
1446
1150
|
function applyFrames(response, host, options = {}, observation) {
|
|
1447
1151
|
const rootId = response.headers.get(FRAME_STREAM_HEADER) ?? "";
|
|
1152
|
+
response.headers.get(FRAME_TIERS_HEADER)?.split(",").forEach(prepareTier);
|
|
1448
1153
|
const as = options.as;
|
|
1449
1154
|
const version = options.version;
|
|
1450
1155
|
const perFrame = typeof version === "function" ? new Map() : null;
|
|
1451
|
-
const
|
|
1452
|
-
const connection = wire && wire.connection;
|
|
1453
|
-
const reader = wire && isEventStream(response) ? wire.open(response.body) : new ChunkReader(response.body);
|
|
1156
|
+
const reader = options[LIVE_WIRE] || new ChunkReader(response.body);
|
|
1454
1157
|
const open = new Map();
|
|
1455
|
-
let cancelled;
|
|
1456
|
-
let resolveEnd;
|
|
1457
|
-
if (connection) {
|
|
1458
|
-
connection.ended = new Promise(resolve => resolveEnd = resolve);
|
|
1459
|
-
connection.cancel = reason => {
|
|
1460
|
-
if (cancelled !== undefined) return;
|
|
1461
|
-
cancelled = reason;
|
|
1462
|
-
try {
|
|
1463
|
-
const r = reader.cancel && reader.cancel(reason);
|
|
1464
|
-
if (r && typeof r.then === "function") r.then(undefined, () => {});
|
|
1465
|
-
} catch {}
|
|
1466
|
-
};
|
|
1467
|
-
}
|
|
1468
1158
|
const errorRecord = (id, error) => ({
|
|
1469
1159
|
type: "error",
|
|
1470
1160
|
id,
|
|
@@ -1488,26 +1178,15 @@ function applyFrames(response, host, options = {}, observation) {
|
|
|
1488
1178
|
chunk.version = v;
|
|
1489
1179
|
} else if (version !== undefined) chunk.version = version;
|
|
1490
1180
|
if (chunk.type === "start") open.set(chunk.id, chunk.version);else if (chunk.type === "complete" || chunk.type === "error" && !chunk.key) open.delete(chunk.id);
|
|
1491
|
-
|
|
1181
|
+
const needs = chunk.tiers?.map(prepareTier) || [];
|
|
1182
|
+
if (chunk.type === "data" || chunk.type === "slot" && Object.values(chunk.args).some(v => v && v.$ref)) await Promise.all([host.prepareData?.(), ...needs]);
|
|
1492
1183
|
host.apply(chunk);
|
|
1493
1184
|
}
|
|
1494
1185
|
result = await reader.next();
|
|
1495
1186
|
}
|
|
1496
1187
|
};
|
|
1497
1188
|
const end = error => {
|
|
1498
|
-
|
|
1499
|
-
const sweep = () => {
|
|
1500
|
-
for (const id of open.keys()) host.apply(errorRecord(id, dead));
|
|
1501
|
-
};
|
|
1502
|
-
if (connection) {
|
|
1503
|
-
connection.done = true;
|
|
1504
|
-
resolveEnd({
|
|
1505
|
-
open: open.size,
|
|
1506
|
-
error: dead,
|
|
1507
|
-
sweep,
|
|
1508
|
-
close: () => {}
|
|
1509
|
-
});
|
|
1510
|
-
} else if (error === undefined) sweep();
|
|
1189
|
+
if (error === undefined) for (const id of open.keys()) host.apply(errorRecord(id, new Error("Frame stream ended before the frame completed.")));
|
|
1511
1190
|
};
|
|
1512
1191
|
return drain().then(() => {
|
|
1513
1192
|
end(undefined);
|
|
@@ -1520,7 +1199,19 @@ function applyFrames(response, host, options = {}, observation) {
|
|
|
1520
1199
|
const SERVER_COMPONENT = /*#__PURE__*/Symbol.for("solid.server-component");
|
|
1521
1200
|
const SERVER_COMPONENT_ADDRESS = /*#__PURE__*/Symbol.for("solid.server-component-address");
|
|
1522
1201
|
const COMPONENT_BINDING = /*#__PURE__*/Symbol.for("solid.component-binding");
|
|
1202
|
+
const CONTENT_TOKEN = "\u0000";
|
|
1203
|
+
function contentAddress(token) {
|
|
1204
|
+
return token.split(CONTENT_TOKEN)[0];
|
|
1205
|
+
}
|
|
1206
|
+
const stagedContent = {
|
|
1207
|
+
preview() {},
|
|
1208
|
+
commit() {}
|
|
1209
|
+
};
|
|
1523
1210
|
let resolveServerComponent;
|
|
1211
|
+
const calls = new Map();
|
|
1212
|
+
function callFor(address) {
|
|
1213
|
+
return calls.get(address);
|
|
1214
|
+
}
|
|
1524
1215
|
function parseServerComponent(value, ctx) {
|
|
1525
1216
|
return {
|
|
1526
1217
|
id: ctx.parse(value[SERVER_COMPONENT]),
|
|
@@ -1566,7 +1257,6 @@ function flightCodec(codec) {
|
|
|
1566
1257
|
function createServerComponentHandler({
|
|
1567
1258
|
host,
|
|
1568
1259
|
component,
|
|
1569
|
-
onStream,
|
|
1570
1260
|
intercept
|
|
1571
1261
|
}) {
|
|
1572
1262
|
const byFn = new Map();
|
|
@@ -1589,46 +1279,78 @@ function createServerComponentHandler({
|
|
|
1589
1279
|
}
|
|
1590
1280
|
return binding;
|
|
1591
1281
|
};
|
|
1592
|
-
|
|
1282
|
+
const staged = new Map();
|
|
1283
|
+
const latest = new Map();
|
|
1284
|
+
const stage = (address, base, version) => {
|
|
1285
|
+
if (!base) return undefined;
|
|
1286
|
+
let committed = false;
|
|
1287
|
+
const chunks = [];
|
|
1288
|
+
const token = address + CONTENT_TOKEN + version;
|
|
1289
|
+
const entry = {
|
|
1290
|
+
token,
|
|
1291
|
+
prepareData: host.prepareData,
|
|
1292
|
+
apply(chunk) {
|
|
1293
|
+
if (committed || chunk.type === "data") host.apply(chunk);else chunks.push(chunk);
|
|
1294
|
+
},
|
|
1295
|
+
preview() {
|
|
1296
|
+
if (host.preview) for (const chunk of chunks) host.preview(chunk);
|
|
1297
|
+
},
|
|
1298
|
+
commit() {
|
|
1299
|
+
committed = true;
|
|
1300
|
+
staged.delete(address);
|
|
1301
|
+
for (const chunk of chunks) host.apply(chunk);
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
staged.set(address, entry);
|
|
1305
|
+
const comp = base[COMPONENT_BINDING].component;
|
|
1306
|
+
const binding = props => comp(props, () => token);
|
|
1307
|
+
binding[COMPONENT_BINDING] = {
|
|
1308
|
+
component: comp,
|
|
1309
|
+
address: token
|
|
1310
|
+
};
|
|
1311
|
+
latest.set(address, binding);
|
|
1312
|
+
return entry;
|
|
1313
|
+
};
|
|
1314
|
+
const settled = (address, binding) => latest.get(address) || binding;
|
|
1315
|
+
const showing = address => {
|
|
1316
|
+
const frame = host.get(address);
|
|
1317
|
+
return frame !== undefined && frame.error === undefined;
|
|
1318
|
+
};
|
|
1319
|
+
const named = (token, half) => {
|
|
1320
|
+
const entry = staged.get(contentAddress(token));
|
|
1321
|
+
if (entry && entry.token === token) entry[half]();
|
|
1322
|
+
};
|
|
1323
|
+
stagedContent.preview = token => named(token, "preview");
|
|
1324
|
+
stagedContent.commit = token => named(token, "commit");
|
|
1325
|
+
resolveServerComponent = (id, address) => settled(address, bindingFor(address, id));
|
|
1593
1326
|
const versions = new Map();
|
|
1594
|
-
const connections = new Map();
|
|
1595
1327
|
const bump = address => {
|
|
1596
1328
|
const version = (versions.get(address) || 0) + 1;
|
|
1597
1329
|
versions.set(address, version);
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
connections.delete(address);
|
|
1601
|
-
connection.cancel(new Error("Superseded by a newer response for the address."));
|
|
1602
|
-
}
|
|
1330
|
+
staged.delete(address);
|
|
1331
|
+
tierLoads.wire?.r?.cancel(host, address);
|
|
1603
1332
|
return version;
|
|
1604
1333
|
};
|
|
1605
|
-
const
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
};
|
|
1334
|
+
const begin = (address, version) => host.apply({
|
|
1335
|
+
type: "start",
|
|
1336
|
+
id: address,
|
|
1337
|
+
version
|
|
1338
|
+
});
|
|
1611
1339
|
return {
|
|
1612
1340
|
intercept: intercept && (info => {
|
|
1613
1341
|
const hit = intercept(info);
|
|
1614
1342
|
if (hit === undefined) return undefined;
|
|
1615
|
-
const
|
|
1343
|
+
const address = frameAddress(info.id, info.args);
|
|
1344
|
+
if (!info.meta?.live) calls.set(address, info);
|
|
1345
|
+
const binding = () => bindingFor(address, info.id);
|
|
1616
1346
|
if (typeof hit.then === "function") return hit.then(landed => landed ? binding() : undefined);
|
|
1617
1347
|
return binding();
|
|
1618
1348
|
}),
|
|
1349
|
+
onLive() {
|
|
1350
|
+
prepareTier("wire");
|
|
1351
|
+
},
|
|
1619
1352
|
resume(info) {
|
|
1620
|
-
|
|
1621
|
-
const version = versions.get(address);
|
|
1622
|
-
const frame = host.get(address);
|
|
1623
|
-
const have = frame && frame.have ? frame.have() : undefined;
|
|
1624
|
-
if (version === undefined && !have) return undefined;
|
|
1625
|
-
const encoded = have && encodeHaveList(have);
|
|
1626
|
-
return {
|
|
1627
|
-
position: String(version || 0),
|
|
1628
|
-
headers: encoded ? {
|
|
1629
|
-
[FRAME_HAVE_HEADER]: encoded
|
|
1630
|
-
} : undefined
|
|
1631
|
-
};
|
|
1353
|
+
return tierLoads.wire?.r?.resume(host, info, versions);
|
|
1632
1354
|
},
|
|
1633
1355
|
handle(response, ctx) {
|
|
1634
1356
|
if (!isFrameStreamResponse(response)) return undefined;
|
|
@@ -1638,31 +1360,16 @@ function createServerComponentHandler({
|
|
|
1638
1360
|
return applyFlightResponse(response, address, binding);
|
|
1639
1361
|
}
|
|
1640
1362
|
const wire = ctx[LIVE_WIRE];
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
const current = connections.get(address);
|
|
1644
|
-
if (current && !current.done) {
|
|
1645
|
-
connection.ended = current.ended;
|
|
1646
|
-
const body = response.body;
|
|
1647
|
-
if (body) body.cancel().catch(() => {});
|
|
1648
|
-
return binding;
|
|
1649
|
-
}
|
|
1650
|
-
const version = bump(address);
|
|
1651
|
-
if (onStream) onStream(address, version, response);
|
|
1652
|
-
applyFrameResponse(response, host, {
|
|
1653
|
-
as: address,
|
|
1654
|
-
version,
|
|
1655
|
-
[LIVE_WIRE]: wire
|
|
1656
|
-
}).catch(() => {});
|
|
1657
|
-
hold(address, connection);
|
|
1658
|
-
return binding;
|
|
1659
|
-
}
|
|
1363
|
+
if (wire) return prepareTier("wire").then(() => tierLoads.wire.r.connect(response, wire, address, binding, host, bump, begin));
|
|
1364
|
+
calls.set(address, ctx);
|
|
1660
1365
|
const version = bump(address);
|
|
1661
|
-
|
|
1662
|
-
|
|
1366
|
+
const entry = showing(address) ? stage(address, binding, version) : undefined;
|
|
1367
|
+
if (!entry) begin(address, version);
|
|
1368
|
+
const target = entry || host;
|
|
1369
|
+
const applied = applyFrameResponse(response, target, {
|
|
1663
1370
|
as: address,
|
|
1664
1371
|
version
|
|
1665
|
-
}).catch(err =>
|
|
1372
|
+
}).catch(err => target.apply({
|
|
1666
1373
|
type: "error",
|
|
1667
1374
|
id: address,
|
|
1668
1375
|
version,
|
|
@@ -1670,17 +1377,10 @@ function createServerComponentHandler({
|
|
|
1670
1377
|
message: String(err && err.message)
|
|
1671
1378
|
}
|
|
1672
1379
|
}));
|
|
1673
|
-
return
|
|
1380
|
+
return entry ? applied.then(() => settled(address, binding)) : binding;
|
|
1674
1381
|
},
|
|
1675
1382
|
showing(address, functionId) {
|
|
1676
1383
|
bindingFor(address, functionId);
|
|
1677
|
-
const comp = componentFor(functionId);
|
|
1678
|
-
if (comp && (typeof comp === "function" || typeof comp === "object") && !comp[COMPONENT_BINDING]) {
|
|
1679
|
-
comp[COMPONENT_BINDING] = {
|
|
1680
|
-
component: comp,
|
|
1681
|
-
address
|
|
1682
|
-
};
|
|
1683
|
-
}
|
|
1684
1384
|
}
|
|
1685
1385
|
};
|
|
1686
1386
|
async function applyFlightResponse(response, address, binding) {
|
|
@@ -1694,11 +1394,26 @@ function createServerComponentHandler({
|
|
|
1694
1394
|
});
|
|
1695
1395
|
const payload = deserializeStream(new Response(source), flightCodec(getServerFunctionsCodec()));
|
|
1696
1396
|
let carried = false;
|
|
1697
|
-
|
|
1397
|
+
const regions = new Map();
|
|
1398
|
+
const regionOf = id => {
|
|
1399
|
+
for (const [root, entry] of regions) if (id === root || id.startsWith(root + ".")) return entry;
|
|
1400
|
+
};
|
|
1401
|
+
const target = {
|
|
1402
|
+
apply: chunk => {
|
|
1403
|
+
const entry = regionOf(chunk.id);
|
|
1404
|
+
if (entry) entry.apply(chunk);else host.apply(chunk);
|
|
1405
|
+
},
|
|
1406
|
+
prepareData: host.prepareData
|
|
1407
|
+
};
|
|
1408
|
+
await applyFrameResponse(response, target, {
|
|
1698
1409
|
as,
|
|
1699
1410
|
version: frameId => {
|
|
1700
1411
|
const version = bump(frameId);
|
|
1701
|
-
|
|
1412
|
+
let entry = regionOf(frameId);
|
|
1413
|
+
if (!entry && showing(frameId)) {
|
|
1414
|
+
entry = stage(frameId, frameId === as ? binding : byAddress.get(frameId), version);
|
|
1415
|
+
if (entry) regions.set(frameId, entry);
|
|
1416
|
+
}
|
|
1702
1417
|
return version;
|
|
1703
1418
|
},
|
|
1704
1419
|
onOutcome: text => {
|
|
@@ -1713,47 +1428,16 @@ function createServerComponentHandler({
|
|
|
1713
1428
|
if (response.headers.has(ERROR_HEADER) && !hasFlightMetadata(response)) {
|
|
1714
1429
|
throw envelope.value;
|
|
1715
1430
|
}
|
|
1716
|
-
return rootId ? binding : envelope.value;
|
|
1431
|
+
return rootId ? settled(address, binding) : envelope.value;
|
|
1717
1432
|
}
|
|
1718
1433
|
}
|
|
1719
1434
|
|
|
1720
|
-
const
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
state.materializeTrace = fn;
|
|
1727
|
-
}
|
|
1728
|
-
function materialize(marker) {
|
|
1729
|
-
let value = state.materialized.get(marker.$tr);
|
|
1730
|
-
if (value === undefined) {
|
|
1731
|
-
value = state.materializeTrace(marker);
|
|
1732
|
-
state.materialized.set(marker.$tr, value);
|
|
1733
|
-
if (value !== null && typeof value === "object") state.materializedValues.add(value);
|
|
1734
|
-
}
|
|
1735
|
-
return value;
|
|
1736
|
-
}
|
|
1737
|
-
function isMaterializedContainer(value) {
|
|
1738
|
-
return value !== null && typeof value === "object" && state.materializedValues.has(value);
|
|
1739
|
-
}
|
|
1740
|
-
function isContainerTraceMarker(value) {
|
|
1741
|
-
if (value == null || typeof value !== "object" || value.$tr == null) return false;
|
|
1742
|
-
const tr = value.$tr;
|
|
1743
|
-
return tr.__SEROVAL_STREAM__ === true || typeof tr[Symbol.asyncIterator] === "function";
|
|
1744
|
-
}
|
|
1745
|
-
function reviveContainerTraces(value) {
|
|
1746
|
-
if (!state.materializeTrace || value == null || typeof value !== "object") return value;
|
|
1747
|
-
if (isContainerTraceMarker(value)) return materialize(value);
|
|
1748
|
-
if (Array.isArray(value)) {
|
|
1749
|
-
for (let i = 0; i < value.length; i++) value[i] = reviveContainerTraces(value[i]);
|
|
1750
|
-
} else if (Object.getPrototypeOf(value) === Object.prototype) {
|
|
1751
|
-
for (const key of Object.keys(value)) value[key] = reviveContainerTraces(value[key]);
|
|
1752
|
-
}
|
|
1753
|
-
return value;
|
|
1754
|
-
}
|
|
1755
|
-
|
|
1756
|
-
setContainerTraceMaterializer(materializeContainerTrace);
|
|
1435
|
+
const TRACE_STATE = Symbol.for("solid.container-trace-state");
|
|
1436
|
+
tierLoaders.trace = () => import('@solidjs/web/frames/trace');
|
|
1437
|
+
tierLoaders.regions = () => import('@solidjs/web/frames/regions');
|
|
1438
|
+
tierLoaders.assets = () => import('@solidjs/web/frames/assets');
|
|
1439
|
+
tierLoaders.bind = () => import('@solidjs/web/frames/bind');
|
|
1440
|
+
tierLoaders.wire = () => import('@solidjs/web/frames/wire');
|
|
1757
1441
|
function asyncArg(value) {
|
|
1758
1442
|
return value;
|
|
1759
1443
|
}
|
|
@@ -1766,116 +1450,119 @@ function loadCodec() {
|
|
|
1766
1450
|
});
|
|
1767
1451
|
}
|
|
1768
1452
|
const tables = new Map();
|
|
1769
|
-
function
|
|
1770
|
-
let
|
|
1771
|
-
if (!
|
|
1772
|
-
|
|
1453
|
+
function tableFor(id, version, current) {
|
|
1454
|
+
let byVersion = tables.get(id);
|
|
1455
|
+
if (!byVersion) tables.set(id, byVersion = new Map());else for (const v of byVersion.keys()) if (v < current) byVersion.delete(v);
|
|
1456
|
+
let t = byVersion.get(version);
|
|
1457
|
+
if (!t && codec) byVersion.set(version, t = codec.createJSONDataTable());
|
|
1458
|
+
return t;
|
|
1459
|
+
}
|
|
1460
|
+
function followAddress(host, frame, binding) {
|
|
1461
|
+
createRenderEffect(() => {
|
|
1462
|
+
const token = binding();
|
|
1463
|
+
stagedContent.preview(token);
|
|
1464
|
+
return token;
|
|
1465
|
+
}, token => {
|
|
1466
|
+
stagedContent.commit(token);
|
|
1467
|
+
frame.rebind(contentAddress(token));
|
|
1468
|
+
});
|
|
1773
1469
|
}
|
|
1774
|
-
function
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1470
|
+
function landing(host, address, value, failed) {
|
|
1471
|
+
let thrown = host.get(address)?.error;
|
|
1472
|
+
return createMemo(() => {
|
|
1473
|
+
failed();
|
|
1474
|
+
const error = host.get(address)?.error;
|
|
1475
|
+
if (error !== undefined && error !== thrown) {
|
|
1476
|
+
thrown = error;
|
|
1477
|
+
throw error;
|
|
1478
|
+
}
|
|
1479
|
+
const wait = host.landing(address);
|
|
1480
|
+
if (!wait) return value;
|
|
1481
|
+
const asked = error !== undefined ? reask(address) : undefined;
|
|
1482
|
+
return (asked ? asked.then(() => wait) : wait).then(() => value);
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
function reask(address) {
|
|
1486
|
+
const call = callFor(address);
|
|
1487
|
+
return call && call.retry();
|
|
1778
1488
|
}
|
|
1779
|
-
function
|
|
1780
|
-
|
|
1489
|
+
function failing() {
|
|
1490
|
+
const [failed, setFailed] = createSignal(0, {
|
|
1491
|
+
ownedWrite: true
|
|
1492
|
+
});
|
|
1493
|
+
return [failed, info => info.reason === "error" && setFailed(n => n + 1)];
|
|
1781
1494
|
}
|
|
1782
1495
|
function getFrameHost() {
|
|
1783
1496
|
if (!sharedHost) {
|
|
1784
1497
|
sharedHost = createFrameHost({
|
|
1785
1498
|
prepareData: loadCodec,
|
|
1786
|
-
applyData: c => tableFor(c.id)?.apply(c),
|
|
1787
|
-
resolve: (ref, id) => tableFor(id)?.resolve(ref),
|
|
1788
|
-
|
|
1789
|
-
isContainer: isMaterializedContainer
|
|
1499
|
+
applyData: (c, current) => tableFor(c.id, c.version, current)?.apply(c),
|
|
1500
|
+
resolve: (ref, id, version, current) => tableFor(id, version, current)?.resolve(ref),
|
|
1501
|
+
closeData: (id, version, error) => tables.get(id)?.get(version)?.close(error)
|
|
1790
1502
|
});
|
|
1791
1503
|
}
|
|
1792
1504
|
return sharedHost;
|
|
1793
1505
|
}
|
|
1794
|
-
function
|
|
1795
|
-
while (typeof value === "function") value = value();
|
|
1796
|
-
if (Array.isArray(value)) {
|
|
1797
|
-
const out = [];
|
|
1798
|
-
for (const v of value) {
|
|
1799
|
-
const n = normalizeSlotContent(v);
|
|
1800
|
-
Array.isArray(n) ? out.push(...n) : out.push(n);
|
|
1801
|
-
}
|
|
1802
|
-
return out;
|
|
1803
|
-
}
|
|
1804
|
-
if (value == null || typeof value === "boolean") return document.createTextNode("");
|
|
1805
|
-
return value instanceof Node ? value : document.createTextNode(String(value));
|
|
1806
|
-
}
|
|
1807
|
-
function gatherClaims(el, registry) {
|
|
1808
|
-
if (el.hasAttribute("_hk")) registry.set(el.getAttribute("_hk"), el);
|
|
1809
|
-
if (el.hasAttribute(FRAME_ID_ATTR)) return;
|
|
1810
|
-
for (let c = el.firstElementChild; c; c = c.nextElementSibling) gatherClaims(c, registry);
|
|
1811
|
-
}
|
|
1812
|
-
function hasPendingFragment(existing) {
|
|
1813
|
-
for (const n of existing) {
|
|
1814
|
-
if (n.nodeType !== 1) continue;
|
|
1815
|
-
const el = n;
|
|
1816
|
-
if (el.tagName === "TEMPLATE" && el.id.startsWith("pl-")) return true;
|
|
1817
|
-
if (el.querySelector?.('template[id^="pl-"]')) return true;
|
|
1818
|
-
}
|
|
1819
|
-
return false;
|
|
1820
|
-
}
|
|
1821
|
-
function claimRender(prefix, existing, render) {
|
|
1506
|
+
function claimRender(prefix, existing, render, scope, bound) {
|
|
1822
1507
|
const sc = sharedConfig;
|
|
1823
|
-
if (!sc.
|
|
1824
|
-
const
|
|
1825
|
-
for (const n of existing) {
|
|
1826
|
-
if (n.nodeType !== 1) continue;
|
|
1827
|
-
gatherClaims(n, registry);
|
|
1828
|
-
}
|
|
1829
|
-
if (!registry.size && !hasPendingFragment(existing)) return render();
|
|
1830
|
-
const prevRegistry = sc.registry;
|
|
1831
|
-
const prevHydrating = sc.hydrating;
|
|
1832
|
-
const prevClaimRoots = sc.claimRoots;
|
|
1833
|
-
if (prevRegistry) for (const key of registry.keys()) prevRegistry.delete(key);
|
|
1834
|
-
sc.registry = registry;
|
|
1835
|
-
sc.hydrating = true;
|
|
1508
|
+
if (!sc.hydrateWindow || !sc.registry) return render();
|
|
1509
|
+
const prevRoots = sc.claimRoots;
|
|
1836
1510
|
sc.claimRoots = existing;
|
|
1837
1511
|
try {
|
|
1838
1512
|
return runWithOwner(createOwner({
|
|
1839
1513
|
id: prefix
|
|
1840
|
-
}), render);
|
|
1514
|
+
}), () => sc.hydrateWindow(bound ? undefined : prefix, render, scope));
|
|
1841
1515
|
} finally {
|
|
1842
|
-
sc.
|
|
1843
|
-
sc.hydrating = prevHydrating;
|
|
1844
|
-
sc.claimRoots = prevClaimRoots;
|
|
1516
|
+
sc.claimRoots = prevRoots;
|
|
1845
1517
|
}
|
|
1846
1518
|
}
|
|
1847
1519
|
function liveSlotProps(initial, ctx) {
|
|
1848
|
-
const [args, setArgs] = createSignal(initial
|
|
1520
|
+
const [args, setArgs] = createSignal(initial, {
|
|
1521
|
+
ownedWrite: true
|
|
1522
|
+
});
|
|
1849
1523
|
ctx.onUpdate(next => setArgs(() => next));
|
|
1850
1524
|
return slotArgsProxy(args);
|
|
1851
1525
|
}
|
|
1852
|
-
function
|
|
1853
|
-
|
|
1526
|
+
function sameArg(a, b) {
|
|
1527
|
+
if (a === b) return true;
|
|
1528
|
+
if (!a || !b || typeof a !== "object" || typeof b !== "object") return false;
|
|
1529
|
+
if (a instanceof Boxed || b instanceof Boxed) return a instanceof Boxed && b instanceof Boxed && a.c === b.c;
|
|
1530
|
+
if (isAsyncValue(a) || isAsyncValue(b) || a instanceof Node || b instanceof Node) return false;
|
|
1531
|
+
try {
|
|
1532
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
1533
|
+
} catch {
|
|
1534
|
+
return false;
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
class Boxed {
|
|
1538
|
+
constructor(c) {
|
|
1539
|
+
this.c = c;
|
|
1540
|
+
}
|
|
1854
1541
|
}
|
|
1855
1542
|
function slotArgsProxy(args) {
|
|
1856
1543
|
const owner = getOwner();
|
|
1857
|
-
const
|
|
1544
|
+
const reads = new Map();
|
|
1858
1545
|
return new Proxy({}, {
|
|
1859
1546
|
get: (_, key) => {
|
|
1860
|
-
|
|
1861
|
-
if (isMaterializedContainer(v)) return v;
|
|
1862
|
-
if (!isAsyncValue(v)) return v;
|
|
1863
|
-
let read = asyncReads.get(key);
|
|
1547
|
+
let read = reads.get(key);
|
|
1864
1548
|
if (!read) {
|
|
1865
1549
|
const make = () => createMemo(() => {
|
|
1866
1550
|
const raw = args()[key];
|
|
1551
|
+
if (globalThis[TRACE_STATE]?.materializedValues.has(raw)) return new Boxed(raw);
|
|
1867
1552
|
if (raw != null && typeof raw.then === "function") {
|
|
1868
1553
|
if (raw.s === 1) return raw.v;
|
|
1869
1554
|
if (raw.s === 2) throw raw.v;
|
|
1870
1555
|
}
|
|
1871
1556
|
return raw;
|
|
1872
1557
|
}, {
|
|
1873
|
-
transparent: true
|
|
1558
|
+
transparent: true,
|
|
1559
|
+
equals: sameArg
|
|
1874
1560
|
});
|
|
1875
1561
|
read = owner ? runWithOwner(owner, make) : make();
|
|
1876
|
-
|
|
1562
|
+
reads.set(key, read);
|
|
1877
1563
|
}
|
|
1878
|
-
|
|
1564
|
+
const v = read();
|
|
1565
|
+
return v instanceof Boxed ? v.c : v;
|
|
1879
1566
|
},
|
|
1880
1567
|
has: (_, key) => key in args(),
|
|
1881
1568
|
ownKeys: () => Reflect.ownKeys(args()),
|
|
@@ -1885,142 +1572,13 @@ function slotArgsProxy(args) {
|
|
|
1885
1572
|
} : undefined
|
|
1886
1573
|
});
|
|
1887
1574
|
}
|
|
1888
|
-
function
|
|
1889
|
-
const [consumers, setConsumers] = createSignal(ctx.positions);
|
|
1890
|
-
ctx.onRebind(setConsumers);
|
|
1891
|
-
const output = createMemo(() => {
|
|
1892
|
-
const out = fill(args);
|
|
1893
|
-
const node = typeof Node === "function" && out instanceof Node;
|
|
1894
|
-
return out == null || typeof out !== "object" || node ? {} : out;
|
|
1895
|
-
});
|
|
1896
|
-
const state = new WeakMap();
|
|
1897
|
-
let bound = new Set();
|
|
1898
|
-
createRenderEffect(() => {
|
|
1899
|
-
const out = output();
|
|
1900
|
-
return consumers().map(({
|
|
1901
|
-
element,
|
|
1902
|
-
positions
|
|
1903
|
-
}) => ({
|
|
1904
|
-
element,
|
|
1905
|
-
...propsFor(element, positions, out)
|
|
1906
|
-
}));
|
|
1907
|
-
}, writes => {
|
|
1908
|
-
const next = new Set();
|
|
1909
|
-
for (const {
|
|
1910
|
-
element,
|
|
1911
|
-
props,
|
|
1912
|
-
handlers
|
|
1913
|
-
} of writes) {
|
|
1914
|
-
next.add(element);
|
|
1915
|
-
write(element, props, handlers);
|
|
1916
|
-
}
|
|
1917
|
-
for (const element of bound) if (!next.has(element)) write(element, {}, {});
|
|
1918
|
-
bound = next;
|
|
1919
|
-
});
|
|
1920
|
-
onCleanup(() => {
|
|
1921
|
-
for (const element of bound) write(element, {}, {});
|
|
1922
|
-
});
|
|
1923
|
-
function write(element, props, handlers) {
|
|
1924
|
-
const st = state.get(element);
|
|
1925
|
-
for (const k in st.prev) if (!(k in props) && k !== "ref") delete st.prev[k];
|
|
1926
|
-
assign(element, props, true, st.prev);
|
|
1927
|
-
st.keys = handlers;
|
|
1928
|
-
for (const name of st.on) {
|
|
1929
|
-
if (!(name in handlers)) {
|
|
1930
|
-
element.removeEventListener(name, st.listener);
|
|
1931
|
-
st.on.delete(name);
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1934
|
-
for (const name in handlers) {
|
|
1935
|
-
if (!st.on.has(name)) {
|
|
1936
|
-
element.addEventListener(name, st.listener);
|
|
1937
|
-
st.on.add(name);
|
|
1938
|
-
}
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
function propsFor(element, positions, out) {
|
|
1942
|
-
let st = state.get(element);
|
|
1943
|
-
if (!st) {
|
|
1944
|
-
const s = {
|
|
1945
|
-
prev: {},
|
|
1946
|
-
ref: undefined,
|
|
1947
|
-
refId: "",
|
|
1948
|
-
on: new Set(),
|
|
1949
|
-
keys: {},
|
|
1950
|
-
listener(e) {
|
|
1951
|
-
const o = output();
|
|
1952
|
-
const keys = s.keys[e.type];
|
|
1953
|
-
if (keys === undefined) return;
|
|
1954
|
-
for (const k of keys) {
|
|
1955
|
-
const h = o[k];
|
|
1956
|
-
if (Array.isArray(h)) h[0].call(this, h[1], e);else if (typeof h === "function") h.call(this, e);
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1959
|
-
};
|
|
1960
|
-
state.set(element, st = s);
|
|
1961
|
-
}
|
|
1962
|
-
const props = {};
|
|
1963
|
-
const handlers = {};
|
|
1964
|
-
let classNames = null;
|
|
1965
|
-
let styleProps = null;
|
|
1966
|
-
let refKeys = null;
|
|
1967
|
-
for (const {
|
|
1968
|
-
pos,
|
|
1969
|
-
key,
|
|
1970
|
-
name
|
|
1971
|
-
} of positions) {
|
|
1972
|
-
if (pos === "class" || pos === "style") {
|
|
1973
|
-
if (name === undefined) props[pos] = out[key];else if (pos === "class") (classNames || (classNames = {}))[name] = !!out[key];else (styleProps || (styleProps = {}))[name] = out[key];
|
|
1974
|
-
} else if (pos === "ref") {
|
|
1975
|
-
(refKeys || (refKeys = [])).push(key);
|
|
1976
|
-
} else if (pos.startsWith("on:")) {
|
|
1977
|
-
const event = pos.slice(3);
|
|
1978
|
-
(handlers[event] || (handlers[event] = [])).push(key);
|
|
1979
|
-
} else props[pos] = out[key];
|
|
1980
|
-
}
|
|
1981
|
-
if (classNames !== null && !("class" in props)) props.class = classNames;
|
|
1982
|
-
if (styleProps !== null && !("style" in props)) props.style = styleProps;
|
|
1983
|
-
if (refKeys !== null) {
|
|
1984
|
-
const id = refKeys.join(",");
|
|
1985
|
-
if (st.refId !== id) {
|
|
1986
|
-
const keys = refKeys;
|
|
1987
|
-
st.refId = id;
|
|
1988
|
-
st.ref = el => {
|
|
1989
|
-
const o = output();
|
|
1990
|
-
for (const k of keys) {
|
|
1991
|
-
const r = o[k];
|
|
1992
|
-
typeof r === "function" && r(el);
|
|
1993
|
-
}
|
|
1994
|
-
};
|
|
1995
|
-
}
|
|
1996
|
-
props.ref = st.ref;
|
|
1997
|
-
}
|
|
1998
|
-
return {
|
|
1999
|
-
props,
|
|
2000
|
-
handlers
|
|
2001
|
-
};
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
function isReactiveContent(value) {
|
|
2005
|
-
if (typeof value === "function") return true;
|
|
2006
|
-
if (Array.isArray(value)) {
|
|
2007
|
-
for (const v of value) if (isReactiveContent(v)) return true;
|
|
2008
|
-
}
|
|
2009
|
-
return false;
|
|
2010
|
-
}
|
|
2011
|
-
function slotsFor(props) {
|
|
2012
|
-
const bindings = new Map();
|
|
1575
|
+
function slotsFor(props, scope) {
|
|
2013
1576
|
const fillScopes = new Map();
|
|
2014
1577
|
return new Proxy({}, {
|
|
2015
1578
|
get(_, prop) {
|
|
2016
1579
|
if (typeof prop !== "string" || !(prop in props)) return undefined;
|
|
2017
1580
|
return (slotProps, ctx) => {
|
|
2018
1581
|
const key = ctx && ctx.key;
|
|
2019
|
-
const prev = key !== undefined && bindings.get(key);
|
|
2020
|
-
if (prev) {
|
|
2021
|
-
bindings.delete(key);
|
|
2022
|
-
prev.dispose();
|
|
2023
|
-
}
|
|
2024
1582
|
const prevFill = key !== undefined && fillScopes.get(key);
|
|
2025
1583
|
if (prevFill) {
|
|
2026
1584
|
fillScopes.delete(key);
|
|
@@ -2039,10 +1597,12 @@ function slotsFor(props) {
|
|
|
2039
1597
|
});
|
|
2040
1598
|
runWithOwner(owner, () => {
|
|
2041
1599
|
const args = ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotArgsProxy(() => slotProps);
|
|
2042
|
-
|
|
1600
|
+
tierLoads.bind.r.bind(fill, args, ctx, undefined);
|
|
2043
1601
|
});
|
|
2044
1602
|
return undefined;
|
|
2045
1603
|
}
|
|
1604
|
+
const range = ctx && ctx.range;
|
|
1605
|
+
if (!range) return undefined;
|
|
2046
1606
|
const fillOwner = streamInvoke ? createOwner() : null;
|
|
2047
1607
|
if (fillOwner && key !== undefined && ctx) {
|
|
2048
1608
|
fillScopes.set(key, fillOwner);
|
|
@@ -2051,42 +1611,31 @@ function slotsFor(props) {
|
|
|
2051
1611
|
fillOwner.dispose();
|
|
2052
1612
|
});
|
|
2053
1613
|
}
|
|
2054
|
-
const settle = out => {
|
|
2055
|
-
const existing = ctx && ctx.existing || [];
|
|
2056
|
-
if (existing.length) {
|
|
2057
|
-
const list = Array.isArray(out) ? out : [out];
|
|
2058
|
-
const inPlace = list.every(n => existing.some(e => e === n || e.nodeType === 1 && e.contains(n)));
|
|
2059
|
-
if (inPlace) return undefined;
|
|
2060
|
-
}
|
|
2061
|
-
return out;
|
|
2062
|
-
};
|
|
2063
1614
|
const evaluate = () => {
|
|
2064
1615
|
const v = props[prop];
|
|
2065
1616
|
if (typeof v === "function" && ctx && ctx.invoked) {
|
|
2066
|
-
|
|
1617
|
+
const fillProps = ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotArgsProxy(() => slotProps);
|
|
1618
|
+
return untrack(() => v(fillProps), undefined);
|
|
2067
1619
|
}
|
|
2068
1620
|
return v;
|
|
2069
1621
|
};
|
|
2070
1622
|
const adopted = !!(ctx && ctx.frame && ctx.adopted && ctx.existing && ctx.existing.length);
|
|
2071
1623
|
const prefix = ctx && ctx.frame ? `sc-${ctx.frame}-${ctx.key}-` : "";
|
|
2072
|
-
const value = fillOwner ? runWithOwner(fillOwner, () => adopted ? claimRender(prefix, ctx.existing, evaluate) : evaluate()) : adopted ? claimRender(prefix, ctx.existing, evaluate) : evaluate();
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
}
|
|
2076
|
-
if (
|
|
2077
|
-
|
|
2078
|
-
const owner = createOwner();
|
|
2079
|
-
bindings.set(key, owner);
|
|
1624
|
+
const value = fillOwner ? runWithOwner(fillOwner, () => adopted ? claimRender(prefix, ctx.existing, evaluate, scope) : evaluate()) : adopted ? claimRender(prefix, ctx.existing, evaluate, scope) : evaluate();
|
|
1625
|
+
const owner = fillOwner || createOwner({
|
|
1626
|
+
transparent: true
|
|
1627
|
+
});
|
|
1628
|
+
if (!fillOwner) {
|
|
1629
|
+
fillScopes.set(key, owner);
|
|
2080
1630
|
ctx.onCleanup(() => {
|
|
2081
|
-
if (
|
|
1631
|
+
if (fillScopes.get(key) === owner) fillScopes.delete(key);
|
|
2082
1632
|
owner.dispose();
|
|
2083
1633
|
});
|
|
2084
|
-
const end = ctx.range.end;
|
|
2085
|
-
const bind = () => insert(end.parentNode, () => typeof source === "function" ? source() : source, end, [...ctx.existing]);
|
|
2086
|
-
runWithOwner(owner, () => adopted ? claimRender(prefix, ctx.existing, bind) : bind());
|
|
2087
|
-
return undefined;
|
|
2088
1634
|
}
|
|
2089
|
-
|
|
1635
|
+
const end = range.end;
|
|
1636
|
+
const bind = () => insert(end.parentNode, value, end, [...ctx.existing]);
|
|
1637
|
+
runWithOwner(owner, () => adopted ? claimRender(prefix, ctx.existing, bind, scope, true) : bind());
|
|
1638
|
+
return undefined;
|
|
2090
1639
|
};
|
|
2091
1640
|
}
|
|
2092
1641
|
});
|
|
@@ -2109,12 +1658,8 @@ function boundaryScope(owner) {
|
|
|
2109
1658
|
function boundaryComponent(host, fnId) {
|
|
2110
1659
|
return (props, binding) => {
|
|
2111
1660
|
const owner = getOwner();
|
|
2112
|
-
const id = binding ? binding() : fnId;
|
|
2113
|
-
|
|
2114
|
-
let release;
|
|
2115
|
-
const arm = () => new Promise(r => release = r);
|
|
2116
|
-
const mountGate = applied ? undefined : arm();
|
|
2117
|
-
let setGate;
|
|
1661
|
+
const id = binding ? contentAddress(binding()) : fnId;
|
|
1662
|
+
const [failed, onApply] = failing();
|
|
2118
1663
|
const {
|
|
2119
1664
|
element,
|
|
2120
1665
|
frame,
|
|
@@ -2125,30 +1670,12 @@ function boundaryComponent(host, fnId) {
|
|
|
2125
1670
|
slots: slotsFor(props),
|
|
2126
1671
|
ownerScope: boundaryScope(owner),
|
|
2127
1672
|
reveal: revealSeam(owner),
|
|
2128
|
-
onApply
|
|
2129
|
-
applied = true;
|
|
2130
|
-
if (release) {
|
|
2131
|
-
release();
|
|
2132
|
-
release = undefined;
|
|
2133
|
-
}
|
|
2134
|
-
setGate && setGate(undefined);
|
|
2135
|
-
}
|
|
1673
|
+
onApply
|
|
2136
1674
|
});
|
|
2137
|
-
const [gatePromise, setGatePromise] = createSignal(applied ? undefined : mountGate);
|
|
2138
|
-
setGate = setGatePromise;
|
|
2139
|
-
if (binding) {
|
|
2140
|
-
createRenderEffect(binding, (address, prev) => {
|
|
2141
|
-
if (prev !== undefined && address !== prev && tables.has(address)) {
|
|
2142
|
-
applied = false;
|
|
2143
|
-
setGatePromise(arm());
|
|
2144
|
-
}
|
|
2145
|
-
frame.rebind(address);
|
|
2146
|
-
});
|
|
2147
|
-
}
|
|
2148
1675
|
onCleanup(dispose);
|
|
2149
|
-
if (
|
|
2150
|
-
|
|
2151
|
-
return createMemo(() => (
|
|
1676
|
+
if (!binding) return landing(host, id, element, failed);
|
|
1677
|
+
followAddress(host, frame, binding);
|
|
1678
|
+
return createMemo(() => landing(host, contentAddress(binding()), element, failed));
|
|
2152
1679
|
};
|
|
2153
1680
|
}
|
|
2154
1681
|
const claimedBoundaries = new Set();
|
|
@@ -2163,7 +1690,7 @@ function pumpLiveChannel() {
|
|
|
2163
1690
|
const pump = () => reader.read().then(r => {
|
|
2164
1691
|
if (r.done) return;
|
|
2165
1692
|
const op = r.value;
|
|
2166
|
-
liveOps.set(`${
|
|
1693
|
+
for (const m of op.type === "ops" ? op.ops : [op]) liveOps.set(`${m.type}:${m.fid || ""}:${m.key || ""}`, m);
|
|
2167
1694
|
for (const apply of liveAppliers) apply(op);
|
|
2168
1695
|
return pump();
|
|
2169
1696
|
});
|
|
@@ -2173,7 +1700,7 @@ function pumpLiveChannel() {
|
|
|
2173
1700
|
let boundaryIndex = null;
|
|
2174
1701
|
const isBoundaryId = id => !id.includes(".");
|
|
2175
1702
|
function indexBoundaries(root) {
|
|
2176
|
-
root.querySelectorAll(
|
|
1703
|
+
root.querySelectorAll(FRAME_SELECTOR).forEach(el => {
|
|
2177
1704
|
const key = el.getAttribute(FRAME_ID_ATTR);
|
|
2178
1705
|
if (key && isBoundaryId(key) && !boundaryIndex.has(key)) boundaryIndex.set(key, el);
|
|
2179
1706
|
});
|
|
@@ -2185,8 +1712,9 @@ function findBoundaryElement(id) {
|
|
|
2185
1712
|
}
|
|
2186
1713
|
return boundaryIndex.get(id);
|
|
2187
1714
|
}
|
|
2188
|
-
const boundaryWaiters = new Map();
|
|
2189
1715
|
const arrivals = new Map();
|
|
1716
|
+
const FRAME_SELECTOR = `[${FRAME_ID_ATTR}]`;
|
|
1717
|
+
const disposedFrames = new WeakSet();
|
|
2190
1718
|
function awaitBoundary(id) {
|
|
2191
1719
|
let arrival = arrivals.get(id);
|
|
2192
1720
|
if (!arrival) {
|
|
@@ -2208,18 +1736,16 @@ function installRevealHook() {
|
|
|
2208
1736
|
const hy = globalThis._$HY;
|
|
2209
1737
|
if (!hy || hy.$sc || !hy.fr) return;
|
|
2210
1738
|
hy.$sc = true;
|
|
1739
|
+
hy.fa = pl => {
|
|
1740
|
+
const el = pl.closest(FRAME_SELECTOR);
|
|
1741
|
+
return !!el && !disposedFrames.has(el);
|
|
1742
|
+
};
|
|
2211
1743
|
hy.fr.subscribe((_id, parent) => {
|
|
2212
1744
|
if (!boundaryIndex) return;
|
|
2213
1745
|
const root = parent || (typeof document !== "undefined" ? document.body : null);
|
|
2214
1746
|
if (root) indexBoundaries(root);
|
|
2215
|
-
if (!
|
|
1747
|
+
if (!arrivals.size) return;
|
|
2216
1748
|
const exhausted = hy.done && !hy.fr.pending();
|
|
2217
|
-
for (const [id, notify] of boundaryWaiters) {
|
|
2218
|
-
const el = boundaryIndex && boundaryIndex.get(id);
|
|
2219
|
-
if (!el && !exhausted) continue;
|
|
2220
|
-
boundaryWaiters.delete(id);
|
|
2221
|
-
notify(el);
|
|
2222
|
-
}
|
|
2223
1749
|
for (const [id, arrival] of arrivals) {
|
|
2224
1750
|
const el = boundaryIndex && boundaryIndex.get(id);
|
|
2225
1751
|
if (!el && !exhausted) continue;
|
|
@@ -2233,37 +1759,21 @@ function documentBoundary(host, id, props, binding) {
|
|
|
2233
1759
|
const claimed = claimedBoundaries.has(id);
|
|
2234
1760
|
const el = !claimed ? findBoundaryElement(id) : undefined;
|
|
2235
1761
|
if (el) return adoptBoundary(host, id, el, props, binding);
|
|
2236
|
-
if (!claimed &&
|
|
1762
|
+
if (!claimed && boundaryMayArrive()) {
|
|
2237
1763
|
const owner = getOwner();
|
|
2238
|
-
|
|
2239
|
-
onCleanup(() =>
|
|
2240
|
-
return createMemo(() =>
|
|
2241
|
-
|
|
1764
|
+
let live = true;
|
|
1765
|
+
onCleanup(() => live = false);
|
|
1766
|
+
return createMemo(() => awaitBoundary(id).then(() => live && runWithOwner(owner, () => {
|
|
1767
|
+
const node = claimedBoundaries.has(id) ? undefined : findBoundaryElement(id);
|
|
1768
|
+
return node ? adoptBoundary(host, id, node, props, binding) : boundaryComponent(host, id)(props, binding);
|
|
1769
|
+
})));
|
|
2242
1770
|
}
|
|
2243
1771
|
return boundaryComponent(host, id)(props, binding);
|
|
2244
1772
|
}
|
|
2245
|
-
function documentAddress(id) {
|
|
2246
|
-
const records = globalThis._$SC?.a;
|
|
2247
|
-
if (records) {
|
|
2248
|
-
for (const address in records) if (records[address] === id) return address;
|
|
2249
|
-
}
|
|
2250
|
-
return id;
|
|
2251
|
-
}
|
|
2252
1773
|
function adoptBoundary(host, id, el, props, binding) {
|
|
2253
1774
|
claimedBoundaries.add(id);
|
|
2254
|
-
const address = binding ? binding() :
|
|
1775
|
+
const address = binding ? contentAddress(binding()) : id;
|
|
2255
1776
|
const appliedRecords = new Set();
|
|
2256
|
-
const claimedFragments = new Set();
|
|
2257
|
-
const claimRegionFragments = root => {
|
|
2258
|
-
const fr = globalThis._$HY?.fr;
|
|
2259
|
-
if (!fr || !fr.claim) return;
|
|
2260
|
-
root.querySelectorAll('template[id^="pl-"]').forEach(tpl => {
|
|
2261
|
-
const fragId = tpl.id.slice(3);
|
|
2262
|
-
if (claimedFragments.has(fragId)) return;
|
|
2263
|
-
claimedFragments.add(fragId);
|
|
2264
|
-
fr.claim(fragId);
|
|
2265
|
-
});
|
|
2266
|
-
};
|
|
2267
1777
|
const drainRecords = () => {
|
|
2268
1778
|
const hy = globalThis._$HY;
|
|
2269
1779
|
if (!hy || !hy.r) return;
|
|
@@ -2273,13 +1783,17 @@ function adoptBoundary(host, id, el, props, binding) {
|
|
|
2273
1783
|
if (appliedRecords.has(key)) continue;
|
|
2274
1784
|
if (key.startsWith(slotPrefix)) {
|
|
2275
1785
|
appliedRecords.add(key);
|
|
2276
|
-
host.apply({
|
|
1786
|
+
const apply = args => host.apply({
|
|
2277
1787
|
type: "slot",
|
|
2278
1788
|
id: address,
|
|
2279
1789
|
version: 0,
|
|
2280
1790
|
key: key.slice(slotPrefix.length),
|
|
2281
|
-
args
|
|
1791
|
+
args
|
|
2282
1792
|
});
|
|
1793
|
+
const value = hy.r[key];
|
|
1794
|
+
if (value && typeof value.then === "function") {
|
|
1795
|
+
if (value.s === 1) apply(value.v);else if (value.s === 2) value.then(undefined, () => {});else value.then(apply, () => {});
|
|
1796
|
+
} else apply(value);
|
|
2283
1797
|
} else if (key.startsWith("sc:region:")) {
|
|
2284
1798
|
const childId = key.slice("sc:region:".length);
|
|
2285
1799
|
if (childId.startsWith(id + ".")) {
|
|
@@ -2296,14 +1810,18 @@ function adoptBoundary(host, id, el, props, binding) {
|
|
|
2296
1810
|
}
|
|
2297
1811
|
}
|
|
2298
1812
|
};
|
|
2299
|
-
claimRegionFragments(el);
|
|
2300
1813
|
const fr = globalThis._$HY?.fr;
|
|
1814
|
+
let frame;
|
|
2301
1815
|
const unsubscribe = fr ? fr.subscribe((_fragId, parent) => {
|
|
2302
|
-
|
|
1816
|
+
const inside = !!parent && el.contains(parent);
|
|
2303
1817
|
drainRecords();
|
|
1818
|
+
if (inside && frame) frame.apply({
|
|
1819
|
+
version: frame.version ?? 0,
|
|
1820
|
+
r: {}
|
|
1821
|
+
});
|
|
2304
1822
|
}) : undefined;
|
|
2305
1823
|
const applyLiveOp = op => {
|
|
2306
|
-
if (op.
|
|
1824
|
+
if (op.fid && op.fid !== id) return;
|
|
2307
1825
|
host.apply({
|
|
2308
1826
|
...op,
|
|
2309
1827
|
id: address,
|
|
@@ -2314,55 +1832,44 @@ function adoptBoundary(host, id, el, props, binding) {
|
|
|
2314
1832
|
onCleanup(() => {
|
|
2315
1833
|
liveAppliers.delete(applyLiveOp);
|
|
2316
1834
|
unsubscribe && unsubscribe();
|
|
2317
|
-
if (fr && fr.release) for (const fragId of claimedFragments) fr.release(fragId);
|
|
2318
1835
|
});
|
|
2319
1836
|
drainRecords();
|
|
2320
1837
|
for (const op of liveOps.values()) applyLiveOp(op);
|
|
2321
1838
|
const owner = getOwner();
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
1839
|
+
const sc = sharedConfig;
|
|
1840
|
+
const [failed, onApply] = failing();
|
|
1841
|
+
frame = createFrame(el, {
|
|
2325
1842
|
adopt: true,
|
|
2326
1843
|
host,
|
|
2327
1844
|
id: address,
|
|
2328
|
-
slots: slotsFor(props
|
|
1845
|
+
slots: slotsFor(props, {
|
|
1846
|
+
registry: sc.registry,
|
|
1847
|
+
gather: sc.gather
|
|
1848
|
+
}),
|
|
2329
1849
|
ownerScope: boundaryScope(owner),
|
|
2330
1850
|
reveal: revealSeam(owner),
|
|
2331
|
-
onApply
|
|
2332
|
-
|
|
2333
|
-
release();
|
|
2334
|
-
release = undefined;
|
|
2335
|
-
}
|
|
2336
|
-
setGate && setGate(undefined);
|
|
2337
|
-
},
|
|
1851
|
+
onApply,
|
|
1852
|
+
hold: () => sc.isHydrationInProgress?.() ? runWithOwner(owner, () => untrack(() => sc.holdBoundary("sc:" + id))) : () => {},
|
|
2338
1853
|
...{
|
|
2339
|
-
recordsPending: () => {
|
|
2340
|
-
if (document.readyState === "loading") return true;
|
|
2341
|
-
const hy = globalThis._$HY;
|
|
2342
|
-
return !!(hy && hy.fr && hy.fr.pending());
|
|
2343
|
-
},
|
|
2344
|
-
drainRecords,
|
|
2345
1854
|
claimScope: id
|
|
2346
1855
|
}
|
|
2347
1856
|
});
|
|
2348
1857
|
if (binding) {
|
|
2349
|
-
|
|
2350
|
-
const
|
|
2351
|
-
|
|
2352
|
-
const gate = createMemo(() => gatePromise());
|
|
2353
|
-
createRenderEffect(binding, (address, prev) => {
|
|
2354
|
-
if (prev !== undefined && address !== prev && tables.has(address)) {
|
|
2355
|
-
setGatePromise(arm());
|
|
2356
|
-
}
|
|
2357
|
-
frame.rebind(address);
|
|
2358
|
-
});
|
|
2359
|
-
createRenderEffect(() => (gate(), undefined), () => {});
|
|
1858
|
+
followAddress(host, frame, binding);
|
|
1859
|
+
const source = createMemo(() => landing(host, contentAddress(binding()), true, failed));
|
|
1860
|
+
createRenderEffect(() => source()(), () => {});
|
|
2360
1861
|
}
|
|
2361
|
-
onCleanup(() =>
|
|
1862
|
+
onCleanup(() => {
|
|
1863
|
+
frame.dispose();
|
|
1864
|
+
disposedFrames.add(el);
|
|
1865
|
+
el.querySelectorAll(FRAME_SELECTOR).forEach(e => disposedFrames.add(e));
|
|
1866
|
+
});
|
|
2362
1867
|
return el;
|
|
2363
1868
|
}
|
|
2364
|
-
function installServerComponents(host = getFrameHost()) {
|
|
1869
|
+
function installServerComponents(host = getFrameHost(), options) {
|
|
2365
1870
|
const g = globalThis;
|
|
1871
|
+
Object.assign(tierLoaders, options?.tiers);
|
|
1872
|
+
g._$HY?.r?.["sc:tiers"]?.forEach(prepareTier);
|
|
2366
1873
|
if (!g._$SC) {
|
|
2367
1874
|
g._$SC = {
|
|
2368
1875
|
c: {},
|
|
@@ -2387,7 +1894,6 @@ function installServerComponents(host = getFrameHost()) {
|
|
|
2387
1894
|
const handler = createServerComponentHandler({
|
|
2388
1895
|
host,
|
|
2389
1896
|
component: fnId => g._$SC.r(fnId),
|
|
2390
|
-
onStream: address => beginStream(address),
|
|
2391
1897
|
intercept: ({
|
|
2392
1898
|
id
|
|
2393
1899
|
}) => {
|
|
@@ -2407,4 +1913,4 @@ function installServerComponents(host = getFrameHost()) {
|
|
|
2407
1913
|
});
|
|
2408
1914
|
}
|
|
2409
1915
|
|
|
2410
|
-
export { FRAME_APPLIED_EVENT,
|
|
1916
|
+
export { FRAME_APPLIED_EVENT, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents, isAsyncValue, isFrameStreamResponse };
|