@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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DEV, OBSERVE, getOwner, onCleanup, createMemo, runWithOwner,
|
|
2
|
-
import { insert
|
|
3
|
-
import { frameAddress, SINGLE_FLIGHT_HEADER, LIVE_WIRE, deserializeStream, getServerFunctionsCodec, createChunk, deliverFlightData, ERROR_HEADER, hasFlightMetadata,
|
|
4
|
-
import {
|
|
1
|
+
import { DEV, OBSERVE, getOwner, onCleanup, createMemo, runWithOwner, untrack, createRenderEffect, createSignal, createOwner } from 'solid-js';
|
|
2
|
+
import { insert } from '@solidjs/web';
|
|
3
|
+
import { frameAddress, SINGLE_FLIGHT_HEADER, LIVE_WIRE, deserializeStream, getServerFunctionsCodec, createChunk, deliverFlightData, ERROR_HEADER, hasFlightMetadata, ChunkReader, configureServerFunctionsClient } from '@solidjs/web/server-functions/client';
|
|
4
|
+
import { sharedConfig, createLoadingBoundary } from 'solid-js/internal';
|
|
5
5
|
|
|
6
6
|
const ELEMENT_NODE = 1;
|
|
7
7
|
const TEXT_NODE = 3;
|
|
@@ -28,43 +28,25 @@ 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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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");
|
|
41
|
+
}
|
|
42
|
+
function slotShapeFinding(data, message) {
|
|
43
|
+
DEV.report(OBSERVE.diagnostics.emit({
|
|
44
|
+
code: "BINDING_SLOT_POSITION",
|
|
45
|
+
kind: "render",
|
|
46
|
+
severity: "warn",
|
|
47
|
+
message,
|
|
48
|
+
data
|
|
49
|
+
}, null));
|
|
68
50
|
}
|
|
69
51
|
function chunkToRecords(chunk) {
|
|
70
52
|
switch (chunk.type) {
|
|
@@ -125,9 +107,12 @@ function chunkToRecords(chunk) {
|
|
|
125
107
|
digest: chunk.digest
|
|
126
108
|
}
|
|
127
109
|
};
|
|
110
|
+
case "ops":
|
|
111
|
+
return Object.assign({}, ...chunk.ops.map(chunkToRecords));
|
|
128
112
|
case "complete":
|
|
129
113
|
return {
|
|
130
|
-
":complete": true
|
|
114
|
+
":complete": true,
|
|
115
|
+
":bound": chunk.bound
|
|
131
116
|
};
|
|
132
117
|
case "error":
|
|
133
118
|
if (!chunk.key) return {
|
|
@@ -151,11 +136,20 @@ function createFrameHost(options = {}) {
|
|
|
151
136
|
});
|
|
152
137
|
return store;
|
|
153
138
|
};
|
|
139
|
+
const landings = new Map();
|
|
140
|
+
const lands = records => "" in records || ":error" in records || ":complete" in records;
|
|
141
|
+
const applyTo = (id, version, r) => {
|
|
142
|
+
const set = frames.get(id);
|
|
143
|
+
if (set) for (const frame of set) frame.apply({
|
|
144
|
+
version,
|
|
145
|
+
r
|
|
146
|
+
});
|
|
147
|
+
};
|
|
154
148
|
const write = (store, version, records) => {
|
|
155
149
|
if (store.version !== undefined && version < store.version) return false;
|
|
156
150
|
if (store.version === undefined || version > store.version) {
|
|
157
151
|
store.version = version;
|
|
158
|
-
|
|
152
|
+
store.records = {};
|
|
159
153
|
}
|
|
160
154
|
const assets = records["seg::assets"];
|
|
161
155
|
const previous = assets && store.records["seg::assets"];
|
|
@@ -171,6 +165,33 @@ function createFrameHost(options = {}) {
|
|
|
171
165
|
}
|
|
172
166
|
return true;
|
|
173
167
|
};
|
|
168
|
+
const settleArgs = (store, recordKey, record, chunk) => {
|
|
169
|
+
const args = record.args;
|
|
170
|
+
const out = {};
|
|
171
|
+
let regions, decoded;
|
|
172
|
+
const settle = () => {
|
|
173
|
+
if (! --record.pending && store.records[recordKey] === record) applyTo(chunk.id, store.version, {
|
|
174
|
+
[recordKey]: record
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
for (const key in args) {
|
|
178
|
+
const value = args[key];
|
|
179
|
+
if (value && typeof value.$ref === "string") {
|
|
180
|
+
const resolved = out[key] = options.resolve && options.resolve(value, chunk.id, chunk.version, store.version);
|
|
181
|
+
(decoded ??= {})[key] = true;
|
|
182
|
+
if (resolved instanceof Promise && resolved.s === 0) {
|
|
183
|
+
record.pending = (record.pending || 0) + 1;
|
|
184
|
+
resolved.c.push(settle);
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
if (value && typeof value.$frame === "string") (regions ??= {})[key] = value.$frame;
|
|
188
|
+
out[key] = value;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
record.args = out;
|
|
192
|
+
record.regions = regions;
|
|
193
|
+
record.decoded = decoded;
|
|
194
|
+
};
|
|
174
195
|
return {
|
|
175
196
|
register(id, frame) {
|
|
176
197
|
let set = frames.get(id);
|
|
@@ -178,11 +199,13 @@ function createFrameHost(options = {}) {
|
|
|
178
199
|
set.add(frame);
|
|
179
200
|
const store = stores.get(id);
|
|
180
201
|
if (store && store.version !== undefined) {
|
|
181
|
-
frame.apply({
|
|
202
|
+
if (!store.open) frame.apply({
|
|
182
203
|
version: store.version,
|
|
183
204
|
r: store.records
|
|
205
|
+
});else if (store.shown) frame.apply({
|
|
206
|
+
version: store.shownVersion,
|
|
207
|
+
r: store.shown
|
|
184
208
|
});
|
|
185
|
-
frame.rebase && frame.rebase();
|
|
186
209
|
}
|
|
187
210
|
},
|
|
188
211
|
unregister(id, frame) {
|
|
@@ -200,26 +223,68 @@ function createFrameHost(options = {}) {
|
|
|
200
223
|
value: html
|
|
201
224
|
};
|
|
202
225
|
if (store.version === undefined) store.version = 0;
|
|
226
|
+
store.shown = store.records;
|
|
227
|
+
store.shownVersion = store.version;
|
|
203
228
|
}
|
|
204
229
|
}
|
|
205
230
|
}
|
|
206
231
|
}
|
|
207
|
-
if (!frame)
|
|
232
|
+
if (!frame) {
|
|
233
|
+
stores.delete(id);
|
|
234
|
+
landings.delete(id);
|
|
235
|
+
}
|
|
208
236
|
},
|
|
209
237
|
apply(chunk) {
|
|
210
238
|
if (chunk.type === "data") {
|
|
211
|
-
|
|
239
|
+
const store = stores.get(chunk.id);
|
|
240
|
+
const current = store && store.version;
|
|
241
|
+
if (store && chunk.version < current) return;
|
|
242
|
+
options.applyData && options.applyData(chunk, current);
|
|
212
243
|
return;
|
|
213
244
|
}
|
|
214
245
|
const records = chunkToRecords(chunk);
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
246
|
+
const store = storeFor(chunk.id);
|
|
247
|
+
if (!write(store, chunk.version, records)) return;
|
|
248
|
+
if (chunk.type === "slot") {
|
|
249
|
+
const key = `slot:${chunk.key}`;
|
|
250
|
+
settleArgs(store, key, records[key], chunk);
|
|
251
|
+
}
|
|
252
|
+
if (chunk.type === "complete" && chunk.bound) {
|
|
253
|
+
console.warn(`Server component "${chunk.id}" kept streaming past the server's ${chunk.bound} ` + `bound and was cut off (complete.bound: "${chunk.bound}"); its content is the last ` + `value the server sent, not a settled one. A source meant to keep streaming is ` + `declared with live(): wrap the server function (live(fn)) so the client holds a ` + `standing connection instead.`);
|
|
254
|
+
}
|
|
255
|
+
let r = records;
|
|
256
|
+
if (chunk.type === "start") store.open = true;else if (lands(records)) {
|
|
257
|
+
store.open = false;
|
|
258
|
+
store.shown = r = store.records;
|
|
259
|
+
store.shownVersion = chunk.version;
|
|
260
|
+
const landed = landings.get(chunk.id);
|
|
261
|
+
if (landed && !(":complete" in records && ":error" in r)) {
|
|
262
|
+
landings.delete(chunk.id);
|
|
263
|
+
":error" in records ? landed.j(records[":error"]) : landed.r();
|
|
264
|
+
}
|
|
222
265
|
}
|
|
266
|
+
applyTo(chunk.id, chunk.version, r);
|
|
267
|
+
if (":complete" in records || ":error" in records) options.closeData && options.closeData(chunk.id, chunk.version, records[":error"]);
|
|
268
|
+
},
|
|
269
|
+
landing(id) {
|
|
270
|
+
const store = stores.get(id);
|
|
271
|
+
if (!store || !store.open && !store.shown) return undefined;
|
|
272
|
+
if (store.shown && !(":error" in store.shown)) return undefined;
|
|
273
|
+
let wait = landings.get(id);
|
|
274
|
+
if (!wait) {
|
|
275
|
+
landings.set(id, wait = {});
|
|
276
|
+
wait.p = new Promise((r, j) => (wait.r = r, wait.j = j));
|
|
277
|
+
}
|
|
278
|
+
return wait.p;
|
|
279
|
+
},
|
|
280
|
+
preview(chunk) {
|
|
281
|
+
if (chunk.type !== "slot") return;
|
|
282
|
+
const set = frames.get(chunk.id);
|
|
283
|
+
if (!set) return;
|
|
284
|
+
const records = chunkToRecords(chunk);
|
|
285
|
+
const key = `slot:${chunk.key}`;
|
|
286
|
+
settleArgs(storeFor(chunk.id), key, records[key], chunk);
|
|
287
|
+
for (const frame of set) frame.preview && frame.preview(records);
|
|
223
288
|
},
|
|
224
289
|
get(id) {
|
|
225
290
|
const set = frames.get(id);
|
|
@@ -229,45 +294,51 @@ function createFrameHost(options = {}) {
|
|
|
229
294
|
if (!options.serialize) throw new Error("host has no serializer");
|
|
230
295
|
return options.serialize(value);
|
|
231
296
|
},
|
|
232
|
-
resolve(ref, frameId) {
|
|
233
|
-
return options.resolve ? options.resolve(ref, frameId) : undefined;
|
|
234
|
-
},
|
|
235
297
|
revive: options.revive,
|
|
236
|
-
isContainer: options.isContainer,
|
|
237
298
|
prepareData: options.prepareData
|
|
238
299
|
};
|
|
239
300
|
}
|
|
240
301
|
const FRAME_APPLIED_EVENT = "frame:applied";
|
|
302
|
+
const tierLoaders = {};
|
|
303
|
+
const tierLoads = {};
|
|
304
|
+
const liveFrames = new Set();
|
|
305
|
+
function prepareTier(name) {
|
|
306
|
+
let load = tierLoads[name];
|
|
307
|
+
if (!load) {
|
|
308
|
+
const loader = tierLoaders[name];
|
|
309
|
+
tierLoads[name] = load = loader ? loader().then(module => {
|
|
310
|
+
load.r = module;
|
|
311
|
+
module.install?.();
|
|
312
|
+
for (const frame of liveFrames) frame.apply({
|
|
313
|
+
version: frame.version,
|
|
314
|
+
r: {}
|
|
315
|
+
});
|
|
316
|
+
}) : Promise.resolve();
|
|
317
|
+
}
|
|
318
|
+
return load;
|
|
319
|
+
}
|
|
320
|
+
const tierReady = name => !tierLoaders[name] || prepareTier(name).r;
|
|
321
|
+
const needsRegions = record => record.regions && !tierReady("regions");
|
|
322
|
+
const carriesTrace = value => value != null && typeof value === "object" && (value.$tr != null || Object.values(value).some(carriesTrace));
|
|
323
|
+
const needsTrace = args => !tierLoads.trace?.r && carriesTrace(args) && !tierReady("trace");
|
|
241
324
|
class FrameImpl {
|
|
242
325
|
#element;
|
|
243
|
-
#start;
|
|
244
|
-
#end;
|
|
245
326
|
#options;
|
|
327
|
+
#outer;
|
|
246
328
|
#version;
|
|
247
329
|
#store = Object.create(null);
|
|
248
|
-
#
|
|
330
|
+
#appliedRoot;
|
|
331
|
+
#appliedError;
|
|
249
332
|
#hasContent = false;
|
|
250
|
-
#errorNotified = false;
|
|
251
|
-
#revealed = new Set();
|
|
252
|
-
#fallbackShown = new Set();
|
|
253
333
|
#appliedHoles = new Map();
|
|
254
|
-
#have;
|
|
255
334
|
#slots;
|
|
256
335
|
#mountedSlots = new Set();
|
|
257
336
|
#slotCleanups = new Map();
|
|
258
337
|
#slotArgs = new Map();
|
|
259
338
|
#slotUpdaters = new Map();
|
|
260
|
-
#
|
|
261
|
-
#
|
|
262
|
-
#slotNodes = new Map();
|
|
263
|
-
#slotConsumers = new Map();
|
|
264
|
-
#slotRebinders = new Map();
|
|
265
|
-
#processedAssets = new WeakSet();
|
|
266
|
-
#recordRefresh = null;
|
|
339
|
+
#hold;
|
|
340
|
+
#heldRecords = new Map();
|
|
267
341
|
#disposed = false;
|
|
268
|
-
#styleFlush = () => {
|
|
269
|
-
if (!this.#disposed) this.#flush();
|
|
270
|
-
};
|
|
271
342
|
#claimTree = (node, direct) => {
|
|
272
343
|
const handlers = claimHandlers();
|
|
273
344
|
if (!handlers) return;
|
|
@@ -277,12 +348,12 @@ class FrameImpl {
|
|
|
277
348
|
const scope = this.#options.ownerScope;
|
|
278
349
|
return scope ? scope(fn) : fn();
|
|
279
350
|
}
|
|
280
|
-
constructor(element,
|
|
351
|
+
constructor(element, options = {}) {
|
|
281
352
|
this.#element = element;
|
|
282
|
-
this.#start = start;
|
|
283
|
-
this.#end = end;
|
|
284
353
|
this.#options = options;
|
|
285
354
|
this.#slots = options.slots;
|
|
355
|
+
this.#outer = options.parent;
|
|
356
|
+
liveFrames.add(this);
|
|
286
357
|
if (options.adopt) {
|
|
287
358
|
this.#hasContent = true;
|
|
288
359
|
this.#claimContent();
|
|
@@ -292,15 +363,12 @@ class FrameImpl {
|
|
|
292
363
|
}
|
|
293
364
|
if (options.adopt && this.#version === undefined) this.#syncSlots();
|
|
294
365
|
}
|
|
295
|
-
#parent() {
|
|
296
|
-
return this.#element ?? this.#start.parentNode;
|
|
297
|
-
}
|
|
298
366
|
#applied(version, reason) {
|
|
299
367
|
this.#options.onApply?.({
|
|
300
368
|
version,
|
|
301
369
|
reason
|
|
302
370
|
});
|
|
303
|
-
const parent = this.#
|
|
371
|
+
const parent = this.#element;
|
|
304
372
|
const Ev = parent && (parent.ownerDocument || parent).defaultView?.CustomEvent;
|
|
305
373
|
if (Ev) {
|
|
306
374
|
parent.dispatchEvent(new Ev(FRAME_APPLIED_EVENT, {
|
|
@@ -313,18 +381,12 @@ class FrameImpl {
|
|
|
313
381
|
}));
|
|
314
382
|
}
|
|
315
383
|
}
|
|
316
|
-
#firstContent() {
|
|
317
|
-
return this.#start ? this.#start.nextSibling : this.#parent().firstChild;
|
|
318
|
-
}
|
|
319
384
|
get version() {
|
|
320
385
|
return this.#version;
|
|
321
386
|
}
|
|
322
387
|
get store() {
|
|
323
388
|
return this.#store;
|
|
324
389
|
}
|
|
325
|
-
isRevealed(segment) {
|
|
326
|
-
return this.#revealed.has(segment);
|
|
327
|
-
}
|
|
328
390
|
get error() {
|
|
329
391
|
return this.#store[":error"];
|
|
330
392
|
}
|
|
@@ -339,68 +401,59 @@ class FrameImpl {
|
|
|
339
401
|
this.#version = v;
|
|
340
402
|
this.#resetStreamState();
|
|
341
403
|
}
|
|
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
|
-
}
|
|
404
|
+
for (const key in write.r) this.#store[key] = write.r[key];
|
|
352
405
|
this.#flush();
|
|
353
406
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
this.#
|
|
407
|
+
preview(records, inherited) {
|
|
408
|
+
const adopted = new Set();
|
|
409
|
+
if (this.#disposed) return adopted;
|
|
410
|
+
const R = tierLoads.regions?.r;
|
|
411
|
+
for (const key in records) {
|
|
412
|
+
const record = records[key];
|
|
413
|
+
if (!record || record.kind !== "slot" || !key.startsWith("slot:")) continue;
|
|
414
|
+
if (inherited && key in this.#store) continue;
|
|
415
|
+
const occurrence = key.slice(5);
|
|
416
|
+
const update = this.#mountedSlots.has(occurrence) && this.#slotUpdaters.get(occurrence);
|
|
417
|
+
if (!update || (R ? R.changed(this, occurrence, record) : record.regions)) continue;
|
|
418
|
+
this.#slotArgs.set(occurrence, record);
|
|
419
|
+
adopted.add(key);
|
|
420
|
+
update(this.#resolveArgs(occurrence, record));
|
|
421
|
+
}
|
|
422
|
+
if (R) for (const frame of R.frames(this)) for (const key of frame.preview(records, true)) adopted.add(key);
|
|
423
|
+
if (!inherited) for (const key of adopted) this.#store[key] = records[key];
|
|
424
|
+
return adopted;
|
|
425
|
+
}
|
|
426
|
+
#resetStreamState() {
|
|
427
|
+
this.#store = Object.create(null);
|
|
428
|
+
this.#appliedRoot = this.#appliedError = undefined;
|
|
357
429
|
this.#appliedHoles.clear();
|
|
358
|
-
this.#processedAssets = new WeakSet();
|
|
359
|
-
this.#errorNotified = false;
|
|
360
|
-
clearStreamRecords(this.#store, root);
|
|
361
430
|
}
|
|
362
431
|
#flush() {
|
|
363
432
|
if (this.#disposed) return;
|
|
364
433
|
const version = this.#version;
|
|
365
434
|
const root = this.#store[""];
|
|
366
|
-
if (root && root.kind === "html" && root
|
|
435
|
+
if (root && root.kind === "html" && root !== this.#appliedRoot) {
|
|
367
436
|
const reason = this.#hasContent ? "morph" : "materialize";
|
|
368
437
|
this.#applyRoot(root.value);
|
|
369
|
-
this.#
|
|
370
|
-
this.#
|
|
371
|
-
"": root.digest,
|
|
372
|
-
...root.holes
|
|
373
|
-
};
|
|
438
|
+
this.#appliedRoot = root;
|
|
439
|
+
this.#recordHave("", root);
|
|
374
440
|
this.#applied(version, reason);
|
|
375
441
|
}
|
|
376
|
-
|
|
377
|
-
|
|
442
|
+
const error = this.#store[":error"];
|
|
443
|
+
if (error && error !== this.#appliedError) {
|
|
444
|
+
this.#appliedError = error;
|
|
378
445
|
this.#applied(version, "error");
|
|
379
446
|
}
|
|
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
|
-
}
|
|
447
|
+
for (const key in this.#store) {
|
|
448
|
+
const record = this.#store[key];
|
|
449
|
+
if (!key.endsWith(":assets") || !record || this.#appliedHoles.get(key) === record) continue;
|
|
450
|
+
const tier = tierReady("assets");
|
|
451
|
+
if (!tier) break;
|
|
452
|
+
this.#appliedHoles.set(key, record);
|
|
453
|
+
tier.apply(record);
|
|
454
|
+
}
|
|
455
|
+
this.#revealSegments();
|
|
456
|
+
let morphed = false;
|
|
404
457
|
for (const key in this.#store) {
|
|
405
458
|
const record = this.#store[key];
|
|
406
459
|
if (!record || this.#appliedHoles.get(key) === record) continue;
|
|
@@ -411,49 +464,40 @@ class FrameImpl {
|
|
|
411
464
|
} else if (this.#applyHole(key.slice(5), record.value)) {
|
|
412
465
|
this.#appliedHoles.set(key, record);
|
|
413
466
|
this.#recordHave(key.slice(5), record);
|
|
414
|
-
|
|
467
|
+
morphed = true;
|
|
415
468
|
}
|
|
416
469
|
} else if (key.startsWith("attr:")) {
|
|
417
470
|
if (this.#applyAttrs(key.slice(5), record.value, record.removed)) {
|
|
418
471
|
this.#appliedHoles.set(key, record);
|
|
419
472
|
this.#recordHave("lha:" + key.slice(5), record);
|
|
420
|
-
|
|
473
|
+
morphed = true;
|
|
421
474
|
}
|
|
422
475
|
}
|
|
423
476
|
}
|
|
424
|
-
|
|
425
|
-
const record = this.#store[key];
|
|
426
|
-
if (!key.endsWith(":assets") || !record || this.#processedAssets.has(record)) {
|
|
427
|
-
continue;
|
|
428
|
-
}
|
|
429
|
-
this.#processedAssets.add(record);
|
|
430
|
-
if (record.modules) {
|
|
431
|
-
for (const href of record.modules) ensureModulePreload(href);
|
|
432
|
-
}
|
|
433
|
-
if (record.preloads) {
|
|
434
|
-
for (const entry of record.preloads) ensurePreload(entry);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
477
|
+
if (morphed) this.#applied(version, "morph");
|
|
437
478
|
this.#syncSlots();
|
|
438
479
|
}
|
|
439
480
|
#resolveSlot(prop) {
|
|
440
|
-
return this.#slots?.[prop] ?? this.#
|
|
481
|
+
return this.#slots?.[prop] ?? (this.#outer && this.#outer.#resolveSlot(prop));
|
|
441
482
|
}
|
|
442
483
|
#resolveSlotRecord(occurrence) {
|
|
443
484
|
const record = this.#store[`slot:${occurrence}`];
|
|
444
485
|
if (record !== undefined) return record;
|
|
445
|
-
return this.#
|
|
486
|
+
return this.#outer && this.#outer.#resolveSlotRecord(occurrence);
|
|
446
487
|
}
|
|
447
488
|
#removeSlotRecord(occurrence) {
|
|
448
489
|
const key = `slot:${occurrence}`;
|
|
449
490
|
if (key in this.#store) {
|
|
450
491
|
if (!this.#mountedSlots.has(occurrence)) delete this.#store[key];
|
|
451
|
-
} else this.#
|
|
492
|
+
} else this.#outer && this.#outer.#removeSlotRecord(occurrence);
|
|
452
493
|
}
|
|
453
494
|
#syncSlots(root) {
|
|
454
|
-
if (!this.#slots && !this.#
|
|
495
|
+
if (!this.#slots && !this.#outer) return;
|
|
455
496
|
const found = new Map();
|
|
456
497
|
if (root) collectSlots(root.firstChild, null, found, found);else this.#collectSlots(found, found);
|
|
498
|
+
let waiting = false;
|
|
499
|
+
const R = tierLoads.regions?.r;
|
|
500
|
+
const B = tierLoads.bind?.r;
|
|
457
501
|
for (const [occurrence, start] of found) {
|
|
458
502
|
const callback = this.#resolveSlot(propOf(occurrence));
|
|
459
503
|
const consumers = Array.isArray(start) ? start : null;
|
|
@@ -462,76 +506,57 @@ class FrameImpl {
|
|
|
462
506
|
continue;
|
|
463
507
|
}
|
|
464
508
|
const record = this.#resolveSlotRecord(occurrence);
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
this.#mountedSlots.delete(occurrence);
|
|
471
|
-
this.#runSlotCleanups(occurrence);
|
|
509
|
+
const mounted = this.#mountedSlots.has(occurrence);
|
|
510
|
+
if (record === undefined && isCalled(occurrence)) {
|
|
511
|
+
waiting ||= !mounted;
|
|
512
|
+
if (consumers && !mounted && !this.#options.adopt) devSlotOrphan(this, occurrence, consumers, "record");
|
|
513
|
+
continue;
|
|
472
514
|
}
|
|
473
|
-
if (!
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
this.#recordRefresh = null;
|
|
477
|
-
if (this.#disposed) return;
|
|
478
|
-
this.#options.drainRecords?.();
|
|
479
|
-
this.#syncSlots();
|
|
480
|
-
});
|
|
481
|
-
continue;
|
|
482
|
-
}
|
|
483
|
-
if (consumers && record === undefined && occurrence.indexOf("#") !== -1) devSlotOrphan(this, occurrence, consumers, "record");
|
|
484
|
-
if (this.#options.adopt) this.#discoverRegions(occurrence, start);
|
|
485
|
-
const nodes = this.#invokeSlot(occurrence, callback, record, start, this.#options.adopt);
|
|
486
|
-
if (consumers) {
|
|
487
|
-
this.#slotNodes.set(occurrence, consumers.map(c => c.element));
|
|
488
|
-
this.#slotConsumers.set(occurrence, consumers);
|
|
489
|
-
} else {
|
|
490
|
-
if (nodes) this.#replaceRange(occurrence, start, nodes);
|
|
491
|
-
this.#slotNodes.set(occurrence, nodes);
|
|
492
|
-
}
|
|
493
|
-
this.#mountedSlots.add(occurrence);
|
|
494
|
-
if (!this.#options.adopt || nodes) this.#discoverRegions(occurrence, start);
|
|
495
|
-
this.#bindRegions(occurrence);
|
|
515
|
+
if (!mounted && record && (record.pending || needsRegions(record) || needsTrace(record.args))) {
|
|
516
|
+
waiting = true;
|
|
517
|
+
if (this.#options.adopt && !consumers) this.#heldRecords.has(occurrence) || this.#heldRecords.set(occurrence, record);
|
|
496
518
|
continue;
|
|
497
519
|
}
|
|
498
|
-
if (
|
|
499
|
-
this.#
|
|
500
|
-
this.#
|
|
501
|
-
const
|
|
502
|
-
|
|
520
|
+
if (!mounted) {
|
|
521
|
+
const held = this.#heldRecords.get(occurrence);
|
|
522
|
+
this.#heldRecords.delete(occurrence);
|
|
523
|
+
const mountRecord = held || record;
|
|
524
|
+
this.#invokeSlot(occurrence, callback, mountRecord, start, this.#options.adopt);
|
|
525
|
+
if (consumers) B.sync(this, occurrence, consumers);
|
|
526
|
+
this.#mountedSlots.add(occurrence);
|
|
527
|
+
R?.bind(this, occurrence);
|
|
528
|
+
if (mountRecord === record || !record || record.kind !== "slot") continue;
|
|
503
529
|
}
|
|
530
|
+
if (consumers) B.sync(this, occurrence, consumers);
|
|
504
531
|
if (record !== this.#slotArgs.get(occurrence)) {
|
|
505
|
-
if (
|
|
506
|
-
this.#slotArgs.set(occurrence, record);
|
|
507
|
-
this.#reconcileRegions(occurrence, record);
|
|
508
|
-
continue;
|
|
509
|
-
}
|
|
532
|
+
if (needsRegions(record) || needsTrace(record.args)) continue;
|
|
510
533
|
const update = this.#slotUpdaters.get(occurrence);
|
|
511
534
|
if (update) {
|
|
512
|
-
const props = this.#resolveArgs(occurrence, record
|
|
535
|
+
const props = this.#resolveArgs(occurrence, record);
|
|
513
536
|
this.#slotArgs.set(occurrence, record);
|
|
514
537
|
update(props);
|
|
515
|
-
this
|
|
538
|
+
R?.bind(this, occurrence);
|
|
516
539
|
continue;
|
|
517
540
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
if (nodes) this.#replaceRange(occurrence, start, nodes);
|
|
521
|
-
this.#slotNodes.set(occurrence, nodes);
|
|
522
|
-
}
|
|
523
|
-
this.#bindRegions(occurrence);
|
|
541
|
+
this.#invokeSlot(occurrence, callback, record, start);
|
|
542
|
+
R?.bind(this, occurrence);
|
|
524
543
|
}
|
|
525
544
|
}
|
|
545
|
+
if (found.b && !tierReady("bind")) waiting = true;
|
|
526
546
|
if (!root) {
|
|
527
547
|
for (const occurrence of [...this.#mountedSlots]) {
|
|
528
548
|
if (!found.has(occurrence)) this.#unmountSlot(occurrence);
|
|
529
549
|
}
|
|
550
|
+
if (waiting && !this.#hold) this.#hold = this.#options.hold?.();else if (!waiting && this.#hold) this.#releaseHold();
|
|
530
551
|
}
|
|
531
552
|
}
|
|
553
|
+
#releaseHold() {
|
|
554
|
+
const release = this.#hold;
|
|
555
|
+
this.#hold = undefined;
|
|
556
|
+
release && release();
|
|
557
|
+
}
|
|
532
558
|
#invokeSlot(occurrence, callback, record, start, adopted) {
|
|
533
559
|
this.#slotUpdaters.delete(occurrence);
|
|
534
|
-
this.#slotRebinders.delete(occurrence);
|
|
535
560
|
const cleanups = this.#slotCleanups.get(occurrence) ?? [];
|
|
536
561
|
let existing = [];
|
|
537
562
|
let end = null;
|
|
@@ -550,35 +575,22 @@ class FrameImpl {
|
|
|
550
575
|
end
|
|
551
576
|
} : undefined,
|
|
552
577
|
positions,
|
|
553
|
-
onRebind: positions ? fn =>
|
|
578
|
+
onRebind: positions ? fn => tierLoads.bind.r.rebinder(this, occurrence, fn) : undefined
|
|
554
579
|
};
|
|
555
|
-
const props = record && record.kind === "slot" ? this.#resolveArgs(occurrence, record
|
|
556
|
-
|
|
580
|
+
const props = record && record.kind === "slot" ? this.#resolveArgs(occurrence, record, adopted, start) : {};
|
|
581
|
+
this.#scoped(() => callback(props, ctx));
|
|
557
582
|
this.#slotArgs.set(occurrence, record);
|
|
558
583
|
if (cleanups.length) this.#slotCleanups.set(occurrence, cleanups);
|
|
559
|
-
if (content == null) return null;
|
|
560
|
-
return Array.isArray(content) ? content : [content];
|
|
561
|
-
}
|
|
562
|
-
#replaceRange(key, start, nodes) {
|
|
563
|
-
const parent = start.parentNode;
|
|
564
|
-
const end = eachInRange(start, key, n => parent.removeChild(n));
|
|
565
|
-
for (const node of nodes) parent.insertBefore(node, end);
|
|
566
584
|
}
|
|
567
585
|
#unmountSlot(key) {
|
|
568
586
|
this.#mountedSlots.delete(key);
|
|
569
|
-
this.#slotNodes.delete(key);
|
|
570
|
-
this.#slotConsumers.delete(key);
|
|
571
587
|
this.#slotArgs.delete(key);
|
|
572
588
|
this.#slotUpdaters.delete(key);
|
|
573
|
-
this.#
|
|
574
|
-
this.#slotResolvedRefs.delete(key);
|
|
589
|
+
this.#heldRecords.delete(key);
|
|
575
590
|
this.#removeSlotRecord(key);
|
|
576
591
|
this.#runSlotCleanups(key);
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
disposeRegions(regions);
|
|
580
|
-
this.#slotRegions.delete(key);
|
|
581
|
-
}
|
|
592
|
+
tierLoads.regions?.r?.unmount(this, key);
|
|
593
|
+
tierLoads.bind?.r?.unmount(this, key);
|
|
582
594
|
}
|
|
583
595
|
#runSlotCleanups(key) {
|
|
584
596
|
const cleanups = this.#slotCleanups.get(key);
|
|
@@ -586,129 +598,33 @@ class FrameImpl {
|
|
|
586
598
|
this.#slotCleanups.delete(key);
|
|
587
599
|
for (const fn of cleanups) fn();
|
|
588
600
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
host,
|
|
592
|
-
id
|
|
593
|
-
} = this.#options;
|
|
594
|
-
if (host) for (const key in args) {
|
|
595
|
-
if (isDataRef(args[key]) && host.resolve(args[key], id) === undefined) return true;
|
|
596
|
-
}
|
|
597
|
-
return false;
|
|
598
|
-
}
|
|
599
|
-
#regionsFor(slotKey) {
|
|
600
|
-
let regions = this.#slotRegions.get(slotKey);
|
|
601
|
-
if (!regions) this.#slotRegions.set(slotKey, regions = new Map());
|
|
602
|
-
return regions;
|
|
601
|
+
get options() {
|
|
602
|
+
return this.#options;
|
|
603
603
|
}
|
|
604
|
-
#resolveArgs(slotKey,
|
|
605
|
-
const
|
|
606
|
-
|
|
604
|
+
#resolveArgs(slotKey, record, claiming, start) {
|
|
605
|
+
const {
|
|
606
|
+
args,
|
|
607
|
+
regions,
|
|
608
|
+
decoded
|
|
609
|
+
} = record;
|
|
610
|
+
const revive = this.#options.host && this.#options.host.revive;
|
|
607
611
|
const props = {};
|
|
608
612
|
for (const key in args) {
|
|
613
|
+
if (regions && key in regions) continue;
|
|
609
614
|
const value = args[key];
|
|
610
|
-
|
|
611
|
-
const resolved = host ? host.resolve(value, this.#options.id) : undefined;
|
|
612
|
-
let cache = this.#slotResolvedRefs.get(slotKey);
|
|
613
|
-
if (!cache) this.#slotResolvedRefs.set(slotKey, cache = {});
|
|
614
|
-
cache[key] = resolved;
|
|
615
|
-
props[key] = resolved;
|
|
616
|
-
} else if (isFrameRef(value)) {
|
|
617
|
-
let entry = regions.get(key);
|
|
618
|
-
if (!entry) {
|
|
619
|
-
const element = makeFrameElement(value.$frame);
|
|
620
|
-
entry = {
|
|
621
|
-
childId: value.$frame,
|
|
622
|
-
element,
|
|
623
|
-
frame: undefined
|
|
624
|
-
};
|
|
625
|
-
regions.set(key, entry);
|
|
626
|
-
} else if (entry.childId !== value.$frame) {
|
|
627
|
-
renameRegion(entry, value.$frame);
|
|
628
|
-
}
|
|
629
|
-
props[key] = entry.element;
|
|
630
|
-
} else {
|
|
631
|
-
props[key] = host && host.revive ? host.revive(value) : value;
|
|
632
|
-
}
|
|
615
|
+
props[key] = revive && !(decoded && key in decoded) ? revive(value, claiming) : value;
|
|
633
616
|
}
|
|
617
|
+
if (regions) tierLoads.regions.r.resolve(this, slotKey, regions, props, claiming && start);
|
|
634
618
|
return props;
|
|
635
619
|
}
|
|
636
|
-
#discoverRegions(slotKey, start) {
|
|
637
|
-
if (!start || Array.isArray(start)) return;
|
|
638
|
-
const regions = this.#regionsFor(slotKey);
|
|
639
|
-
eachInRange(start, slotKey, n => collectRegionElements(n, regions));
|
|
640
|
-
}
|
|
641
|
-
#refArgsUnchanged(occurrence, record) {
|
|
642
|
-
const old = this.#slotArgs.get(occurrence);
|
|
643
|
-
if (!record || record.kind !== "slot") return false;
|
|
644
|
-
if (old && old.kind !== "slot") return false;
|
|
645
|
-
const a = old && old.args || {};
|
|
646
|
-
const b = record.args || {};
|
|
647
|
-
const ka = Object.keys(a);
|
|
648
|
-
const kb = Object.keys(b);
|
|
649
|
-
if (kb.length !== ka.length) return false;
|
|
650
|
-
const cache = this.#slotResolvedRefs.get(occurrence);
|
|
651
|
-
for (const key of ka) {
|
|
652
|
-
const va = a[key];
|
|
653
|
-
const vb = b[key];
|
|
654
|
-
if (va === vb) continue;
|
|
655
|
-
if (isFrameRef(va) && isFrameRef(vb)) continue;
|
|
656
|
-
if (isDataRef(va) && isDataRef(vb) && cache && key in cache) {
|
|
657
|
-
const host = this.#options.host;
|
|
658
|
-
const next = host ? host.resolve(vb, this.#options.id) : undefined;
|
|
659
|
-
if (host && host.isContainer && (host.isContainer(next) || host.isContainer(cache[key]))) {
|
|
660
|
-
if (next === cache[key]) continue;
|
|
661
|
-
return false;
|
|
662
|
-
}
|
|
663
|
-
if (isAsyncLike(next) || isAsyncLike(cache[key])) return false;
|
|
664
|
-
try {
|
|
665
|
-
if (JSON.stringify(next) === JSON.stringify(cache[key])) continue;
|
|
666
|
-
} catch (e) {
|
|
667
|
-
return false;
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
return false;
|
|
671
|
-
}
|
|
672
|
-
return true;
|
|
673
|
-
}
|
|
674
|
-
#reconcileRegions(occurrence, record) {
|
|
675
|
-
const args = record && record.args;
|
|
676
|
-
if (!args) return;
|
|
677
|
-
const regions = this.#slotRegions.get(occurrence);
|
|
678
|
-
if (!regions) return;
|
|
679
|
-
for (const key in args) {
|
|
680
|
-
const value = args[key];
|
|
681
|
-
if (!isFrameRef(value)) continue;
|
|
682
|
-
const entry = regions.get(key);
|
|
683
|
-
if (entry && entry.childId !== value.$frame) renameRegion(entry, value.$frame);
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
#bindRegions(slotKey) {
|
|
687
|
-
const regions = this.#slotRegions.get(slotKey);
|
|
688
|
-
if (!regions) return;
|
|
689
|
-
for (const entry of regions.values()) {
|
|
690
|
-
if (!entry.frame) {
|
|
691
|
-
entry.frame = new FrameImpl(entry.element, null, null, {
|
|
692
|
-
id: entry.childId,
|
|
693
|
-
host: this.#options.host,
|
|
694
|
-
adopt: entry.adopt,
|
|
695
|
-
claimScope: this.#options.claimScope ?? this.#options.id,
|
|
696
|
-
ownerScope: this.#options.ownerScope,
|
|
697
|
-
resolveSlot: prop => this.#resolveSlot(prop),
|
|
698
|
-
resolveSlotRecord: occurrence => this.#resolveSlotRecord(occurrence),
|
|
699
|
-
removeSlotRecord: occurrence => this.#removeSlotRecord(occurrence)
|
|
700
|
-
});
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
620
|
#collectSlots(found, elements) {
|
|
705
|
-
collectSlots(this.#
|
|
621
|
+
collectSlots(this.#element.firstChild, null, found, elements);
|
|
706
622
|
}
|
|
707
|
-
#findPlaceholder(name) {
|
|
708
|
-
return findPlaceholder(this.#
|
|
623
|
+
#findPlaceholder(name, root) {
|
|
624
|
+
return findPlaceholder((root || this.#element).firstChild, null, placeholderId(name));
|
|
709
625
|
}
|
|
710
626
|
contentHTML() {
|
|
711
|
-
if (this.#disposed || !this.#
|
|
627
|
+
if (this.#disposed || !this.#hasContent) return null;
|
|
712
628
|
return this.#element.innerHTML;
|
|
713
629
|
}
|
|
714
630
|
rebind(id) {
|
|
@@ -726,20 +642,11 @@ class FrameImpl {
|
|
|
726
642
|
this.#element.setAttribute(FRAME_ID_ATTR, id);
|
|
727
643
|
}
|
|
728
644
|
this.#version = undefined;
|
|
729
|
-
this.#
|
|
730
|
-
this.#resetStreamState(true);
|
|
645
|
+
this.#resetStreamState();
|
|
731
646
|
if (host) host.register(id, this);
|
|
732
647
|
}
|
|
733
|
-
rebase() {
|
|
734
|
-
this.#version = undefined;
|
|
735
|
-
}
|
|
736
|
-
have() {
|
|
737
|
-
return this.#have;
|
|
738
|
-
}
|
|
739
648
|
#recordHave(key, record) {
|
|
740
|
-
|
|
741
|
-
this.#have[key] = record.digest;
|
|
742
|
-
if (record.holes) Object.assign(this.#have, record.holes);
|
|
649
|
+
tierLoads.wire?.r?.have(this, key, record);
|
|
743
650
|
}
|
|
744
651
|
dispose() {
|
|
745
652
|
if (this.#disposed) return;
|
|
@@ -749,36 +656,33 @@ class FrameImpl {
|
|
|
749
656
|
} = this.#options;
|
|
750
657
|
if (host && id !== undefined) host.unregister(id, this);
|
|
751
658
|
this.#disposed = true;
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
this.#recordRefresh = null;
|
|
755
|
-
}
|
|
659
|
+
liveFrames.delete(this);
|
|
660
|
+
this.#releaseHold();
|
|
756
661
|
for (const key of [...this.#slotCleanups.keys()]) this.#runSlotCleanups(key);
|
|
757
662
|
for (const key of this.#mountedSlots) this.#removeSlotRecord(key);
|
|
758
|
-
|
|
759
|
-
this.#slotRegions.clear();
|
|
663
|
+
tierLoads.regions?.r?.unmount(this);
|
|
760
664
|
this.#mountedSlots.clear();
|
|
761
665
|
}
|
|
762
666
|
#applyRoot(html) {
|
|
763
667
|
const fragment = parseFragment(html);
|
|
764
|
-
const parent = this.#
|
|
668
|
+
const parent = this.#element;
|
|
765
669
|
if (!this.#hasContent) {
|
|
766
|
-
|
|
670
|
+
parent.textContent = "";
|
|
767
671
|
this.#claimTree(fragment);
|
|
768
|
-
parent.
|
|
672
|
+
parent.appendChild(fragment);
|
|
769
673
|
this.#hasContent = true;
|
|
770
674
|
} else {
|
|
771
675
|
const claim = this.#claimTree;
|
|
772
676
|
const ranges = new Map();
|
|
773
677
|
this.#collectSlots(ranges);
|
|
774
678
|
const grafts = [];
|
|
775
|
-
reconcileChildren(parent, fragment,
|
|
679
|
+
reconcileChildren(parent, fragment, null, null, claim, ranges, grafts);
|
|
776
680
|
if (ranges.size) for (const root of grafts) flushGrafts(root, ranges);
|
|
777
681
|
}
|
|
778
682
|
}
|
|
779
683
|
#applyHole(marker, html) {
|
|
780
684
|
if (!this.#hasContent) return false;
|
|
781
|
-
const open = findLiveTarget(this.#
|
|
685
|
+
const open = findLiveTarget(this.#element.firstChild, null, n => n.nodeType === COMMENT_NODE && n.data === marker);
|
|
782
686
|
if (!open) return false;
|
|
783
687
|
const close = rangeClose(open, "lh:/" + marker.slice(3));
|
|
784
688
|
if (!close) {
|
|
@@ -792,7 +696,7 @@ class FrameImpl {
|
|
|
792
696
|
}
|
|
793
697
|
#applyAttrs(addr, text, removed) {
|
|
794
698
|
if (!this.#hasContent) return false;
|
|
795
|
-
const el = findLiveTarget(this.#
|
|
699
|
+
const el = findLiveTarget(this.#element.firstChild, null, n => n.nodeType === ELEMENT_NODE && n.getAttribute("data-lha") === addr);
|
|
796
700
|
if (!el) return false;
|
|
797
701
|
const parsed = parseFragment(`<i${text}></i>`).firstChild;
|
|
798
702
|
const keepOpen = preservesOpen(el);
|
|
@@ -824,69 +728,66 @@ class FrameImpl {
|
|
|
824
728
|
}
|
|
825
729
|
return true;
|
|
826
730
|
}
|
|
827
|
-
#clearContent() {
|
|
828
|
-
removeUntil(this.#parent(), this.#firstContent(), this.#end);
|
|
829
|
-
}
|
|
830
731
|
#claimContent() {
|
|
831
|
-
let n = this.#
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
732
|
+
for (let n = this.#element.firstChild; n; n = n.nextSibling) this.#claimTree(n);
|
|
733
|
+
}
|
|
734
|
+
#revealSegments(root) {
|
|
735
|
+
const version = this.#version;
|
|
736
|
+
for (const key in this.#store) {
|
|
737
|
+
const record = this.#store[key];
|
|
738
|
+
const name = segmentName(key);
|
|
739
|
+
if (name === null || !record || this.#appliedHoles.get(key) === record) continue;
|
|
740
|
+
if (this.#segmentReady(name, root)) {
|
|
741
|
+
this.#appliedHoles.set(key, record);
|
|
742
|
+
this.#revealSegment(name, root);
|
|
743
|
+
this.#applied(version, "reveal");
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
for (const key in this.#store) {
|
|
747
|
+
const m = /^seg:([^:]+):fallback$/.exec(key);
|
|
748
|
+
if (!m || this.#appliedHoles.has(key) || this.#appliedHoles.has(`seg:${m[1]}`)) continue;
|
|
749
|
+
if (this.#showFallback(m[1], root)) {
|
|
750
|
+
this.#appliedHoles.set(key, this.#store[key]);
|
|
751
|
+
this.#applied(version, "reveal");
|
|
752
|
+
}
|
|
835
753
|
}
|
|
836
754
|
}
|
|
837
|
-
#segmentReady(name) {
|
|
755
|
+
#segmentReady(name, root) {
|
|
838
756
|
const content = this.#store[`seg:${name}`];
|
|
839
757
|
if (!content || content.kind !== "html") return false;
|
|
840
758
|
if (!this.#store[`seg:${name}:reveal`]) return false;
|
|
841
759
|
const assets = this.#store[`seg:${name}:assets`];
|
|
842
|
-
if (assets && assets.styles)
|
|
843
|
-
|
|
844
|
-
for (const entry of assets.styles) ready = ensureStylesheet(entry, this.#styleFlush) && ready;
|
|
845
|
-
if (!ready) return false;
|
|
846
|
-
}
|
|
847
|
-
if (!this.#findPlaceholder(name)) return false;
|
|
848
|
-
return true;
|
|
760
|
+
if (assets && (assets.styles || assets.inlineStyles) && !tierReady("assets")?.gate(assets.styles || [], this)) return false;
|
|
761
|
+
return !!this.#findPlaceholder(name, root);
|
|
849
762
|
}
|
|
850
|
-
#revealSegment(name) {
|
|
851
|
-
const tpl = this.#findPlaceholder(name);
|
|
763
|
+
#revealSegment(name, root) {
|
|
764
|
+
const tpl = this.#findPlaceholder(name, root);
|
|
852
765
|
if (!tpl) return;
|
|
853
|
-
const assets = this.#store[`seg:${name}:assets`];
|
|
854
|
-
if (assets && assets.inlineStyles) applyInlineStyles(assets.inlineStyles);
|
|
855
766
|
const content = this.#store[`seg:${name}`];
|
|
856
767
|
const closing = rangeClose(tpl, placeholderId(name));
|
|
857
768
|
if (!closing) {
|
|
858
|
-
console.error(`Frame fragment placeholder "${name}" is missing its closing comment ` + `(<!--${placeholderId(name)}-->);
|
|
859
|
-
}
|
|
860
|
-
const parent = tpl.parentNode;
|
|
861
|
-
removeUntil(parent, tpl.nextSibling, closing);
|
|
862
|
-
if (this.#options.reveal) {
|
|
863
|
-
const fallbackFrag = tpl.content.cloneNode(true);
|
|
864
|
-
this.#claimTree(fallbackFrag);
|
|
865
|
-
this.#options.reveal({
|
|
866
|
-
before: closing,
|
|
867
|
-
fallback: [...fallbackFrag.childNodes],
|
|
868
|
-
content: () => {
|
|
869
|
-
const materialized = this.#materialize(content);
|
|
870
|
-
this.#syncSlots(materialized);
|
|
871
|
-
this.#claimTree(materialized);
|
|
872
|
-
return materialized;
|
|
873
|
-
}
|
|
874
|
-
});
|
|
875
|
-
tpl.remove();
|
|
876
|
-
this.#revealed.add(name);
|
|
877
|
-
this.#recordHave(name, content);
|
|
769
|
+
console.error(`Frame fragment placeholder "${name}" is missing its closing comment ` + `(<!--${placeholderId(name)}-->); the segment is not revealed. Likely an ` + `HTML-rewriting layer stripped the comment, or invalid nesting split the ` + `placeholder range.`, tpl);
|
|
878
770
|
return;
|
|
879
771
|
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
772
|
+
removeUntil(tpl.parentNode, tpl.nextSibling, closing);
|
|
773
|
+
const fallbackFrag = tpl.content.cloneNode(true);
|
|
774
|
+
this.#claimTree(fallbackFrag);
|
|
775
|
+
(this.#options.reveal || revealAtOnce)({
|
|
776
|
+
before: closing,
|
|
777
|
+
fallback: [...fallbackFrag.childNodes],
|
|
778
|
+
content: () => {
|
|
779
|
+
const materialized = this.#materialize(content);
|
|
780
|
+
this.#syncSlots(materialized);
|
|
781
|
+
this.#claimTree(materialized);
|
|
782
|
+
this.#revealSegments(materialized);
|
|
783
|
+
return materialized;
|
|
784
|
+
}
|
|
785
|
+
});
|
|
883
786
|
tpl.remove();
|
|
884
|
-
closing && closing.remove();
|
|
885
|
-
this.#revealed.add(name);
|
|
886
787
|
this.#recordHave(name, content);
|
|
887
788
|
}
|
|
888
|
-
#showFallback(name) {
|
|
889
|
-
const tpl = this.#findPlaceholder(name);
|
|
789
|
+
#showFallback(name, root) {
|
|
790
|
+
const tpl = this.#findPlaceholder(name, root);
|
|
890
791
|
if (!tpl) return false;
|
|
891
792
|
const closing = rangeClose(tpl, placeholderId(name));
|
|
892
793
|
if (!closing) return false;
|
|
@@ -900,13 +801,13 @@ class FrameImpl {
|
|
|
900
801
|
}
|
|
901
802
|
}
|
|
902
803
|
function createFrame(boundary, options) {
|
|
903
|
-
return new FrameImpl(boundary,
|
|
804
|
+
return new FrameImpl(boundary, options);
|
|
904
805
|
}
|
|
905
806
|
const FRAME_TAG = "solid-frame";
|
|
906
807
|
const FRAME_ID_ATTR = "data-fid";
|
|
907
808
|
function createFrameElement(options) {
|
|
908
809
|
const el = makeFrameElement(options.id);
|
|
909
|
-
const frame = new FrameImpl(el,
|
|
810
|
+
const frame = new FrameImpl(el, options);
|
|
910
811
|
return {
|
|
911
812
|
element: el,
|
|
912
813
|
frame,
|
|
@@ -929,23 +830,16 @@ function segmentName(key) {
|
|
|
929
830
|
const m = /^seg:([^:]+)$/.exec(key);
|
|
930
831
|
return m ? m[1] : null;
|
|
931
832
|
}
|
|
932
|
-
function isAsyncLike(v) {
|
|
933
|
-
return !!v && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
|
|
934
|
-
}
|
|
935
833
|
function propOf(occurrence) {
|
|
936
834
|
const hash = occurrence.indexOf("#");
|
|
937
835
|
return hash === -1 ? occurrence : occurrence.slice(0, hash);
|
|
938
836
|
}
|
|
939
|
-
function
|
|
940
|
-
return
|
|
941
|
-
}
|
|
942
|
-
function isFrameRef(value) {
|
|
943
|
-
return !!value && typeof value.$frame === "string";
|
|
837
|
+
function isCalled(occurrence) {
|
|
838
|
+
return occurrence.indexOf("#") !== -1;
|
|
944
839
|
}
|
|
945
|
-
function
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
} of regions.values()) frame?.dispose();
|
|
840
|
+
function revealAtOnce(seam) {
|
|
841
|
+
seam.before.parentNode.insertBefore(seam.content(), seam.before);
|
|
842
|
+
seam.before.remove();
|
|
949
843
|
}
|
|
950
844
|
function removeUntil(parent, n, stop) {
|
|
951
845
|
while (n && n !== stop) {
|
|
@@ -959,80 +853,6 @@ function parseFragment(html) {
|
|
|
959
853
|
template.innerHTML = html;
|
|
960
854
|
return template.content;
|
|
961
855
|
}
|
|
962
|
-
const PRELOAD_QUALIFIERS = ["as", "crossorigin", "type", "media", "imagesrcset", "imagesizes"];
|
|
963
|
-
function qualifierValue(name, value) {
|
|
964
|
-
if (value == null) return null;
|
|
965
|
-
if (name === "imagesrcset" || name === "imagesizes") return value === "" ? null : value;
|
|
966
|
-
if (name === "as") return value.replace(/[A-Z]/g, c => String.fromCharCode(c.charCodeAt(0) + 32));
|
|
967
|
-
if (name !== "crossorigin") return value;
|
|
968
|
-
return value.length === 15 && value.toLowerCase() === "use-credentials" ? "use-credentials" : "anonymous";
|
|
969
|
-
}
|
|
970
|
-
function findHeadElement(selector, attr, value, qualifiers) {
|
|
971
|
-
candidate: for (const node of document.head.querySelectorAll(selector)) {
|
|
972
|
-
if (node.getAttribute(attr) !== value) continue;
|
|
973
|
-
if (!qualifiers) return node;
|
|
974
|
-
for (let i = 0; i < PRELOAD_QUALIFIERS.length; i++) {
|
|
975
|
-
const name = PRELOAD_QUALIFIERS[i];
|
|
976
|
-
if (qualifierValue(name, node.getAttribute(name)) !== qualifierValue(name, qualifiers[name] ?? null)) continue candidate;
|
|
977
|
-
}
|
|
978
|
-
return node;
|
|
979
|
-
}
|
|
980
|
-
return null;
|
|
981
|
-
}
|
|
982
|
-
function ensurePreload(entry) {
|
|
983
|
-
const attrs = entry.attrs;
|
|
984
|
-
const href = entry.href;
|
|
985
|
-
if (findHeadElement('link[rel="preload"]', "href", href || null, attrs)) return;
|
|
986
|
-
const link = document.createElement("link");
|
|
987
|
-
link.rel = "preload";
|
|
988
|
-
for (const name in attrs) link.setAttribute(name, attrs[name]);
|
|
989
|
-
if (href) link.setAttribute("href", href);
|
|
990
|
-
document.head.appendChild(link);
|
|
991
|
-
}
|
|
992
|
-
function ensureStylesheet(entry, onSettle) {
|
|
993
|
-
const href = typeof entry === "string" ? entry : entry.href;
|
|
994
|
-
let link = findHeadElement('link[rel="stylesheet"]', "href", href);
|
|
995
|
-
if (!link) {
|
|
996
|
-
link = document.createElement("link");
|
|
997
|
-
link.rel = "stylesheet";
|
|
998
|
-
if (typeof entry !== "string" && entry.attrs) {
|
|
999
|
-
for (const name in entry.attrs) link.setAttribute(name, entry.attrs[name]);
|
|
1000
|
-
}
|
|
1001
|
-
link.href = href;
|
|
1002
|
-
const waiters = new Set();
|
|
1003
|
-
link._$frWaiters = waiters;
|
|
1004
|
-
const settle = () => {
|
|
1005
|
-
link._$frWaiters = null;
|
|
1006
|
-
for (const fn of waiters) fn();
|
|
1007
|
-
};
|
|
1008
|
-
link.addEventListener("load", settle);
|
|
1009
|
-
link.addEventListener("error", settle);
|
|
1010
|
-
document.head.appendChild(link);
|
|
1011
|
-
}
|
|
1012
|
-
const waiters = link._$frWaiters;
|
|
1013
|
-
if (waiters == null) return true;
|
|
1014
|
-
waiters.add(onSettle);
|
|
1015
|
-
return false;
|
|
1016
|
-
}
|
|
1017
|
-
function ensureModulePreload(href) {
|
|
1018
|
-
if (findHeadElement('link[rel="modulepreload"]', "href", href)) return;
|
|
1019
|
-
const link = document.createElement("link");
|
|
1020
|
-
link.rel = "modulepreload";
|
|
1021
|
-
link.href = href;
|
|
1022
|
-
document.head.appendChild(link);
|
|
1023
|
-
}
|
|
1024
|
-
function applyInlineStyles(inlineStyles) {
|
|
1025
|
-
for (const entry of inlineStyles) {
|
|
1026
|
-
if (findHeadElement("style[data-asset]", "data-asset", entry.id)) continue;
|
|
1027
|
-
const el = document.createElement("style");
|
|
1028
|
-
el.setAttribute("data-asset", entry.id);
|
|
1029
|
-
if (entry.attrs) {
|
|
1030
|
-
for (const name in entry.attrs) el.setAttribute(name, entry.attrs[name]);
|
|
1031
|
-
}
|
|
1032
|
-
el.textContent = entry.content || "";
|
|
1033
|
-
document.head.appendChild(el);
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
856
|
function isPlaceholderStart(node, id) {
|
|
1037
857
|
return node.tagName === "TEMPLATE" && node.id === id;
|
|
1038
858
|
}
|
|
@@ -1078,48 +898,20 @@ function collectSlots(n, end, out, elements) {
|
|
|
1078
898
|
n = afterRange(n, id);
|
|
1079
899
|
continue;
|
|
1080
900
|
}
|
|
901
|
+
if (elements !== undefined && isTextStart(n)) {
|
|
902
|
+
const B = tierLoads.bind?.r;
|
|
903
|
+
B ? B.text(n, elements) : elements.b = true;
|
|
904
|
+
}
|
|
1081
905
|
if (n.nodeType === ELEMENT_NODE && !isFrameElement(n)) {
|
|
1082
906
|
if (elements !== undefined && n.hasAttributes()) {
|
|
1083
|
-
const
|
|
1084
|
-
|
|
1085
|
-
for (const occurrence in byOccurrence) {
|
|
1086
|
-
let consumers = elements.get(occurrence);
|
|
1087
|
-
if (consumers === undefined) elements.set(occurrence, consumers = []);else if (!Array.isArray(consumers)) continue;
|
|
1088
|
-
consumers.push({
|
|
1089
|
-
element: n,
|
|
1090
|
-
positions: byOccurrence[occurrence]
|
|
1091
|
-
});
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
907
|
+
const B = tierLoads.bind?.r;
|
|
908
|
+
B ? B.positions(n, elements) : hasSlotMarker(n) && (elements.b = true);
|
|
1094
909
|
}
|
|
1095
910
|
collectSlots(n.firstChild, null, out, elements);
|
|
1096
911
|
}
|
|
1097
912
|
n = n.nextSibling;
|
|
1098
913
|
}
|
|
1099
914
|
}
|
|
1100
|
-
function collectRegionElements(node, regions) {
|
|
1101
|
-
if (node.nodeType !== ELEMENT_NODE) return;
|
|
1102
|
-
if (isFrameElement(node)) {
|
|
1103
|
-
const childId = node.getAttribute(FRAME_ID_ATTR);
|
|
1104
|
-
if (childId && childId.includes(".")) {
|
|
1105
|
-
const argKey = childId.slice(childId.lastIndexOf(".") + 1);
|
|
1106
|
-
if (!regions.has(argKey)) {
|
|
1107
|
-
regions.set(argKey, {
|
|
1108
|
-
childId,
|
|
1109
|
-
element: node,
|
|
1110
|
-
frame: undefined,
|
|
1111
|
-
adopt: true
|
|
1112
|
-
});
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
return;
|
|
1116
|
-
}
|
|
1117
|
-
for (let c = node.firstChild; c; c = c.nextSibling) collectRegionElements(c, regions);
|
|
1118
|
-
}
|
|
1119
|
-
function renameRegion(entry, childId) {
|
|
1120
|
-
entry.childId = childId;
|
|
1121
|
-
if (entry.frame) entry.frame.rebind(childId);else entry.element.setAttribute(FRAME_ID_ATTR, childId);
|
|
1122
|
-
}
|
|
1123
915
|
function eachInRange(start, key, cb) {
|
|
1124
916
|
const end = slotEnd(key);
|
|
1125
917
|
let n = start.nextSibling;
|
|
@@ -1130,28 +922,6 @@ function eachInRange(start, key, cb) {
|
|
|
1130
922
|
}
|
|
1131
923
|
return n;
|
|
1132
924
|
}
|
|
1133
|
-
function clearStreamRecords(records, root) {
|
|
1134
|
-
for (const key in records) {
|
|
1135
|
-
if (/^(seg|hole|attr):/.test(key) || key === ":error" || root && key === "") {
|
|
1136
|
-
delete records[key];
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
function argsEquivalent(a, b) {
|
|
1141
|
-
if (a === b) return true;
|
|
1142
|
-
if (!a || !b) return false;
|
|
1143
|
-
const ka = Object.keys(a);
|
|
1144
|
-
const kb = Object.keys(b);
|
|
1145
|
-
if (ka.length !== kb.length) return false;
|
|
1146
|
-
for (const key of ka) {
|
|
1147
|
-
const va = a[key];
|
|
1148
|
-
const vb = b[key];
|
|
1149
|
-
if (va === vb) continue;
|
|
1150
|
-
if (isFrameRef(va) && va.$frame === vb?.$frame) continue;
|
|
1151
|
-
return false;
|
|
1152
|
-
}
|
|
1153
|
-
return true;
|
|
1154
|
-
}
|
|
1155
925
|
function slotStartId(node) {
|
|
1156
926
|
if (node.nodeType !== COMMENT_NODE) return null;
|
|
1157
927
|
const m = SLOT_START.exec(node.data);
|
|
@@ -1171,62 +941,11 @@ function preservesOpen(el) {
|
|
|
1171
941
|
const t = el.tagName;
|
|
1172
942
|
return t === "DETAILS" || t === "DIALOG";
|
|
1173
943
|
}
|
|
1174
|
-
|
|
1175
|
-
const
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
if (!name.startsWith(SLOT_MARKER)) continue;
|
|
1180
|
-
const pos = name.slice(SLOT_MARKER.length);
|
|
1181
|
-
if (pos === "ref" || pos.startsWith("on:")) continue;
|
|
1182
|
-
out || (out = {
|
|
1183
|
-
attrs: new Set(),
|
|
1184
|
-
class: null,
|
|
1185
|
-
style: null
|
|
1186
|
-
});
|
|
1187
|
-
if (pos !== "class" && pos !== "style") {
|
|
1188
|
-
out.attrs.add(pos);
|
|
1189
|
-
continue;
|
|
1190
|
-
}
|
|
1191
|
-
for (const entry of attrs[i].value.split(",")) {
|
|
1192
|
-
const eq = entry.indexOf("=");
|
|
1193
|
-
if (eq === -1) {
|
|
1194
|
-
out.attrs.add(pos);
|
|
1195
|
-
continue;
|
|
1196
|
-
}
|
|
1197
|
-
(out[pos] || (out[pos] = [])).push(decodeURIComponent(entry.slice(eq + 1)));
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
return out;
|
|
1201
|
-
}
|
|
1202
|
-
function morphOwnedClass(oldEl, value, names) {
|
|
1203
|
-
const list = oldEl.classList;
|
|
1204
|
-
const set = new Set(value ? value.split(/\s+/) : []);
|
|
1205
|
-
set.delete("");
|
|
1206
|
-
for (const name of names) list.contains(name) ? set.add(name) : set.delete(name);
|
|
1207
|
-
const next = [...set].join(" ");
|
|
1208
|
-
if (next === (oldEl.getAttribute("class") || "")) return false;
|
|
1209
|
-
next ? oldEl.setAttribute("class", next) : oldEl.removeAttribute("class");
|
|
1210
|
-
return true;
|
|
1211
|
-
}
|
|
1212
|
-
function morphOwnedStyle(oldEl, value, names) {
|
|
1213
|
-
const style = oldEl.style;
|
|
1214
|
-
const saved = names.map(name => [name, style.getPropertyValue(name), style.getPropertyPriority(name)]);
|
|
1215
|
-
const before = oldEl.getAttribute("style");
|
|
1216
|
-
value ? oldEl.setAttribute("style", value) : oldEl.removeAttribute("style");
|
|
1217
|
-
for (const [name, v, priority] of saved) {
|
|
1218
|
-
v ? style.setProperty(name, v, priority) : style.removeProperty(name);
|
|
1219
|
-
}
|
|
1220
|
-
return oldEl.getAttribute("style") !== before;
|
|
1221
|
-
}
|
|
1222
|
-
function applyOwned(oldEl, name, value, owned) {
|
|
1223
|
-
if (owned === null) return undefined;
|
|
1224
|
-
if (owned.attrs.has(name)) return false;
|
|
1225
|
-
if ((name === "class" || name === "style") && owned[name] !== null) {
|
|
1226
|
-
return name === "class" ? morphOwnedClass(oldEl, value, owned.class) : morphOwnedStyle(oldEl, value, owned.style);
|
|
1227
|
-
}
|
|
1228
|
-
return undefined;
|
|
1229
|
-
}
|
|
944
|
+
const ownedPositions = el => {
|
|
945
|
+
const B = tierLoads.bind?.r;
|
|
946
|
+
return B ? B.owned(el) : null;
|
|
947
|
+
};
|
|
948
|
+
const applyOwned = (oldEl, name, value, owned) => owned === null ? undefined : tierLoads.bind.r.apply(oldEl, name, value, owned);
|
|
1230
949
|
function morphAttributes(oldEl, newEl, claim) {
|
|
1231
950
|
let reclaim = false;
|
|
1232
951
|
let changed = false;
|
|
@@ -1274,8 +993,9 @@ function morphNode(oldNode, newNode, claim, ranges, grafts) {
|
|
|
1274
993
|
oldNode.data = newNode.data;
|
|
1275
994
|
}
|
|
1276
995
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
996
|
+
const afterRange = (start, id) => afterMarker(start, slotEnd(id));
|
|
997
|
+
const afterText = start => afterMarker(start, SLOT_TEXT_END);
|
|
998
|
+
function afterMarker(start, end) {
|
|
1279
999
|
let n = start.nextSibling;
|
|
1280
1000
|
while (n) {
|
|
1281
1001
|
if (n.nodeType === COMMENT_NODE && n.data === end) return n.nextSibling;
|
|
@@ -1294,10 +1014,10 @@ function devSlotOrphan(frame, occurrence, consumers, why) {
|
|
|
1294
1014
|
for (const c of consumers) for (const p of c.positions) positions.add(p.pos);
|
|
1295
1015
|
const where = `${consumers.length} element${consumers.length === 1 ? "" : "s"} (positions: ${[...positions].join(", ")})`;
|
|
1296
1016
|
DEV.report(OBSERVE.diagnostics.emit({
|
|
1297
|
-
code: "
|
|
1017
|
+
code: "BINDING_SLOT_POSITION",
|
|
1298
1018
|
kind: "render",
|
|
1299
1019
|
severity: "warn",
|
|
1300
|
-
message: why === "fill" ? `[
|
|
1020
|
+
message: why === "fill" ? `[BINDING_SLOT_POSITION] Server markup binds \`${occurrence}\` at ${where}, but no client fill ` + `resolves for slot \`${prop}\` — those positions never bind and the elements are inert. ` + `Pass \`${prop}\` to the server component on the client (a function returning the object the ` + `markup reads), or check that the prop name matches on both sides.` : `[BINDING_SLOT_POSITION] Server markup binds \`${occurrence}\` at ${where}, but no args record ` + `for it arrived and none can — the fill mounts with empty args. A called slot always emits its ` + `record ahead of the markup that reads it, so this is the frame protocol out of step, not the fill: ` + `a client and server from different builds (a stale dev prebundle, a cached asset), or a runtime ` + `bug minting the marker and the record under different ids.`,
|
|
1301
1021
|
data: {
|
|
1302
1022
|
reason: "orphan",
|
|
1303
1023
|
why,
|
|
@@ -1375,6 +1095,11 @@ function reconcileChildren(parent, source, boundStart = null, boundEnd = null, c
|
|
|
1375
1095
|
const nextNew = newChild.nextSibling;
|
|
1376
1096
|
const pid = slotStartId(newChild);
|
|
1377
1097
|
const old = oldChild === boundEnd ? null : oldChild;
|
|
1098
|
+
if (old && isTextStart(newChild) && old.nodeType === COMMENT_NODE && old.data === newChild.data) {
|
|
1099
|
+
oldChild = afterText(old);
|
|
1100
|
+
newChild = afterText(newChild);
|
|
1101
|
+
continue;
|
|
1102
|
+
}
|
|
1378
1103
|
if (pid !== null) {
|
|
1379
1104
|
if (old && slotStartId(old) === pid) {
|
|
1380
1105
|
oldChild = afterRange(old, pid);
|
|
@@ -1551,18 +1276,7 @@ function observeFrameApply(response) {
|
|
|
1551
1276
|
}
|
|
1552
1277
|
|
|
1553
1278
|
const FRAME_STREAM_HEADER = "X-Frame-Stream";
|
|
1554
|
-
const
|
|
1555
|
-
const FRAME_HAVE_BUDGET = 4096;
|
|
1556
|
-
function encodeHaveList(have) {
|
|
1557
|
-
let out = "";
|
|
1558
|
-
for (const key in have) {
|
|
1559
|
-
const digest = have[key];
|
|
1560
|
-
if (typeof digest !== "string") continue;
|
|
1561
|
-
out += (out ? "," : "") + key + "=" + digest;
|
|
1562
|
-
if (out.length > FRAME_HAVE_BUDGET) return undefined;
|
|
1563
|
-
}
|
|
1564
|
-
return out || undefined;
|
|
1565
|
-
}
|
|
1279
|
+
const FRAME_TIERS_HEADER = "X-Frame-Tiers";
|
|
1566
1280
|
function isFrameStreamResponse(response) {
|
|
1567
1281
|
return response.headers.has(FRAME_STREAM_HEADER);
|
|
1568
1282
|
}
|
|
@@ -1582,26 +1296,12 @@ async function observedApplyFrameResponse(response, host, options = {}) {
|
|
|
1582
1296
|
}
|
|
1583
1297
|
function applyFrames(response, host, options = {}, observation) {
|
|
1584
1298
|
const rootId = response.headers.get(FRAME_STREAM_HEADER) ?? "";
|
|
1299
|
+
response.headers.get(FRAME_TIERS_HEADER)?.split(",").forEach(prepareTier);
|
|
1585
1300
|
const as = options.as;
|
|
1586
1301
|
const version = options.version;
|
|
1587
1302
|
const perFrame = typeof version === "function" ? new Map() : null;
|
|
1588
|
-
const
|
|
1589
|
-
const connection = wire && wire.connection;
|
|
1590
|
-
const reader = wire && isEventStream(response) ? wire.open(response.body) : new ChunkReader(response.body);
|
|
1303
|
+
const reader = options[LIVE_WIRE] || new ChunkReader(response.body);
|
|
1591
1304
|
const open = new Map();
|
|
1592
|
-
let cancelled;
|
|
1593
|
-
let resolveEnd;
|
|
1594
|
-
if (connection) {
|
|
1595
|
-
connection.ended = new Promise(resolve => resolveEnd = resolve);
|
|
1596
|
-
connection.cancel = reason => {
|
|
1597
|
-
if (cancelled !== undefined) return;
|
|
1598
|
-
cancelled = reason;
|
|
1599
|
-
try {
|
|
1600
|
-
const r = reader.cancel && reader.cancel(reason);
|
|
1601
|
-
if (r && typeof r.then === "function") r.then(undefined, () => {});
|
|
1602
|
-
} catch {}
|
|
1603
|
-
};
|
|
1604
|
-
}
|
|
1605
1305
|
const errorRecord = (id, error) => ({
|
|
1606
1306
|
type: "error",
|
|
1607
1307
|
id,
|
|
@@ -1626,26 +1326,15 @@ function applyFrames(response, host, options = {}, observation) {
|
|
|
1626
1326
|
} else if (version !== undefined) chunk.version = version;
|
|
1627
1327
|
if (chunk.type === "start") open.set(chunk.id, chunk.version);else if (chunk.type === "complete" || chunk.type === "error" && !chunk.key) open.delete(chunk.id);
|
|
1628
1328
|
if (observation) observation.chunk(chunk, wireId);
|
|
1629
|
-
|
|
1329
|
+
const needs = chunk.tiers?.map(prepareTier) || [];
|
|
1330
|
+
if (chunk.type === "data" || chunk.type === "slot" && Object.values(chunk.args).some(v => v && v.$ref)) await Promise.all([host.prepareData?.(), ...needs]);
|
|
1630
1331
|
host.apply(chunk);
|
|
1631
1332
|
}
|
|
1632
1333
|
result = await reader.next();
|
|
1633
1334
|
}
|
|
1634
1335
|
};
|
|
1635
1336
|
const end = error => {
|
|
1636
|
-
|
|
1637
|
-
const sweep = () => {
|
|
1638
|
-
for (const id of open.keys()) host.apply(errorRecord(id, dead));
|
|
1639
|
-
};
|
|
1640
|
-
if (connection) {
|
|
1641
|
-
connection.done = true;
|
|
1642
|
-
resolveEnd({
|
|
1643
|
-
open: open.size,
|
|
1644
|
-
error: dead,
|
|
1645
|
-
sweep,
|
|
1646
|
-
close: () => {}
|
|
1647
|
-
});
|
|
1648
|
-
} else if (error === undefined) sweep();
|
|
1337
|
+
if (error === undefined) for (const id of open.keys()) host.apply(errorRecord(id, new Error("Frame stream ended before the frame completed.")));
|
|
1649
1338
|
};
|
|
1650
1339
|
return drain().then(() => {
|
|
1651
1340
|
end(undefined);
|
|
@@ -1658,7 +1347,19 @@ function applyFrames(response, host, options = {}, observation) {
|
|
|
1658
1347
|
const SERVER_COMPONENT = /*#__PURE__*/Symbol.for("solid.server-component");
|
|
1659
1348
|
const SERVER_COMPONENT_ADDRESS = /*#__PURE__*/Symbol.for("solid.server-component-address");
|
|
1660
1349
|
const COMPONENT_BINDING = /*#__PURE__*/Symbol.for("solid.component-binding");
|
|
1350
|
+
const CONTENT_TOKEN = "\u0000";
|
|
1351
|
+
function contentAddress(token) {
|
|
1352
|
+
return token.split(CONTENT_TOKEN)[0];
|
|
1353
|
+
}
|
|
1354
|
+
const stagedContent = {
|
|
1355
|
+
preview() {},
|
|
1356
|
+
commit() {}
|
|
1357
|
+
};
|
|
1661
1358
|
let resolveServerComponent;
|
|
1359
|
+
const calls = new Map();
|
|
1360
|
+
function callFor(address) {
|
|
1361
|
+
return calls.get(address);
|
|
1362
|
+
}
|
|
1662
1363
|
function parseServerComponent(value, ctx) {
|
|
1663
1364
|
return {
|
|
1664
1365
|
id: ctx.parse(value[SERVER_COMPONENT]),
|
|
@@ -1704,7 +1405,6 @@ function flightCodec(codec) {
|
|
|
1704
1405
|
function createServerComponentHandler({
|
|
1705
1406
|
host,
|
|
1706
1407
|
component,
|
|
1707
|
-
onStream,
|
|
1708
1408
|
intercept
|
|
1709
1409
|
}) {
|
|
1710
1410
|
const byFn = new Map();
|
|
@@ -1727,46 +1427,78 @@ function createServerComponentHandler({
|
|
|
1727
1427
|
}
|
|
1728
1428
|
return binding;
|
|
1729
1429
|
};
|
|
1730
|
-
|
|
1430
|
+
const staged = new Map();
|
|
1431
|
+
const latest = new Map();
|
|
1432
|
+
const stage = (address, base, version) => {
|
|
1433
|
+
if (!base) return undefined;
|
|
1434
|
+
let committed = false;
|
|
1435
|
+
const chunks = [];
|
|
1436
|
+
const token = address + CONTENT_TOKEN + version;
|
|
1437
|
+
const entry = {
|
|
1438
|
+
token,
|
|
1439
|
+
prepareData: host.prepareData,
|
|
1440
|
+
apply(chunk) {
|
|
1441
|
+
if (committed || chunk.type === "data") host.apply(chunk);else chunks.push(chunk);
|
|
1442
|
+
},
|
|
1443
|
+
preview() {
|
|
1444
|
+
if (host.preview) for (const chunk of chunks) host.preview(chunk);
|
|
1445
|
+
},
|
|
1446
|
+
commit() {
|
|
1447
|
+
committed = true;
|
|
1448
|
+
staged.delete(address);
|
|
1449
|
+
for (const chunk of chunks) host.apply(chunk);
|
|
1450
|
+
}
|
|
1451
|
+
};
|
|
1452
|
+
staged.set(address, entry);
|
|
1453
|
+
const comp = base[COMPONENT_BINDING].component;
|
|
1454
|
+
const binding = props => comp(props, () => token);
|
|
1455
|
+
binding[COMPONENT_BINDING] = {
|
|
1456
|
+
component: comp,
|
|
1457
|
+
address: token
|
|
1458
|
+
};
|
|
1459
|
+
latest.set(address, binding);
|
|
1460
|
+
return entry;
|
|
1461
|
+
};
|
|
1462
|
+
const settled = (address, binding) => latest.get(address) || binding;
|
|
1463
|
+
const showing = address => {
|
|
1464
|
+
const frame = host.get(address);
|
|
1465
|
+
return frame !== undefined && frame.error === undefined;
|
|
1466
|
+
};
|
|
1467
|
+
const named = (token, half) => {
|
|
1468
|
+
const entry = staged.get(contentAddress(token));
|
|
1469
|
+
if (entry && entry.token === token) entry[half]();
|
|
1470
|
+
};
|
|
1471
|
+
stagedContent.preview = token => named(token, "preview");
|
|
1472
|
+
stagedContent.commit = token => named(token, "commit");
|
|
1473
|
+
resolveServerComponent = (id, address) => settled(address, bindingFor(address, id));
|
|
1731
1474
|
const versions = new Map();
|
|
1732
|
-
const connections = new Map();
|
|
1733
1475
|
const bump = address => {
|
|
1734
1476
|
const version = (versions.get(address) || 0) + 1;
|
|
1735
1477
|
versions.set(address, version);
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
connections.delete(address);
|
|
1739
|
-
connection.cancel(new Error("Superseded by a newer response for the address."));
|
|
1740
|
-
}
|
|
1478
|
+
staged.delete(address);
|
|
1479
|
+
tierLoads.wire?.r?.cancel(host, address);
|
|
1741
1480
|
return version;
|
|
1742
1481
|
};
|
|
1743
|
-
const
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
};
|
|
1482
|
+
const begin = (address, version) => host.apply({
|
|
1483
|
+
type: "start",
|
|
1484
|
+
id: address,
|
|
1485
|
+
version
|
|
1486
|
+
});
|
|
1749
1487
|
return {
|
|
1750
1488
|
intercept: intercept && (info => {
|
|
1751
1489
|
const hit = intercept(info);
|
|
1752
1490
|
if (hit === undefined) return undefined;
|
|
1753
|
-
const
|
|
1491
|
+
const address = frameAddress(info.id, info.args);
|
|
1492
|
+
if (!info.meta?.live) calls.set(address, info);
|
|
1493
|
+
const binding = () => bindingFor(address, info.id);
|
|
1754
1494
|
if (typeof hit.then === "function") return hit.then(landed => landed ? binding() : undefined);
|
|
1755
1495
|
return binding();
|
|
1756
1496
|
}),
|
|
1497
|
+
onLive() {
|
|
1498
|
+
prepareTier("wire");
|
|
1499
|
+
},
|
|
1757
1500
|
resume(info) {
|
|
1758
|
-
|
|
1759
|
-
const version = versions.get(address);
|
|
1760
|
-
const frame = host.get(address);
|
|
1761
|
-
const have = frame && frame.have ? frame.have() : undefined;
|
|
1762
|
-
if (version === undefined && !have) return undefined;
|
|
1763
|
-
const encoded = have && encodeHaveList(have);
|
|
1764
|
-
return {
|
|
1765
|
-
position: String(version || 0),
|
|
1766
|
-
headers: encoded ? {
|
|
1767
|
-
[FRAME_HAVE_HEADER]: encoded
|
|
1768
|
-
} : undefined
|
|
1769
|
-
};
|
|
1501
|
+
return tierLoads.wire?.r?.resume(host, info, versions);
|
|
1770
1502
|
},
|
|
1771
1503
|
handle(response, ctx) {
|
|
1772
1504
|
if (!isFrameStreamResponse(response)) return undefined;
|
|
@@ -1776,31 +1508,16 @@ function createServerComponentHandler({
|
|
|
1776
1508
|
return applyFlightResponse(response, address, binding);
|
|
1777
1509
|
}
|
|
1778
1510
|
const wire = ctx[LIVE_WIRE];
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
const current = connections.get(address);
|
|
1782
|
-
if (current && !current.done) {
|
|
1783
|
-
connection.ended = current.ended;
|
|
1784
|
-
const body = response.body;
|
|
1785
|
-
if (body) body.cancel().catch(() => {});
|
|
1786
|
-
return binding;
|
|
1787
|
-
}
|
|
1788
|
-
const version = bump(address);
|
|
1789
|
-
if (onStream) onStream(address, version, response);
|
|
1790
|
-
applyFrameResponse(response, host, {
|
|
1791
|
-
as: address,
|
|
1792
|
-
version,
|
|
1793
|
-
[LIVE_WIRE]: wire
|
|
1794
|
-
}).catch(() => {});
|
|
1795
|
-
hold(address, connection);
|
|
1796
|
-
return binding;
|
|
1797
|
-
}
|
|
1511
|
+
if (wire) return prepareTier("wire").then(() => tierLoads.wire.r.connect(response, wire, address, binding, host, bump, begin));
|
|
1512
|
+
calls.set(address, ctx);
|
|
1798
1513
|
const version = bump(address);
|
|
1799
|
-
|
|
1800
|
-
|
|
1514
|
+
const entry = showing(address) ? stage(address, binding, version) : undefined;
|
|
1515
|
+
if (!entry) begin(address, version);
|
|
1516
|
+
const target = entry || host;
|
|
1517
|
+
const applied = applyFrameResponse(response, target, {
|
|
1801
1518
|
as: address,
|
|
1802
1519
|
version
|
|
1803
|
-
}).catch(err =>
|
|
1520
|
+
}).catch(err => target.apply({
|
|
1804
1521
|
type: "error",
|
|
1805
1522
|
id: address,
|
|
1806
1523
|
version,
|
|
@@ -1808,17 +1525,10 @@ function createServerComponentHandler({
|
|
|
1808
1525
|
message: String(err && err.message)
|
|
1809
1526
|
}
|
|
1810
1527
|
}));
|
|
1811
|
-
return
|
|
1528
|
+
return entry ? applied.then(() => settled(address, binding)) : binding;
|
|
1812
1529
|
},
|
|
1813
1530
|
showing(address, functionId) {
|
|
1814
1531
|
bindingFor(address, functionId);
|
|
1815
|
-
const comp = componentFor(functionId);
|
|
1816
|
-
if (comp && (typeof comp === "function" || typeof comp === "object") && !comp[COMPONENT_BINDING]) {
|
|
1817
|
-
comp[COMPONENT_BINDING] = {
|
|
1818
|
-
component: comp,
|
|
1819
|
-
address
|
|
1820
|
-
};
|
|
1821
|
-
}
|
|
1822
1532
|
}
|
|
1823
1533
|
};
|
|
1824
1534
|
async function applyFlightResponse(response, address, binding) {
|
|
@@ -1832,11 +1542,26 @@ function createServerComponentHandler({
|
|
|
1832
1542
|
});
|
|
1833
1543
|
const payload = deserializeStream(new Response(source), flightCodec(getServerFunctionsCodec()));
|
|
1834
1544
|
let carried = false;
|
|
1835
|
-
|
|
1545
|
+
const regions = new Map();
|
|
1546
|
+
const regionOf = id => {
|
|
1547
|
+
for (const [root, entry] of regions) if (id === root || id.startsWith(root + ".")) return entry;
|
|
1548
|
+
};
|
|
1549
|
+
const target = {
|
|
1550
|
+
apply: chunk => {
|
|
1551
|
+
const entry = regionOf(chunk.id);
|
|
1552
|
+
if (entry) entry.apply(chunk);else host.apply(chunk);
|
|
1553
|
+
},
|
|
1554
|
+
prepareData: host.prepareData
|
|
1555
|
+
};
|
|
1556
|
+
await applyFrameResponse(response, target, {
|
|
1836
1557
|
as,
|
|
1837
1558
|
version: frameId => {
|
|
1838
1559
|
const version = bump(frameId);
|
|
1839
|
-
|
|
1560
|
+
let entry = regionOf(frameId);
|
|
1561
|
+
if (!entry && showing(frameId)) {
|
|
1562
|
+
entry = stage(frameId, frameId === as ? binding : byAddress.get(frameId), version);
|
|
1563
|
+
if (entry) regions.set(frameId, entry);
|
|
1564
|
+
}
|
|
1840
1565
|
return version;
|
|
1841
1566
|
},
|
|
1842
1567
|
onOutcome: text => {
|
|
@@ -1851,47 +1576,16 @@ function createServerComponentHandler({
|
|
|
1851
1576
|
if (response.headers.has(ERROR_HEADER) && !hasFlightMetadata(response)) {
|
|
1852
1577
|
throw envelope.value;
|
|
1853
1578
|
}
|
|
1854
|
-
return rootId ? binding : envelope.value;
|
|
1855
|
-
}
|
|
1856
|
-
}
|
|
1857
|
-
|
|
1858
|
-
const STATE = Symbol.for("solid.container-trace-state");
|
|
1859
|
-
const state = globalThis[STATE] || (globalThis[STATE] = {
|
|
1860
|
-
materialized: new WeakMap(),
|
|
1861
|
-
materializedValues: new WeakSet()
|
|
1862
|
-
});
|
|
1863
|
-
function setContainerTraceMaterializer(fn) {
|
|
1864
|
-
state.materializeTrace = fn;
|
|
1865
|
-
}
|
|
1866
|
-
function materialize(marker) {
|
|
1867
|
-
let value = state.materialized.get(marker.$tr);
|
|
1868
|
-
if (value === undefined) {
|
|
1869
|
-
value = state.materializeTrace(marker);
|
|
1870
|
-
state.materialized.set(marker.$tr, value);
|
|
1871
|
-
if (value !== null && typeof value === "object") state.materializedValues.add(value);
|
|
1872
|
-
}
|
|
1873
|
-
return value;
|
|
1874
|
-
}
|
|
1875
|
-
function isMaterializedContainer(value) {
|
|
1876
|
-
return value !== null && typeof value === "object" && state.materializedValues.has(value);
|
|
1877
|
-
}
|
|
1878
|
-
function isContainerTraceMarker(value) {
|
|
1879
|
-
if (value == null || typeof value !== "object" || value.$tr == null) return false;
|
|
1880
|
-
const tr = value.$tr;
|
|
1881
|
-
return tr.__SEROVAL_STREAM__ === true || typeof tr[Symbol.asyncIterator] === "function";
|
|
1882
|
-
}
|
|
1883
|
-
function reviveContainerTraces(value) {
|
|
1884
|
-
if (!state.materializeTrace || value == null || typeof value !== "object") return value;
|
|
1885
|
-
if (isContainerTraceMarker(value)) return materialize(value);
|
|
1886
|
-
if (Array.isArray(value)) {
|
|
1887
|
-
for (let i = 0; i < value.length; i++) value[i] = reviveContainerTraces(value[i]);
|
|
1888
|
-
} else if (Object.getPrototypeOf(value) === Object.prototype) {
|
|
1889
|
-
for (const key of Object.keys(value)) value[key] = reviveContainerTraces(value[key]);
|
|
1579
|
+
return rootId ? settled(address, binding) : envelope.value;
|
|
1890
1580
|
}
|
|
1891
|
-
return value;
|
|
1892
1581
|
}
|
|
1893
1582
|
|
|
1894
|
-
|
|
1583
|
+
const TRACE_STATE = Symbol.for("solid.container-trace-state");
|
|
1584
|
+
tierLoaders.trace = () => import('@solidjs/web/frames/trace');
|
|
1585
|
+
tierLoaders.regions = () => import('@solidjs/web/frames/regions');
|
|
1586
|
+
tierLoaders.assets = () => import('@solidjs/web/frames/assets');
|
|
1587
|
+
tierLoaders.bind = () => import('@solidjs/web/frames/bind');
|
|
1588
|
+
tierLoaders.wire = () => import('@solidjs/web/frames/wire');
|
|
1895
1589
|
function asyncArg(value) {
|
|
1896
1590
|
return value;
|
|
1897
1591
|
}
|
|
@@ -1904,116 +1598,121 @@ function loadCodec() {
|
|
|
1904
1598
|
});
|
|
1905
1599
|
}
|
|
1906
1600
|
const tables = new Map();
|
|
1907
|
-
function
|
|
1908
|
-
let
|
|
1909
|
-
if (!
|
|
1910
|
-
|
|
1601
|
+
function tableFor(id, version, current) {
|
|
1602
|
+
let byVersion = tables.get(id);
|
|
1603
|
+
if (!byVersion) tables.set(id, byVersion = new Map());else for (const v of byVersion.keys()) if (v < current) byVersion.delete(v);
|
|
1604
|
+
let t = byVersion.get(version);
|
|
1605
|
+
if (!t && codec) byVersion.set(version, t = codec.createJSONDataTable());
|
|
1606
|
+
return t;
|
|
1607
|
+
}
|
|
1608
|
+
function followAddress(host, frame, binding) {
|
|
1609
|
+
createRenderEffect(() => {
|
|
1610
|
+
const token = binding();
|
|
1611
|
+
stagedContent.preview(token);
|
|
1612
|
+
return token;
|
|
1613
|
+
}, token => {
|
|
1614
|
+
stagedContent.commit(token);
|
|
1615
|
+
frame.rebind(contentAddress(token));
|
|
1616
|
+
});
|
|
1911
1617
|
}
|
|
1912
|
-
function
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1618
|
+
function landing(host, address, value, failed) {
|
|
1619
|
+
let thrown = host.get(address)?.error;
|
|
1620
|
+
return createMemo(() => {
|
|
1621
|
+
failed();
|
|
1622
|
+
const error = host.get(address)?.error;
|
|
1623
|
+
if (error !== undefined && error !== thrown) {
|
|
1624
|
+
thrown = error;
|
|
1625
|
+
throw error;
|
|
1626
|
+
}
|
|
1627
|
+
const wait = host.landing(address);
|
|
1628
|
+
if (!wait) return value;
|
|
1629
|
+
const asked = error !== undefined ? reask(address) : undefined;
|
|
1630
|
+
return (asked ? asked.then(() => wait) : wait).then(() => value);
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1633
|
+
function reask(address) {
|
|
1634
|
+
const call = callFor(address);
|
|
1635
|
+
if (!call) console.error(`Server component boundary "${address}" errored, but no call is recorded for it; ` + `reset() cannot re-ask the server. (The address was written by hand, not by a call.)`);
|
|
1636
|
+
return call && call.retry();
|
|
1916
1637
|
}
|
|
1917
|
-
function
|
|
1918
|
-
|
|
1638
|
+
function failing() {
|
|
1639
|
+
const [failed, setFailed] = createSignal(0, {
|
|
1640
|
+
ownedWrite: true
|
|
1641
|
+
});
|
|
1642
|
+
return [failed, info => info.reason === "error" && setFailed(n => n + 1)];
|
|
1919
1643
|
}
|
|
1920
1644
|
function getFrameHost() {
|
|
1921
1645
|
if (!sharedHost) {
|
|
1922
1646
|
sharedHost = createFrameHost({
|
|
1923
1647
|
prepareData: loadCodec,
|
|
1924
|
-
applyData: c => tableFor(c.id)?.apply(c),
|
|
1925
|
-
resolve: (ref, id) => tableFor(id)?.resolve(ref),
|
|
1926
|
-
|
|
1927
|
-
isContainer: isMaterializedContainer
|
|
1648
|
+
applyData: (c, current) => tableFor(c.id, c.version, current)?.apply(c),
|
|
1649
|
+
resolve: (ref, id, version, current) => tableFor(id, version, current)?.resolve(ref),
|
|
1650
|
+
closeData: (id, version, error) => tables.get(id)?.get(version)?.close(error)
|
|
1928
1651
|
});
|
|
1929
1652
|
}
|
|
1930
1653
|
return sharedHost;
|
|
1931
1654
|
}
|
|
1932
|
-
function
|
|
1933
|
-
while (typeof value === "function") value = value();
|
|
1934
|
-
if (Array.isArray(value)) {
|
|
1935
|
-
const out = [];
|
|
1936
|
-
for (const v of value) {
|
|
1937
|
-
const n = normalizeSlotContent(v);
|
|
1938
|
-
Array.isArray(n) ? out.push(...n) : out.push(n);
|
|
1939
|
-
}
|
|
1940
|
-
return out;
|
|
1941
|
-
}
|
|
1942
|
-
if (value == null || typeof value === "boolean") return document.createTextNode("");
|
|
1943
|
-
return value instanceof Node ? value : document.createTextNode(String(value));
|
|
1944
|
-
}
|
|
1945
|
-
function gatherClaims(el, registry) {
|
|
1946
|
-
if (el.hasAttribute("_hk")) registry.set(el.getAttribute("_hk"), el);
|
|
1947
|
-
if (el.hasAttribute(FRAME_ID_ATTR)) return;
|
|
1948
|
-
for (let c = el.firstElementChild; c; c = c.nextElementSibling) gatherClaims(c, registry);
|
|
1949
|
-
}
|
|
1950
|
-
function hasPendingFragment(existing) {
|
|
1951
|
-
for (const n of existing) {
|
|
1952
|
-
if (n.nodeType !== 1) continue;
|
|
1953
|
-
const el = n;
|
|
1954
|
-
if (el.tagName === "TEMPLATE" && el.id.startsWith("pl-")) return true;
|
|
1955
|
-
if (el.querySelector?.('template[id^="pl-"]')) return true;
|
|
1956
|
-
}
|
|
1957
|
-
return false;
|
|
1958
|
-
}
|
|
1959
|
-
function claimRender(prefix, existing, render) {
|
|
1655
|
+
function claimRender(prefix, existing, render, scope, bound) {
|
|
1960
1656
|
const sc = sharedConfig;
|
|
1961
|
-
if (!sc.
|
|
1962
|
-
const
|
|
1963
|
-
for (const n of existing) {
|
|
1964
|
-
if (n.nodeType !== 1) continue;
|
|
1965
|
-
gatherClaims(n, registry);
|
|
1966
|
-
}
|
|
1967
|
-
if (!registry.size && !hasPendingFragment(existing)) return render();
|
|
1968
|
-
const prevRegistry = sc.registry;
|
|
1969
|
-
const prevHydrating = sc.hydrating;
|
|
1970
|
-
const prevClaimRoots = sc.claimRoots;
|
|
1971
|
-
if (prevRegistry) for (const key of registry.keys()) prevRegistry.delete(key);
|
|
1972
|
-
sc.registry = registry;
|
|
1973
|
-
sc.hydrating = true;
|
|
1657
|
+
if (!sc.hydrateWindow || !sc.registry) return render();
|
|
1658
|
+
const prevRoots = sc.claimRoots;
|
|
1974
1659
|
sc.claimRoots = existing;
|
|
1975
1660
|
try {
|
|
1976
1661
|
return runWithOwner(createOwner({
|
|
1977
1662
|
id: prefix
|
|
1978
|
-
}), render);
|
|
1663
|
+
}), () => sc.hydrateWindow(bound ? undefined : prefix, render, scope));
|
|
1979
1664
|
} finally {
|
|
1980
|
-
sc.
|
|
1981
|
-
sc.hydrating = prevHydrating;
|
|
1982
|
-
sc.claimRoots = prevClaimRoots;
|
|
1665
|
+
sc.claimRoots = prevRoots;
|
|
1983
1666
|
}
|
|
1984
1667
|
}
|
|
1985
1668
|
function liveSlotProps(initial, ctx) {
|
|
1986
|
-
const [args, setArgs] = createSignal(initial
|
|
1669
|
+
const [args, setArgs] = createSignal(initial, {
|
|
1670
|
+
ownedWrite: true
|
|
1671
|
+
});
|
|
1987
1672
|
ctx.onUpdate(next => setArgs(() => next));
|
|
1988
1673
|
return slotArgsProxy(args);
|
|
1989
1674
|
}
|
|
1990
|
-
function
|
|
1991
|
-
|
|
1675
|
+
function sameArg(a, b) {
|
|
1676
|
+
if (a === b) return true;
|
|
1677
|
+
if (!a || !b || typeof a !== "object" || typeof b !== "object") return false;
|
|
1678
|
+
if (a instanceof Boxed || b instanceof Boxed) return a instanceof Boxed && b instanceof Boxed && a.c === b.c;
|
|
1679
|
+
if (isAsyncValue(a) || isAsyncValue(b) || a instanceof Node || b instanceof Node) return false;
|
|
1680
|
+
try {
|
|
1681
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
1682
|
+
} catch {
|
|
1683
|
+
return false;
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
class Boxed {
|
|
1687
|
+
constructor(c) {
|
|
1688
|
+
this.c = c;
|
|
1689
|
+
}
|
|
1992
1690
|
}
|
|
1993
1691
|
function slotArgsProxy(args) {
|
|
1994
1692
|
const owner = getOwner();
|
|
1995
|
-
const
|
|
1693
|
+
const reads = new Map();
|
|
1996
1694
|
return new Proxy({}, {
|
|
1997
1695
|
get: (_, key) => {
|
|
1998
|
-
|
|
1999
|
-
if (isMaterializedContainer(v)) return v;
|
|
2000
|
-
if (!isAsyncValue(v)) return v;
|
|
2001
|
-
let read = asyncReads.get(key);
|
|
1696
|
+
let read = reads.get(key);
|
|
2002
1697
|
if (!read) {
|
|
2003
1698
|
const make = () => createMemo(() => {
|
|
2004
1699
|
const raw = args()[key];
|
|
1700
|
+
if (globalThis[TRACE_STATE]?.materializedValues.has(raw)) return new Boxed(raw);
|
|
2005
1701
|
if (raw != null && typeof raw.then === "function") {
|
|
2006
1702
|
if (raw.s === 1) return raw.v;
|
|
2007
1703
|
if (raw.s === 2) throw raw.v;
|
|
2008
1704
|
}
|
|
2009
1705
|
return raw;
|
|
2010
1706
|
}, {
|
|
2011
|
-
transparent: true
|
|
2012
|
-
|
|
1707
|
+
transparent: true,
|
|
1708
|
+
equals: sameArg,
|
|
1709
|
+
_supersedes: true
|
|
1710
|
+
} );
|
|
2013
1711
|
read = owner ? runWithOwner(owner, make) : make();
|
|
2014
|
-
|
|
1712
|
+
reads.set(key, read);
|
|
2015
1713
|
}
|
|
2016
|
-
|
|
1714
|
+
const v = read();
|
|
1715
|
+
return v instanceof Boxed ? v.c : v;
|
|
2017
1716
|
},
|
|
2018
1717
|
has: (_, key) => key in args(),
|
|
2019
1718
|
ownKeys: () => Reflect.ownKeys(args()),
|
|
@@ -2023,159 +1722,13 @@ function slotArgsProxy(args) {
|
|
|
2023
1722
|
} : undefined
|
|
2024
1723
|
});
|
|
2025
1724
|
}
|
|
2026
|
-
function
|
|
2027
|
-
const [consumers, setConsumers] = createSignal(ctx.positions);
|
|
2028
|
-
ctx.onRebind(setConsumers);
|
|
2029
|
-
const output = createMemo(() => {
|
|
2030
|
-
const out = fill(args);
|
|
2031
|
-
const node = typeof Node === "function" && out instanceof Node;
|
|
2032
|
-
if ((out == null || typeof out !== "object" || Array.isArray(out) || node)) {
|
|
2033
|
-
const shape = out === null ? "null" : node ? "a DOM node" : Array.isArray(out) ? "an array" : typeof out;
|
|
2034
|
-
slotShapeFinding(ctx.key, shape, `[ATTRIBUTE_SLOT_POSITION] The fill for \`${ctx.key}\` returned ${shape}; server markup reads ` + `its properties at bound positions, so it must return an object (\`{ done, toggle, … }\`). ` + `Nothing binds until it does.`);
|
|
2035
|
-
}
|
|
2036
|
-
return out == null || typeof out !== "object" || node ? {} : out;
|
|
2037
|
-
});
|
|
2038
|
-
const state = new WeakMap();
|
|
2039
|
-
let bound = new Set();
|
|
2040
|
-
createRenderEffect(() => {
|
|
2041
|
-
const out = output();
|
|
2042
|
-
return consumers().map(({
|
|
2043
|
-
element,
|
|
2044
|
-
positions
|
|
2045
|
-
}) => ({
|
|
2046
|
-
element,
|
|
2047
|
-
...propsFor(element, positions, out)
|
|
2048
|
-
}));
|
|
2049
|
-
}, writes => {
|
|
2050
|
-
const next = new Set();
|
|
2051
|
-
for (const {
|
|
2052
|
-
element,
|
|
2053
|
-
props,
|
|
2054
|
-
handlers
|
|
2055
|
-
} of writes) {
|
|
2056
|
-
next.add(element);
|
|
2057
|
-
write(element, props, handlers);
|
|
2058
|
-
}
|
|
2059
|
-
for (const element of bound) if (!next.has(element)) write(element, {}, {});
|
|
2060
|
-
bound = next;
|
|
2061
|
-
});
|
|
2062
|
-
onCleanup(() => {
|
|
2063
|
-
for (const element of bound) write(element, {}, {});
|
|
2064
|
-
});
|
|
2065
|
-
function write(element, props, handlers) {
|
|
2066
|
-
const st = state.get(element);
|
|
2067
|
-
for (const k in st.prev) if (!(k in props) && k !== "ref") delete st.prev[k];
|
|
2068
|
-
assign(element, props, true, st.prev);
|
|
2069
|
-
st.keys = handlers;
|
|
2070
|
-
for (const name of st.on) {
|
|
2071
|
-
if (!(name in handlers)) {
|
|
2072
|
-
element.removeEventListener(name, st.listener);
|
|
2073
|
-
st.on.delete(name);
|
|
2074
|
-
}
|
|
2075
|
-
}
|
|
2076
|
-
for (const name in handlers) {
|
|
2077
|
-
if (!st.on.has(name)) {
|
|
2078
|
-
element.addEventListener(name, st.listener);
|
|
2079
|
-
st.on.add(name);
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
}
|
|
2083
|
-
function propsFor(element, positions, out) {
|
|
2084
|
-
let st = state.get(element);
|
|
2085
|
-
if (!st) {
|
|
2086
|
-
const s = {
|
|
2087
|
-
prev: {},
|
|
2088
|
-
ref: undefined,
|
|
2089
|
-
refId: "",
|
|
2090
|
-
on: new Set(),
|
|
2091
|
-
keys: {},
|
|
2092
|
-
listener(e) {
|
|
2093
|
-
const o = output();
|
|
2094
|
-
const keys = s.keys[e.type];
|
|
2095
|
-
if (keys === undefined) return;
|
|
2096
|
-
for (const k of keys) {
|
|
2097
|
-
const h = o[k];
|
|
2098
|
-
if (Array.isArray(h)) h[0].call(this, h[1], e);else if (typeof h === "function") h.call(this, e);
|
|
2099
|
-
}
|
|
2100
|
-
}
|
|
2101
|
-
};
|
|
2102
|
-
state.set(element, st = s);
|
|
2103
|
-
}
|
|
2104
|
-
const props = {};
|
|
2105
|
-
const handlers = {};
|
|
2106
|
-
let classNames = null;
|
|
2107
|
-
let styleProps = null;
|
|
2108
|
-
let refKeys = null;
|
|
2109
|
-
for (const {
|
|
2110
|
-
pos,
|
|
2111
|
-
key,
|
|
2112
|
-
name
|
|
2113
|
-
} of positions) {
|
|
2114
|
-
if (pos === "class" || pos === "style") {
|
|
2115
|
-
if (name === undefined) props[pos] = out[key];else if (pos === "class") (classNames || (classNames = {}))[name] = !!out[key];else (styleProps || (styleProps = {}))[name] = out[key];
|
|
2116
|
-
} else if (pos === "ref") {
|
|
2117
|
-
(refKeys || (refKeys = [])).push(key);
|
|
2118
|
-
} else if (pos.startsWith("on:")) {
|
|
2119
|
-
const event = pos.slice(3);
|
|
2120
|
-
(handlers[event] || (handlers[event] = [])).push(key);
|
|
2121
|
-
} else props[pos] = out[key];
|
|
2122
|
-
}
|
|
2123
|
-
if (classNames !== null && !("class" in props)) props.class = classNames;
|
|
2124
|
-
if (styleProps !== null && !("style" in props)) props.style = styleProps;
|
|
2125
|
-
if (refKeys !== null) {
|
|
2126
|
-
const id = refKeys.join(",");
|
|
2127
|
-
if (st.refId !== id) {
|
|
2128
|
-
const keys = refKeys;
|
|
2129
|
-
st.refId = id;
|
|
2130
|
-
st.ref = el => {
|
|
2131
|
-
const o = output();
|
|
2132
|
-
for (const k of keys) {
|
|
2133
|
-
const r = o[k];
|
|
2134
|
-
typeof r === "function" && r(el);
|
|
2135
|
-
}
|
|
2136
|
-
};
|
|
2137
|
-
}
|
|
2138
|
-
props.ref = st.ref;
|
|
2139
|
-
}
|
|
2140
|
-
return {
|
|
2141
|
-
props,
|
|
2142
|
-
handlers
|
|
2143
|
-
};
|
|
2144
|
-
}
|
|
2145
|
-
}
|
|
2146
|
-
function slotShapeFinding(occurrence, shape, message) {
|
|
2147
|
-
DEV.report(OBSERVE.diagnostics.emit({
|
|
2148
|
-
code: "ATTRIBUTE_SLOT_POSITION",
|
|
2149
|
-
kind: "render",
|
|
2150
|
-
severity: "warn",
|
|
2151
|
-
message,
|
|
2152
|
-
data: {
|
|
2153
|
-
reason: "fill-shape",
|
|
2154
|
-
occurrence,
|
|
2155
|
-
shape
|
|
2156
|
-
}
|
|
2157
|
-
}, null));
|
|
2158
|
-
}
|
|
2159
|
-
function isReactiveContent(value) {
|
|
2160
|
-
if (typeof value === "function") return true;
|
|
2161
|
-
if (Array.isArray(value)) {
|
|
2162
|
-
for (const v of value) if (isReactiveContent(v)) return true;
|
|
2163
|
-
}
|
|
2164
|
-
return false;
|
|
2165
|
-
}
|
|
2166
|
-
function slotsFor(props) {
|
|
2167
|
-
const bindings = new Map();
|
|
1725
|
+
function slotsFor(props, scope) {
|
|
2168
1726
|
const fillScopes = new Map();
|
|
2169
1727
|
return new Proxy({}, {
|
|
2170
1728
|
get(_, prop) {
|
|
2171
1729
|
if (typeof prop !== "string" || !(prop in props)) return undefined;
|
|
2172
1730
|
return (slotProps, ctx) => {
|
|
2173
1731
|
const key = ctx && ctx.key;
|
|
2174
|
-
const prev = key !== undefined && bindings.get(key);
|
|
2175
|
-
if (prev) {
|
|
2176
|
-
bindings.delete(key);
|
|
2177
|
-
prev.dispose();
|
|
2178
|
-
}
|
|
2179
1732
|
const prevFill = key !== undefined && fillScopes.get(key);
|
|
2180
1733
|
if (prevFill) {
|
|
2181
1734
|
fillScopes.delete(key);
|
|
@@ -2185,7 +1738,11 @@ function slotsFor(props) {
|
|
|
2185
1738
|
const fill = props[prop];
|
|
2186
1739
|
if (typeof fill !== "function") {
|
|
2187
1740
|
{
|
|
2188
|
-
slotShapeFinding(
|
|
1741
|
+
slotShapeFinding({
|
|
1742
|
+
reason: "fill-shape",
|
|
1743
|
+
occurrence: key,
|
|
1744
|
+
shape: typeof fill
|
|
1745
|
+
}, `[BINDING_SLOT_POSITION] Server markup reads slot \`${prop}\` as data (\`${key}\`), ` + `but the client prop is ${typeof fill === "object" ? "an object" : `a ${typeof fill}`}, ` + `not a function. The fill is a function of the occurrence's args returning the object ` + `the markup reads: \`${prop}={args => ({ … })}\`. Nothing binds until it is.`);
|
|
2189
1746
|
}
|
|
2190
1747
|
return undefined;
|
|
2191
1748
|
}
|
|
@@ -2197,10 +1754,12 @@ function slotsFor(props) {
|
|
|
2197
1754
|
});
|
|
2198
1755
|
runWithOwner(owner, () => {
|
|
2199
1756
|
const args = ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotArgsProxy(() => slotProps);
|
|
2200
|
-
|
|
1757
|
+
tierLoads.bind.r.bind(fill, args, ctx, `the \`${prop}\` binding-slot fill` );
|
|
2201
1758
|
});
|
|
2202
1759
|
return undefined;
|
|
2203
1760
|
}
|
|
1761
|
+
const range = ctx && ctx.range;
|
|
1762
|
+
if (!range) return undefined;
|
|
2204
1763
|
const fillOwner = streamInvoke ? createOwner() : null;
|
|
2205
1764
|
if (fillOwner && key !== undefined && ctx) {
|
|
2206
1765
|
fillScopes.set(key, fillOwner);
|
|
@@ -2209,42 +1768,31 @@ function slotsFor(props) {
|
|
|
2209
1768
|
fillOwner.dispose();
|
|
2210
1769
|
});
|
|
2211
1770
|
}
|
|
2212
|
-
const settle = out => {
|
|
2213
|
-
const existing = ctx && ctx.existing || [];
|
|
2214
|
-
if (existing.length) {
|
|
2215
|
-
const list = Array.isArray(out) ? out : [out];
|
|
2216
|
-
const inPlace = list.every(n => existing.some(e => e === n || e.nodeType === 1 && e.contains(n)));
|
|
2217
|
-
if (inPlace) return undefined;
|
|
2218
|
-
}
|
|
2219
|
-
return out;
|
|
2220
|
-
};
|
|
2221
1771
|
const evaluate = () => {
|
|
2222
1772
|
const v = props[prop];
|
|
2223
1773
|
if (typeof v === "function" && ctx && ctx.invoked) {
|
|
2224
|
-
|
|
1774
|
+
const fillProps = ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotArgsProxy(() => slotProps);
|
|
1775
|
+
return untrack(() => v(fillProps), `the \`${prop}\` template-slot fill` );
|
|
2225
1776
|
}
|
|
2226
1777
|
return v;
|
|
2227
1778
|
};
|
|
2228
1779
|
const adopted = !!(ctx && ctx.frame && ctx.adopted && ctx.existing && ctx.existing.length);
|
|
2229
1780
|
const prefix = ctx && ctx.frame ? `sc-${ctx.frame}-${ctx.key}-` : "";
|
|
2230
|
-
const value = fillOwner ? runWithOwner(fillOwner, () => adopted ? claimRender(prefix, ctx.existing, evaluate) : evaluate()) : adopted ? claimRender(prefix, ctx.existing, evaluate) : evaluate();
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
}
|
|
2234
|
-
if (
|
|
2235
|
-
|
|
2236
|
-
const owner = createOwner();
|
|
2237
|
-
bindings.set(key, owner);
|
|
1781
|
+
const value = fillOwner ? runWithOwner(fillOwner, () => adopted ? claimRender(prefix, ctx.existing, evaluate, scope) : evaluate()) : adopted ? claimRender(prefix, ctx.existing, evaluate, scope) : evaluate();
|
|
1782
|
+
const owner = fillOwner || createOwner({
|
|
1783
|
+
transparent: true
|
|
1784
|
+
});
|
|
1785
|
+
if (!fillOwner) {
|
|
1786
|
+
fillScopes.set(key, owner);
|
|
2238
1787
|
ctx.onCleanup(() => {
|
|
2239
|
-
if (
|
|
1788
|
+
if (fillScopes.get(key) === owner) fillScopes.delete(key);
|
|
2240
1789
|
owner.dispose();
|
|
2241
1790
|
});
|
|
2242
|
-
const end = ctx.range.end;
|
|
2243
|
-
const bind = () => insert(end.parentNode, () => typeof source === "function" ? source() : source, end, [...ctx.existing]);
|
|
2244
|
-
runWithOwner(owner, () => adopted ? claimRender(prefix, ctx.existing, bind) : bind());
|
|
2245
|
-
return undefined;
|
|
2246
1791
|
}
|
|
2247
|
-
|
|
1792
|
+
const end = range.end;
|
|
1793
|
+
const bind = () => insert(end.parentNode, value, end, [...ctx.existing]);
|
|
1794
|
+
runWithOwner(owner, () => adopted ? claimRender(prefix, ctx.existing, bind, scope, true) : bind());
|
|
1795
|
+
return undefined;
|
|
2248
1796
|
};
|
|
2249
1797
|
}
|
|
2250
1798
|
});
|
|
@@ -2267,12 +1815,8 @@ function boundaryScope(owner) {
|
|
|
2267
1815
|
function boundaryComponent(host, fnId) {
|
|
2268
1816
|
return (props, binding) => {
|
|
2269
1817
|
const owner = getOwner();
|
|
2270
|
-
const id = binding ? binding() : fnId;
|
|
2271
|
-
|
|
2272
|
-
let release;
|
|
2273
|
-
const arm = () => new Promise(r => release = r);
|
|
2274
|
-
const mountGate = applied ? undefined : arm();
|
|
2275
|
-
let setGate;
|
|
1818
|
+
const id = binding ? contentAddress(binding()) : fnId;
|
|
1819
|
+
const [failed, onApply] = failing();
|
|
2276
1820
|
const {
|
|
2277
1821
|
element,
|
|
2278
1822
|
frame,
|
|
@@ -2283,30 +1827,12 @@ function boundaryComponent(host, fnId) {
|
|
|
2283
1827
|
slots: slotsFor(props),
|
|
2284
1828
|
ownerScope: boundaryScope(owner),
|
|
2285
1829
|
reveal: revealSeam(owner),
|
|
2286
|
-
onApply
|
|
2287
|
-
applied = true;
|
|
2288
|
-
if (release) {
|
|
2289
|
-
release();
|
|
2290
|
-
release = undefined;
|
|
2291
|
-
}
|
|
2292
|
-
setGate && setGate(undefined);
|
|
2293
|
-
}
|
|
1830
|
+
onApply
|
|
2294
1831
|
});
|
|
2295
|
-
const [gatePromise, setGatePromise] = createSignal(applied ? undefined : mountGate);
|
|
2296
|
-
setGate = setGatePromise;
|
|
2297
|
-
if (binding) {
|
|
2298
|
-
createRenderEffect(binding, (address, prev) => {
|
|
2299
|
-
if (prev !== undefined && address !== prev && tables.has(address)) {
|
|
2300
|
-
applied = false;
|
|
2301
|
-
setGatePromise(arm());
|
|
2302
|
-
}
|
|
2303
|
-
frame.rebind(address);
|
|
2304
|
-
});
|
|
2305
|
-
}
|
|
2306
1832
|
onCleanup(dispose);
|
|
2307
|
-
if (
|
|
2308
|
-
|
|
2309
|
-
return createMemo(() => (
|
|
1833
|
+
if (!binding) return landing(host, id, element, failed);
|
|
1834
|
+
followAddress(host, frame, binding);
|
|
1835
|
+
return createMemo(() => landing(host, contentAddress(binding()), element, failed));
|
|
2310
1836
|
};
|
|
2311
1837
|
}
|
|
2312
1838
|
const claimedBoundaries = new Set();
|
|
@@ -2321,7 +1847,7 @@ function pumpLiveChannel() {
|
|
|
2321
1847
|
const pump = () => reader.read().then(r => {
|
|
2322
1848
|
if (r.done) return;
|
|
2323
1849
|
const op = r.value;
|
|
2324
|
-
liveOps.set(`${
|
|
1850
|
+
for (const m of op.type === "ops" ? op.ops : [op]) liveOps.set(`${m.type}:${m.fid || ""}:${m.key || ""}`, m);
|
|
2325
1851
|
for (const apply of liveAppliers) apply(op);
|
|
2326
1852
|
return pump();
|
|
2327
1853
|
});
|
|
@@ -2331,7 +1857,7 @@ function pumpLiveChannel() {
|
|
|
2331
1857
|
let boundaryIndex = null;
|
|
2332
1858
|
const isBoundaryId = id => !id.includes(".");
|
|
2333
1859
|
function indexBoundaries(root) {
|
|
2334
|
-
root.querySelectorAll(
|
|
1860
|
+
root.querySelectorAll(FRAME_SELECTOR).forEach(el => {
|
|
2335
1861
|
const key = el.getAttribute(FRAME_ID_ATTR);
|
|
2336
1862
|
if (key && isBoundaryId(key) && !boundaryIndex.has(key)) boundaryIndex.set(key, el);
|
|
2337
1863
|
});
|
|
@@ -2343,8 +1869,9 @@ function findBoundaryElement(id) {
|
|
|
2343
1869
|
}
|
|
2344
1870
|
return boundaryIndex.get(id);
|
|
2345
1871
|
}
|
|
2346
|
-
const boundaryWaiters = new Map();
|
|
2347
1872
|
const arrivals = new Map();
|
|
1873
|
+
const FRAME_SELECTOR = `[${FRAME_ID_ATTR}]`;
|
|
1874
|
+
const disposedFrames = new WeakSet();
|
|
2348
1875
|
function awaitBoundary(id) {
|
|
2349
1876
|
let arrival = arrivals.get(id);
|
|
2350
1877
|
if (!arrival) {
|
|
@@ -2366,18 +1893,16 @@ function installRevealHook() {
|
|
|
2366
1893
|
const hy = globalThis._$HY;
|
|
2367
1894
|
if (!hy || hy.$sc || !hy.fr) return;
|
|
2368
1895
|
hy.$sc = true;
|
|
1896
|
+
hy.fa = pl => {
|
|
1897
|
+
const el = pl.closest(FRAME_SELECTOR);
|
|
1898
|
+
return !!el && !disposedFrames.has(el);
|
|
1899
|
+
};
|
|
2369
1900
|
hy.fr.subscribe((_id, parent) => {
|
|
2370
1901
|
if (!boundaryIndex) return;
|
|
2371
1902
|
const root = parent || (typeof document !== "undefined" ? document.body : null);
|
|
2372
1903
|
if (root) indexBoundaries(root);
|
|
2373
|
-
if (!
|
|
1904
|
+
if (!arrivals.size) return;
|
|
2374
1905
|
const exhausted = hy.done && !hy.fr.pending();
|
|
2375
|
-
for (const [id, notify] of boundaryWaiters) {
|
|
2376
|
-
const el = boundaryIndex && boundaryIndex.get(id);
|
|
2377
|
-
if (!el && !exhausted) continue;
|
|
2378
|
-
boundaryWaiters.delete(id);
|
|
2379
|
-
notify(el);
|
|
2380
|
-
}
|
|
2381
1906
|
for (const [id, arrival] of arrivals) {
|
|
2382
1907
|
const el = boundaryIndex && boundaryIndex.get(id);
|
|
2383
1908
|
if (!el && !exhausted) continue;
|
|
@@ -2391,35 +1916,31 @@ function documentBoundary(host, id, props, binding) {
|
|
|
2391
1916
|
const claimed = claimedBoundaries.has(id);
|
|
2392
1917
|
const el = !claimed ? findBoundaryElement(id) : undefined;
|
|
2393
1918
|
if (el) return adoptBoundary(host, id, el, props, binding);
|
|
2394
|
-
if (!claimed &&
|
|
1919
|
+
if (!claimed && boundaryMayArrive()) {
|
|
2395
1920
|
const owner = getOwner();
|
|
2396
|
-
|
|
2397
|
-
onCleanup(() =>
|
|
2398
|
-
return createMemo(() =>
|
|
2399
|
-
|
|
1921
|
+
let live = true;
|
|
1922
|
+
onCleanup(() => live = false);
|
|
1923
|
+
return createMemo(() => awaitBoundary(id).then(() => live && runWithOwner(owner, () => {
|
|
1924
|
+
const node = claimedBoundaries.has(id) ? undefined : findBoundaryElement(id);
|
|
1925
|
+
return node ? adoptBoundary(host, id, node, props, binding) : boundaryComponent(host, id)(props, binding);
|
|
1926
|
+
})));
|
|
2400
1927
|
}
|
|
2401
1928
|
return boundaryComponent(host, id)(props, binding);
|
|
2402
1929
|
}
|
|
2403
|
-
function documentAddress(id) {
|
|
2404
|
-
const records = globalThis._$SC?.a;
|
|
2405
|
-
if (records) {
|
|
2406
|
-
for (const address in records) if (records[address] === id) return address;
|
|
2407
|
-
}
|
|
2408
|
-
return id;
|
|
2409
|
-
}
|
|
2410
1930
|
function adoptBoundary(host, id, el, props, binding) {
|
|
2411
1931
|
claimedBoundaries.add(id);
|
|
2412
|
-
const address = binding ? binding() :
|
|
1932
|
+
const address = binding ? contentAddress(binding()) : id;
|
|
2413
1933
|
const appliedRecords = new Set();
|
|
2414
|
-
const
|
|
2415
|
-
const
|
|
2416
|
-
const
|
|
2417
|
-
if (!
|
|
1934
|
+
const reportedFragments = new Set();
|
|
1935
|
+
const reportRegionFragments = root => {
|
|
1936
|
+
const hy = globalThis._$HY;
|
|
1937
|
+
if (!hy || !hy.r) return;
|
|
2418
1938
|
root.querySelectorAll('template[id^="pl-"]').forEach(tpl => {
|
|
2419
1939
|
const fragId = tpl.id.slice(3);
|
|
2420
|
-
if (
|
|
2421
|
-
|
|
2422
|
-
|
|
1940
|
+
if (reportedFragments.has(fragId)) return;
|
|
1941
|
+
reportedFragments.add(fragId);
|
|
1942
|
+
const ref = hy.r[fragId + "_fr"];
|
|
1943
|
+
ref && typeof ref.then === "function" && ref.then(undefined, error => console.error(`Server <Loading> fragment "${fragId}" inside server component "${id}" rejected on ` + `the server; the frame shows what the server rendered for that outcome.`, error));
|
|
2423
1944
|
});
|
|
2424
1945
|
};
|
|
2425
1946
|
const drainRecords = () => {
|
|
@@ -2431,13 +1952,17 @@ function adoptBoundary(host, id, el, props, binding) {
|
|
|
2431
1952
|
if (appliedRecords.has(key)) continue;
|
|
2432
1953
|
if (key.startsWith(slotPrefix)) {
|
|
2433
1954
|
appliedRecords.add(key);
|
|
2434
|
-
host.apply({
|
|
1955
|
+
const apply = args => host.apply({
|
|
2435
1956
|
type: "slot",
|
|
2436
1957
|
id: address,
|
|
2437
1958
|
version: 0,
|
|
2438
1959
|
key: key.slice(slotPrefix.length),
|
|
2439
|
-
args
|
|
1960
|
+
args
|
|
2440
1961
|
});
|
|
1962
|
+
const value = hy.r[key];
|
|
1963
|
+
if (value && typeof value.then === "function") {
|
|
1964
|
+
if (value.s === 1) apply(value.v);else if (value.s === 2) value.then(undefined, () => {});else value.then(apply, () => {});
|
|
1965
|
+
} else apply(value);
|
|
2441
1966
|
} else if (key.startsWith("sc:region:")) {
|
|
2442
1967
|
const childId = key.slice("sc:region:".length);
|
|
2443
1968
|
if (childId.startsWith(id + ".")) {
|
|
@@ -2454,14 +1979,20 @@ function adoptBoundary(host, id, el, props, binding) {
|
|
|
2454
1979
|
}
|
|
2455
1980
|
}
|
|
2456
1981
|
};
|
|
2457
|
-
|
|
1982
|
+
reportRegionFragments(el);
|
|
2458
1983
|
const fr = globalThis._$HY?.fr;
|
|
1984
|
+
let frame;
|
|
2459
1985
|
const unsubscribe = fr ? fr.subscribe((_fragId, parent) => {
|
|
2460
|
-
|
|
1986
|
+
const inside = !!parent && el.contains(parent);
|
|
1987
|
+
inside && reportRegionFragments(parent);
|
|
2461
1988
|
drainRecords();
|
|
1989
|
+
if (inside && frame) frame.apply({
|
|
1990
|
+
version: frame.version ?? 0,
|
|
1991
|
+
r: {}
|
|
1992
|
+
});
|
|
2462
1993
|
}) : undefined;
|
|
2463
1994
|
const applyLiveOp = op => {
|
|
2464
|
-
if (op.
|
|
1995
|
+
if (op.fid && op.fid !== id) return;
|
|
2465
1996
|
host.apply({
|
|
2466
1997
|
...op,
|
|
2467
1998
|
id: address,
|
|
@@ -2472,55 +2003,44 @@ function adoptBoundary(host, id, el, props, binding) {
|
|
|
2472
2003
|
onCleanup(() => {
|
|
2473
2004
|
liveAppliers.delete(applyLiveOp);
|
|
2474
2005
|
unsubscribe && unsubscribe();
|
|
2475
|
-
if (fr && fr.release) for (const fragId of claimedFragments) fr.release(fragId);
|
|
2476
2006
|
});
|
|
2477
2007
|
drainRecords();
|
|
2478
2008
|
for (const op of liveOps.values()) applyLiveOp(op);
|
|
2479
2009
|
const owner = getOwner();
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2010
|
+
const sc = sharedConfig;
|
|
2011
|
+
const [failed, onApply] = failing();
|
|
2012
|
+
frame = createFrame(el, {
|
|
2483
2013
|
adopt: true,
|
|
2484
2014
|
host,
|
|
2485
2015
|
id: address,
|
|
2486
|
-
slots: slotsFor(props
|
|
2016
|
+
slots: slotsFor(props, {
|
|
2017
|
+
registry: sc.registry,
|
|
2018
|
+
gather: sc.gather
|
|
2019
|
+
}),
|
|
2487
2020
|
ownerScope: boundaryScope(owner),
|
|
2488
2021
|
reveal: revealSeam(owner),
|
|
2489
|
-
onApply
|
|
2490
|
-
|
|
2491
|
-
release();
|
|
2492
|
-
release = undefined;
|
|
2493
|
-
}
|
|
2494
|
-
setGate && setGate(undefined);
|
|
2495
|
-
},
|
|
2022
|
+
onApply,
|
|
2023
|
+
hold: () => sc.isHydrationInProgress?.() ? runWithOwner(owner, () => untrack(() => sc.holdBoundary("sc:" + id))) : () => {},
|
|
2496
2024
|
...{
|
|
2497
|
-
recordsPending: () => {
|
|
2498
|
-
if (document.readyState === "loading") return true;
|
|
2499
|
-
const hy = globalThis._$HY;
|
|
2500
|
-
return !!(hy && hy.fr && hy.fr.pending());
|
|
2501
|
-
},
|
|
2502
|
-
drainRecords,
|
|
2503
2025
|
claimScope: id
|
|
2504
2026
|
}
|
|
2505
2027
|
});
|
|
2506
2028
|
if (binding) {
|
|
2507
|
-
|
|
2508
|
-
const
|
|
2509
|
-
|
|
2510
|
-
const gate = createMemo(() => gatePromise());
|
|
2511
|
-
createRenderEffect(binding, (address, prev) => {
|
|
2512
|
-
if (prev !== undefined && address !== prev && tables.has(address)) {
|
|
2513
|
-
setGatePromise(arm());
|
|
2514
|
-
}
|
|
2515
|
-
frame.rebind(address);
|
|
2516
|
-
});
|
|
2517
|
-
createRenderEffect(() => (gate(), undefined), () => {});
|
|
2029
|
+
followAddress(host, frame, binding);
|
|
2030
|
+
const source = createMemo(() => landing(host, contentAddress(binding()), true, failed));
|
|
2031
|
+
createRenderEffect(() => source()(), () => {});
|
|
2518
2032
|
}
|
|
2519
|
-
onCleanup(() =>
|
|
2033
|
+
onCleanup(() => {
|
|
2034
|
+
frame.dispose();
|
|
2035
|
+
disposedFrames.add(el);
|
|
2036
|
+
el.querySelectorAll(FRAME_SELECTOR).forEach(e => disposedFrames.add(e));
|
|
2037
|
+
});
|
|
2520
2038
|
return el;
|
|
2521
2039
|
}
|
|
2522
|
-
function installServerComponents(host = getFrameHost()) {
|
|
2040
|
+
function installServerComponents(host = getFrameHost(), options) {
|
|
2523
2041
|
const g = globalThis;
|
|
2042
|
+
Object.assign(tierLoaders, options?.tiers);
|
|
2043
|
+
g._$HY?.r?.["sc:tiers"]?.forEach(prepareTier);
|
|
2524
2044
|
if (!g._$SC) {
|
|
2525
2045
|
g._$SC = {
|
|
2526
2046
|
c: {},
|
|
@@ -2545,7 +2065,6 @@ function installServerComponents(host = getFrameHost()) {
|
|
|
2545
2065
|
const handler = createServerComponentHandler({
|
|
2546
2066
|
host,
|
|
2547
2067
|
component: fnId => g._$SC.r(fnId),
|
|
2548
|
-
onStream: address => beginStream(address),
|
|
2549
2068
|
intercept: ({
|
|
2550
2069
|
id
|
|
2551
2070
|
}) => {
|
|
@@ -2565,4 +2084,4 @@ function installServerComponents(host = getFrameHost()) {
|
|
|
2565
2084
|
});
|
|
2566
2085
|
}
|
|
2567
2086
|
|
|
2568
|
-
export { FRAME_APPLIED_EVENT,
|
|
2087
|
+
export { FRAME_APPLIED_EVENT, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents, isAsyncValue, isFrameStreamResponse };
|