@solidjs/web 2.0.0-rc.13 → 2.0.0-rc.15
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 +317 -185
- package/dist/server.js +298 -161
- package/dist/server.observe.js +299 -171
- package/dist/web.dev.js +207 -189
- package/dist/web.js +180 -178
- package/dist/web.observe.js +180 -180
- 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 +665 -1114
- package/frames/dist/client.js +630 -1087
- package/frames/dist/client.observe.js +629 -1087
- package/frames/dist/regions.js +130 -0
- package/frames/dist/server.dev.js +400 -201
- package/frames/dist/server.js +397 -198
- package/frames/dist/server.observe.js +397 -198
- package/frames/dist/trace.js +45 -0
- package/frames/dist/wire.js +133 -0
- package/package.json +30 -4
- 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 +38 -9
- package/serialization/dist/serialization.js +40 -11
- package/serialization/types/serializer-decode.d.ts +24 -2
- package/server-functions/dist/client.dev.js +101 -62
- package/server-functions/dist/client.js +101 -62
- package/server-functions/dist/client.observe.js +101 -62
- package/server-functions/dist/server.dev.js +178 -67
- package/server-functions/dist/server.js +178 -67
- package/server-functions/dist/server.observe.js +178 -67
- package/skills/server-components/SKILL.md +65 -43
- package/types/client.d.ts +120 -8
- package/types/constants.d.ts +3 -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 +33 -9
- package/types/frames/trace-tier.d.ts +2 -0
- package/types/frames/wire-tier.d.ts +116 -0
- package/types/head.d.ts +1 -0
- package/types/index.d.ts +61 -16
- package/types/index.server.d.ts +3 -18
- package/types/jsx.d.ts +4 -13
- package/types/observe.d.ts +4 -2
- package/types/response.d.ts +26 -4
- package/types/serializer-decode.d.ts +24 -2
- package/types/server-functions/client.d.ts +30 -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 +22 -3
- package/types/server.d.ts +119 -17
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DEV, OBSERVE, getOwner, onCleanup, createMemo, runWithOwner,
|
|
2
|
-
import {
|
|
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 { installServerComponentHydration, insert } from '@solidjs/web';
|
|
3
|
+
import { frameAddress, SINGLE_FLIGHT_HEADER, LIVE_WIRE, deserializeStream, getServerFunctionsCodec, createChunk, deliverFlightData, ERROR_HEADER, hasFlightMetadata, ChunkReader, configureServerFunctionsClient } from '@solidjs/web/server-functions/client';
|
|
4
|
+
import { 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.`);
|
|
222
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
|
+
}
|
|
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
|
-
if (root) collectSlots(root
|
|
497
|
+
if (root) collectSlots(root, 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, 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
|
}
|
|
@@ -1069,56 +889,42 @@ function findPlaceholder(n, end, id) {
|
|
|
1069
889
|
}
|
|
1070
890
|
return null;
|
|
1071
891
|
}
|
|
1072
|
-
function collectSlots(
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
const byOccurrence = slotPositions(n);
|
|
1084
|
-
if (byOccurrence !== null) {
|
|
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
|
-
}
|
|
892
|
+
function collectSlots(root, out, elements) {
|
|
893
|
+
let announced;
|
|
894
|
+
const bind = elements && (tierLoads.bind || !(announced = globalThis._$HY?.r?.["sc:tiers"]) || announced.includes("bind"));
|
|
895
|
+
const B = bind && tierLoads.bind?.r;
|
|
896
|
+
const w = root.ownerDocument.createTreeWalker(root, bind ? 0x81 : 0x80);
|
|
897
|
+
let n, p;
|
|
898
|
+
while (n = w.nextNode()) {
|
|
899
|
+
if (n.nodeType !== COMMENT_NODE) {
|
|
900
|
+
if (!n.hasAttribute(FRAME_ID_ATTR)) {
|
|
901
|
+
if (n.hasAttributes()) B ? B.positions(n, elements) : hasSlotMarker(n) && (elements.b = true);
|
|
902
|
+
continue;
|
|
1094
903
|
}
|
|
1095
|
-
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
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
|
-
});
|
|
904
|
+
p = n;
|
|
905
|
+
} else if (n.data.startsWith("slot:")) {
|
|
906
|
+
const id = slotStartId(n);
|
|
907
|
+
if (!id) continue;
|
|
908
|
+
if (!bind) {
|
|
909
|
+
for (p = n.parentNode; p !== root; p = p.parentNode) if (p.hasAttribute(FRAME_ID_ATTR)) break;
|
|
910
|
+
if (p !== root) continue;
|
|
1113
911
|
}
|
|
912
|
+
if (!out.has(id)) out.set(id, n);
|
|
913
|
+
const end = findMarker(n, slotEnd(id));
|
|
914
|
+
if (end) {
|
|
915
|
+
w.currentNode = end;
|
|
916
|
+
continue;
|
|
917
|
+
}
|
|
918
|
+
devReportRange(id);
|
|
919
|
+
p = n.parentNode;
|
|
920
|
+
if (p === root) return;
|
|
921
|
+
} else {
|
|
922
|
+
if (bind && n.data.startsWith(SLOT_TEXT)) B ? B.text(n, elements) : elements.b = true;
|
|
923
|
+
continue;
|
|
1114
924
|
}
|
|
1115
|
-
|
|
925
|
+
while (p.lastChild) p = p.lastChild;
|
|
926
|
+
w.currentNode = p;
|
|
1116
927
|
}
|
|
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
928
|
}
|
|
1123
929
|
function eachInRange(start, key, cb) {
|
|
1124
930
|
const end = slotEnd(key);
|
|
@@ -1130,28 +936,6 @@ function eachInRange(start, key, cb) {
|
|
|
1130
936
|
}
|
|
1131
937
|
return n;
|
|
1132
938
|
}
|
|
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
939
|
function slotStartId(node) {
|
|
1156
940
|
if (node.nodeType !== COMMENT_NODE) return null;
|
|
1157
941
|
const m = SLOT_START.exec(node.data);
|
|
@@ -1171,62 +955,11 @@ function preservesOpen(el) {
|
|
|
1171
955
|
const t = el.tagName;
|
|
1172
956
|
return t === "DETAILS" || t === "DIALOG";
|
|
1173
957
|
}
|
|
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
|
-
}
|
|
958
|
+
const ownedPositions = el => {
|
|
959
|
+
const B = tierLoads.bind?.r;
|
|
960
|
+
return B ? B.owned(el) : null;
|
|
961
|
+
};
|
|
962
|
+
const applyOwned = (oldEl, name, value, owned) => owned === null ? undefined : tierLoads.bind.r.apply(oldEl, name, value, owned);
|
|
1230
963
|
function morphAttributes(oldEl, newEl, claim) {
|
|
1231
964
|
let reclaim = false;
|
|
1232
965
|
let changed = false;
|
|
@@ -1274,11 +1007,12 @@ function morphNode(oldNode, newNode, claim, ranges, grafts) {
|
|
|
1274
1007
|
oldNode.data = newNode.data;
|
|
1275
1008
|
}
|
|
1276
1009
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1010
|
+
const afterRange = (start, id) => findMarker(start, slotEnd(id))?.nextSibling;
|
|
1011
|
+
const afterText = start => findMarker(start, SLOT_TEXT_END)?.nextSibling;
|
|
1012
|
+
function findMarker(start, end) {
|
|
1279
1013
|
let n = start.nextSibling;
|
|
1280
1014
|
while (n) {
|
|
1281
|
-
if (n.nodeType === COMMENT_NODE && n.data === end) return n
|
|
1015
|
+
if (n.nodeType === COMMENT_NODE && n.data === end) return n;
|
|
1282
1016
|
n = n.nextSibling;
|
|
1283
1017
|
}
|
|
1284
1018
|
return null;
|
|
@@ -1294,10 +1028,10 @@ function devSlotOrphan(frame, occurrence, consumers, why) {
|
|
|
1294
1028
|
for (const c of consumers) for (const p of c.positions) positions.add(p.pos);
|
|
1295
1029
|
const where = `${consumers.length} element${consumers.length === 1 ? "" : "s"} (positions: ${[...positions].join(", ")})`;
|
|
1296
1030
|
DEV.report(OBSERVE.diagnostics.emit({
|
|
1297
|
-
code: "
|
|
1031
|
+
code: "BINDING_SLOT_POSITION",
|
|
1298
1032
|
kind: "render",
|
|
1299
1033
|
severity: "warn",
|
|
1300
|
-
message: why === "fill" ? `[
|
|
1034
|
+
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
1035
|
data: {
|
|
1302
1036
|
reason: "orphan",
|
|
1303
1037
|
why,
|
|
@@ -1306,13 +1040,8 @@ function devSlotOrphan(frame, occurrence, consumers, why) {
|
|
|
1306
1040
|
}
|
|
1307
1041
|
}, null));
|
|
1308
1042
|
}
|
|
1309
|
-
function
|
|
1043
|
+
function devReportRange(id) {
|
|
1310
1044
|
const end = slotEnd(id);
|
|
1311
|
-
let n = start.nextSibling;
|
|
1312
|
-
while (n) {
|
|
1313
|
-
if (n.nodeType === COMMENT_NODE && n.data === end) return;
|
|
1314
|
-
n = n.nextSibling;
|
|
1315
|
-
}
|
|
1316
1045
|
DEV.report(OBSERVE.diagnostics.emit({
|
|
1317
1046
|
code: "FRAME_MARKER_CORRUPTED",
|
|
1318
1047
|
kind: "ssr",
|
|
@@ -1375,6 +1104,11 @@ function reconcileChildren(parent, source, boundStart = null, boundEnd = null, c
|
|
|
1375
1104
|
const nextNew = newChild.nextSibling;
|
|
1376
1105
|
const pid = slotStartId(newChild);
|
|
1377
1106
|
const old = oldChild === boundEnd ? null : oldChild;
|
|
1107
|
+
if (old && isTextStart(newChild) && old.nodeType === COMMENT_NODE && old.data === newChild.data) {
|
|
1108
|
+
oldChild = afterText(old);
|
|
1109
|
+
newChild = afterText(newChild);
|
|
1110
|
+
continue;
|
|
1111
|
+
}
|
|
1378
1112
|
if (pid !== null) {
|
|
1379
1113
|
if (old && slotStartId(old) === pid) {
|
|
1380
1114
|
oldChild = afterRange(old, pid);
|
|
@@ -1551,18 +1285,7 @@ function observeFrameApply(response) {
|
|
|
1551
1285
|
}
|
|
1552
1286
|
|
|
1553
1287
|
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
|
-
}
|
|
1288
|
+
const FRAME_TIERS_HEADER = "X-Frame-Tiers";
|
|
1566
1289
|
function isFrameStreamResponse(response) {
|
|
1567
1290
|
return response.headers.has(FRAME_STREAM_HEADER);
|
|
1568
1291
|
}
|
|
@@ -1582,26 +1305,12 @@ async function observedApplyFrameResponse(response, host, options = {}) {
|
|
|
1582
1305
|
}
|
|
1583
1306
|
function applyFrames(response, host, options = {}, observation) {
|
|
1584
1307
|
const rootId = response.headers.get(FRAME_STREAM_HEADER) ?? "";
|
|
1308
|
+
response.headers.get(FRAME_TIERS_HEADER)?.split(",").forEach(prepareTier);
|
|
1585
1309
|
const as = options.as;
|
|
1586
1310
|
const version = options.version;
|
|
1587
1311
|
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);
|
|
1312
|
+
const reader = options[LIVE_WIRE] || new ChunkReader(response.body);
|
|
1591
1313
|
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
1314
|
const errorRecord = (id, error) => ({
|
|
1606
1315
|
type: "error",
|
|
1607
1316
|
id,
|
|
@@ -1626,26 +1335,15 @@ function applyFrames(response, host, options = {}, observation) {
|
|
|
1626
1335
|
} else if (version !== undefined) chunk.version = version;
|
|
1627
1336
|
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
1337
|
if (observation) observation.chunk(chunk, wireId);
|
|
1629
|
-
|
|
1338
|
+
const needs = chunk.tiers?.map(prepareTier) || [];
|
|
1339
|
+
if (chunk.type === "data" || chunk.type === "slot" && Object.values(chunk.args).some(v => v && v.$ref)) await Promise.all([host.prepareData?.(), ...needs]);
|
|
1630
1340
|
host.apply(chunk);
|
|
1631
1341
|
}
|
|
1632
1342
|
result = await reader.next();
|
|
1633
1343
|
}
|
|
1634
1344
|
};
|
|
1635
1345
|
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();
|
|
1346
|
+
if (error === undefined) for (const id of open.keys()) host.apply(errorRecord(id, new Error("Frame stream ended before the frame completed.")));
|
|
1649
1347
|
};
|
|
1650
1348
|
return drain().then(() => {
|
|
1651
1349
|
end(undefined);
|
|
@@ -1658,7 +1356,19 @@ function applyFrames(response, host, options = {}, observation) {
|
|
|
1658
1356
|
const SERVER_COMPONENT = /*#__PURE__*/Symbol.for("solid.server-component");
|
|
1659
1357
|
const SERVER_COMPONENT_ADDRESS = /*#__PURE__*/Symbol.for("solid.server-component-address");
|
|
1660
1358
|
const COMPONENT_BINDING = /*#__PURE__*/Symbol.for("solid.component-binding");
|
|
1359
|
+
const CONTENT_TOKEN = "\u0000";
|
|
1360
|
+
function contentAddress(token) {
|
|
1361
|
+
return token.split(CONTENT_TOKEN)[0];
|
|
1362
|
+
}
|
|
1363
|
+
const stagedContent = {
|
|
1364
|
+
preview() {},
|
|
1365
|
+
commit() {}
|
|
1366
|
+
};
|
|
1661
1367
|
let resolveServerComponent;
|
|
1368
|
+
const calls = new Map();
|
|
1369
|
+
function callFor(address) {
|
|
1370
|
+
return calls.get(address);
|
|
1371
|
+
}
|
|
1662
1372
|
function parseServerComponent(value, ctx) {
|
|
1663
1373
|
return {
|
|
1664
1374
|
id: ctx.parse(value[SERVER_COMPONENT]),
|
|
@@ -1704,7 +1414,6 @@ function flightCodec(codec) {
|
|
|
1704
1414
|
function createServerComponentHandler({
|
|
1705
1415
|
host,
|
|
1706
1416
|
component,
|
|
1707
|
-
onStream,
|
|
1708
1417
|
intercept
|
|
1709
1418
|
}) {
|
|
1710
1419
|
const byFn = new Map();
|
|
@@ -1727,46 +1436,78 @@ function createServerComponentHandler({
|
|
|
1727
1436
|
}
|
|
1728
1437
|
return binding;
|
|
1729
1438
|
};
|
|
1730
|
-
|
|
1439
|
+
const staged = new Map();
|
|
1440
|
+
const latest = new Map();
|
|
1441
|
+
const stage = (address, base, version) => {
|
|
1442
|
+
if (!base) return undefined;
|
|
1443
|
+
let committed = false;
|
|
1444
|
+
const chunks = [];
|
|
1445
|
+
const token = address + CONTENT_TOKEN + version;
|
|
1446
|
+
const entry = {
|
|
1447
|
+
token,
|
|
1448
|
+
prepareData: host.prepareData,
|
|
1449
|
+
apply(chunk) {
|
|
1450
|
+
if (committed || chunk.type === "data") host.apply(chunk);else chunks.push(chunk);
|
|
1451
|
+
},
|
|
1452
|
+
preview() {
|
|
1453
|
+
if (host.preview) for (const chunk of chunks) host.preview(chunk);
|
|
1454
|
+
},
|
|
1455
|
+
commit() {
|
|
1456
|
+
committed = true;
|
|
1457
|
+
staged.delete(address);
|
|
1458
|
+
for (const chunk of chunks) host.apply(chunk);
|
|
1459
|
+
}
|
|
1460
|
+
};
|
|
1461
|
+
staged.set(address, entry);
|
|
1462
|
+
const comp = base[COMPONENT_BINDING].component;
|
|
1463
|
+
const binding = props => comp(props, () => token);
|
|
1464
|
+
binding[COMPONENT_BINDING] = {
|
|
1465
|
+
component: comp,
|
|
1466
|
+
address: token
|
|
1467
|
+
};
|
|
1468
|
+
latest.set(address, binding);
|
|
1469
|
+
return entry;
|
|
1470
|
+
};
|
|
1471
|
+
const settled = (address, binding) => latest.get(address) || binding;
|
|
1472
|
+
const showing = address => {
|
|
1473
|
+
const frame = host.get(address);
|
|
1474
|
+
return frame !== undefined && frame.error === undefined;
|
|
1475
|
+
};
|
|
1476
|
+
const named = (token, half) => {
|
|
1477
|
+
const entry = staged.get(contentAddress(token));
|
|
1478
|
+
if (entry && entry.token === token) entry[half]();
|
|
1479
|
+
};
|
|
1480
|
+
stagedContent.preview = token => named(token, "preview");
|
|
1481
|
+
stagedContent.commit = token => named(token, "commit");
|
|
1482
|
+
resolveServerComponent = (id, address) => settled(address, bindingFor(address, id));
|
|
1731
1483
|
const versions = new Map();
|
|
1732
|
-
const connections = new Map();
|
|
1733
1484
|
const bump = address => {
|
|
1734
1485
|
const version = (versions.get(address) || 0) + 1;
|
|
1735
1486
|
versions.set(address, version);
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
connections.delete(address);
|
|
1739
|
-
connection.cancel(new Error("Superseded by a newer response for the address."));
|
|
1740
|
-
}
|
|
1487
|
+
staged.delete(address);
|
|
1488
|
+
tierLoads.wire?.r?.cancel(host, address);
|
|
1741
1489
|
return version;
|
|
1742
1490
|
};
|
|
1743
|
-
const
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
};
|
|
1491
|
+
const begin = (address, version) => host.apply({
|
|
1492
|
+
type: "start",
|
|
1493
|
+
id: address,
|
|
1494
|
+
version
|
|
1495
|
+
});
|
|
1749
1496
|
return {
|
|
1750
1497
|
intercept: intercept && (info => {
|
|
1751
1498
|
const hit = intercept(info);
|
|
1752
1499
|
if (hit === undefined) return undefined;
|
|
1753
|
-
const
|
|
1500
|
+
const address = frameAddress(info.id, info.args);
|
|
1501
|
+
if (!info.meta?.live) calls.set(address, info);
|
|
1502
|
+
const binding = () => bindingFor(address, info.id);
|
|
1754
1503
|
if (typeof hit.then === "function") return hit.then(landed => landed ? binding() : undefined);
|
|
1755
1504
|
return binding();
|
|
1756
1505
|
}),
|
|
1506
|
+
onLive() {
|
|
1507
|
+
prepareTier("wire");
|
|
1508
|
+
},
|
|
1757
1509
|
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
|
-
};
|
|
1510
|
+
return tierLoads.wire?.r?.resume(host, info, versions);
|
|
1770
1511
|
},
|
|
1771
1512
|
handle(response, ctx) {
|
|
1772
1513
|
if (!isFrameStreamResponse(response)) return undefined;
|
|
@@ -1776,31 +1517,16 @@ function createServerComponentHandler({
|
|
|
1776
1517
|
return applyFlightResponse(response, address, binding);
|
|
1777
1518
|
}
|
|
1778
1519
|
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
|
-
}
|
|
1520
|
+
if (wire) return prepareTier("wire").then(() => tierLoads.wire.r.connect(response, wire, address, binding, host, bump, begin));
|
|
1521
|
+
calls.set(address, ctx);
|
|
1798
1522
|
const version = bump(address);
|
|
1799
|
-
|
|
1800
|
-
|
|
1523
|
+
const entry = showing(address) ? stage(address, binding, version) : undefined;
|
|
1524
|
+
if (!entry) begin(address, version);
|
|
1525
|
+
const target = entry || host;
|
|
1526
|
+
const applied = applyFrameResponse(response, target, {
|
|
1801
1527
|
as: address,
|
|
1802
|
-
version
|
|
1803
|
-
}).catch(err =>
|
|
1528
|
+
version: frameId => frameId === address ? version : bump(frameId)
|
|
1529
|
+
}).catch(err => target.apply({
|
|
1804
1530
|
type: "error",
|
|
1805
1531
|
id: address,
|
|
1806
1532
|
version,
|
|
@@ -1808,17 +1534,10 @@ function createServerComponentHandler({
|
|
|
1808
1534
|
message: String(err && err.message)
|
|
1809
1535
|
}
|
|
1810
1536
|
}));
|
|
1811
|
-
return
|
|
1537
|
+
return entry ? applied.then(() => settled(address, binding)) : binding;
|
|
1812
1538
|
},
|
|
1813
1539
|
showing(address, functionId) {
|
|
1814
1540
|
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
1541
|
}
|
|
1823
1542
|
};
|
|
1824
1543
|
async function applyFlightResponse(response, address, binding) {
|
|
@@ -1832,11 +1551,26 @@ function createServerComponentHandler({
|
|
|
1832
1551
|
});
|
|
1833
1552
|
const payload = deserializeStream(new Response(source), flightCodec(getServerFunctionsCodec()));
|
|
1834
1553
|
let carried = false;
|
|
1835
|
-
|
|
1554
|
+
const regions = new Map();
|
|
1555
|
+
const regionOf = id => {
|
|
1556
|
+
for (const [root, entry] of regions) if (id === root || id.startsWith(root + ".")) return entry;
|
|
1557
|
+
};
|
|
1558
|
+
const target = {
|
|
1559
|
+
apply: chunk => {
|
|
1560
|
+
const entry = regionOf(chunk.id);
|
|
1561
|
+
if (entry) entry.apply(chunk);else host.apply(chunk);
|
|
1562
|
+
},
|
|
1563
|
+
prepareData: host.prepareData
|
|
1564
|
+
};
|
|
1565
|
+
await applyFrameResponse(response, target, {
|
|
1836
1566
|
as,
|
|
1837
1567
|
version: frameId => {
|
|
1838
1568
|
const version = bump(frameId);
|
|
1839
|
-
|
|
1569
|
+
let entry = regionOf(frameId);
|
|
1570
|
+
if (!entry && showing(frameId)) {
|
|
1571
|
+
entry = stage(frameId, frameId === as ? binding : byAddress.get(frameId), version);
|
|
1572
|
+
if (entry) regions.set(frameId, entry);
|
|
1573
|
+
}
|
|
1840
1574
|
return version;
|
|
1841
1575
|
},
|
|
1842
1576
|
onOutcome: text => {
|
|
@@ -1851,47 +1585,16 @@ function createServerComponentHandler({
|
|
|
1851
1585
|
if (response.headers.has(ERROR_HEADER) && !hasFlightMetadata(response)) {
|
|
1852
1586
|
throw envelope.value;
|
|
1853
1587
|
}
|
|
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);
|
|
1588
|
+
return rootId ? settled(address, binding) : envelope.value;
|
|
1872
1589
|
}
|
|
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]);
|
|
1890
|
-
}
|
|
1891
|
-
return value;
|
|
1892
1590
|
}
|
|
1893
1591
|
|
|
1894
|
-
|
|
1592
|
+
const TRACE_STATE = Symbol.for("solid.container-trace-state");
|
|
1593
|
+
tierLoaders.trace = () => import('@solidjs/web/frames/trace');
|
|
1594
|
+
tierLoaders.regions = () => import('@solidjs/web/frames/regions');
|
|
1595
|
+
tierLoaders.assets = () => import('@solidjs/web/frames/assets');
|
|
1596
|
+
tierLoaders.bind = () => import('@solidjs/web/frames/bind');
|
|
1597
|
+
tierLoaders.wire = () => import('@solidjs/web/frames/wire');
|
|
1895
1598
|
function asyncArg(value) {
|
|
1896
1599
|
return value;
|
|
1897
1600
|
}
|
|
@@ -1904,116 +1607,142 @@ function loadCodec() {
|
|
|
1904
1607
|
});
|
|
1905
1608
|
}
|
|
1906
1609
|
const tables = new Map();
|
|
1907
|
-
function
|
|
1908
|
-
let
|
|
1909
|
-
if (!
|
|
1910
|
-
|
|
1610
|
+
function tableFor(id, version, current) {
|
|
1611
|
+
let byVersion = tables.get(id);
|
|
1612
|
+
if (!byVersion) tables.set(id, byVersion = new Map());else for (const v of byVersion.keys()) if (v < current) byVersion.delete(v);
|
|
1613
|
+
let t = byVersion.get(version);
|
|
1614
|
+
if (!t && codec) byVersion.set(version, t = codec.createJSONDataTable());
|
|
1615
|
+
return t;
|
|
1616
|
+
}
|
|
1617
|
+
function followAddress(host, frame, binding) {
|
|
1618
|
+
createRenderEffect(() => {
|
|
1619
|
+
const token = binding();
|
|
1620
|
+
stagedContent.preview(token);
|
|
1621
|
+
return token;
|
|
1622
|
+
}, token => {
|
|
1623
|
+
stagedContent.commit(token);
|
|
1624
|
+
frame.rebind(contentAddress(token));
|
|
1625
|
+
});
|
|
1911
1626
|
}
|
|
1912
|
-
function
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1627
|
+
function landing(host, address, value, failed) {
|
|
1628
|
+
let frame, thrown;
|
|
1629
|
+
const errored = () => (frame = host.get(address))?.error !== undefined && (thrown === (thrown = frame.version) ? 1 : 2);
|
|
1630
|
+
errored();
|
|
1631
|
+
return createMemo(() => {
|
|
1632
|
+
failed();
|
|
1633
|
+
const state = errored();
|
|
1634
|
+
if (state > 1) throw frame.error;
|
|
1635
|
+
const wait = host.landing(address);
|
|
1636
|
+
if (!wait) return value;
|
|
1637
|
+
return (state ? reask(address, wait) : wait).then(() => value);
|
|
1638
|
+
});
|
|
1916
1639
|
}
|
|
1917
|
-
function
|
|
1918
|
-
|
|
1640
|
+
function reask(address, wait) {
|
|
1641
|
+
const call = callFor(address);
|
|
1642
|
+
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.)`);
|
|
1643
|
+
return call ? call.retry().then(() => wait) : wait;
|
|
1644
|
+
}
|
|
1645
|
+
function failing() {
|
|
1646
|
+
const [failed, setFailed] = createSignal(0, {
|
|
1647
|
+
ownedWrite: true
|
|
1648
|
+
});
|
|
1649
|
+
return [failed, info => info.reason === "error" && setFailed(n => n + 1)];
|
|
1919
1650
|
}
|
|
1920
1651
|
function getFrameHost() {
|
|
1921
1652
|
if (!sharedHost) {
|
|
1922
1653
|
sharedHost = createFrameHost({
|
|
1923
1654
|
prepareData: loadCodec,
|
|
1924
|
-
applyData: c => tableFor(c.id)?.apply(c),
|
|
1925
|
-
resolve: (ref, id) => tableFor(id)?.resolve(ref),
|
|
1926
|
-
|
|
1927
|
-
isContainer: isMaterializedContainer
|
|
1655
|
+
applyData: (c, current) => tableFor(c.id, c.version, current)?.apply(c),
|
|
1656
|
+
resolve: (ref, id, version, current) => tableFor(id, version, current)?.resolve(ref),
|
|
1657
|
+
closeData: (id, version, error) => tables.get(id)?.get(version)?.close(error)
|
|
1928
1658
|
});
|
|
1929
1659
|
}
|
|
1930
1660
|
return sharedHost;
|
|
1931
1661
|
}
|
|
1932
|
-
function
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1662
|
+
function claimScope(el) {
|
|
1663
|
+
const registry = sharedConfig.registry;
|
|
1664
|
+
const buckets = new Map();
|
|
1665
|
+
const bucketOf = key => key.slice(0, key.lastIndexOf("-") + 1);
|
|
1666
|
+
const index = root => {
|
|
1667
|
+
if (registry) for (const n of root.querySelectorAll("[_hk]")) {
|
|
1668
|
+
const p = bucketOf(n.getAttribute("_hk"));
|
|
1669
|
+
const b = buckets.get(p);
|
|
1670
|
+
b ? b.push(n) : buckets.set(p, [n]);
|
|
1939
1671
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
}
|
|
1950
|
-
|
|
1951
|
-
|
|
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;
|
|
1672
|
+
};
|
|
1673
|
+
index(el);
|
|
1674
|
+
return {
|
|
1675
|
+
registry,
|
|
1676
|
+
gather(id) {
|
|
1677
|
+
for (const n of buckets.get(bucketOf(id)) || []) {
|
|
1678
|
+
const k = n.getAttribute("_hk");
|
|
1679
|
+
if (k.startsWith(id) && n.isConnected && !registry.has(k)) registry.set(k, n);
|
|
1680
|
+
}
|
|
1681
|
+
},
|
|
1682
|
+
index
|
|
1683
|
+
};
|
|
1958
1684
|
}
|
|
1959
|
-
function claimRender(prefix, existing, render) {
|
|
1685
|
+
function claimRender(prefix, existing, render, scope, bound) {
|
|
1960
1686
|
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;
|
|
1687
|
+
if (!sc.hydrateWindow || !sc.registry) return render();
|
|
1688
|
+
const prevRoots = sc.claimRoots;
|
|
1974
1689
|
sc.claimRoots = existing;
|
|
1975
1690
|
try {
|
|
1976
1691
|
return runWithOwner(createOwner({
|
|
1977
1692
|
id: prefix
|
|
1978
|
-
}), render);
|
|
1693
|
+
}), () => sc.hydrateWindow(bound ? undefined : prefix, render, scope));
|
|
1979
1694
|
} finally {
|
|
1980
|
-
sc.
|
|
1981
|
-
sc.hydrating = prevHydrating;
|
|
1982
|
-
sc.claimRoots = prevClaimRoots;
|
|
1695
|
+
sc.claimRoots = prevRoots;
|
|
1983
1696
|
}
|
|
1984
1697
|
}
|
|
1985
1698
|
function liveSlotProps(initial, ctx) {
|
|
1986
|
-
const [args, setArgs] = createSignal(initial
|
|
1699
|
+
const [args, setArgs] = createSignal(initial, {
|
|
1700
|
+
ownedWrite: true
|
|
1701
|
+
});
|
|
1987
1702
|
ctx.onUpdate(next => setArgs(() => next));
|
|
1988
1703
|
return slotArgsProxy(args);
|
|
1989
1704
|
}
|
|
1990
|
-
function
|
|
1991
|
-
|
|
1705
|
+
function sameArg(a, b) {
|
|
1706
|
+
if (a === b) return true;
|
|
1707
|
+
if (!a || !b || typeof a !== "object" || typeof b !== "object") return false;
|
|
1708
|
+
if (a instanceof Boxed || b instanceof Boxed) return a instanceof Boxed && b instanceof Boxed && a.c === b.c;
|
|
1709
|
+
if (isAsyncValue(a) || isAsyncValue(b) || a instanceof Node || b instanceof Node) return false;
|
|
1710
|
+
try {
|
|
1711
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
1712
|
+
} catch {
|
|
1713
|
+
return false;
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
class Boxed {
|
|
1717
|
+
constructor(c) {
|
|
1718
|
+
this.c = c;
|
|
1719
|
+
}
|
|
1992
1720
|
}
|
|
1993
1721
|
function slotArgsProxy(args) {
|
|
1994
1722
|
const owner = getOwner();
|
|
1995
|
-
const
|
|
1723
|
+
const reads = new Map();
|
|
1996
1724
|
return new Proxy({}, {
|
|
1997
1725
|
get: (_, key) => {
|
|
1998
|
-
|
|
1999
|
-
if (isMaterializedContainer(v)) return v;
|
|
2000
|
-
if (!isAsyncValue(v)) return v;
|
|
2001
|
-
let read = asyncReads.get(key);
|
|
1726
|
+
let read = reads.get(key);
|
|
2002
1727
|
if (!read) {
|
|
2003
1728
|
const make = () => createMemo(() => {
|
|
2004
1729
|
const raw = args()[key];
|
|
1730
|
+
if (globalThis[TRACE_STATE]?.materializedValues.has(raw)) return new Boxed(raw);
|
|
2005
1731
|
if (raw != null && typeof raw.then === "function") {
|
|
2006
1732
|
if (raw.s === 1) return raw.v;
|
|
2007
1733
|
if (raw.s === 2) throw raw.v;
|
|
2008
1734
|
}
|
|
2009
1735
|
return raw;
|
|
2010
1736
|
}, {
|
|
2011
|
-
transparent: true
|
|
2012
|
-
|
|
1737
|
+
transparent: true,
|
|
1738
|
+
equals: sameArg,
|
|
1739
|
+
_supersedes: true
|
|
1740
|
+
} );
|
|
2013
1741
|
read = owner ? runWithOwner(owner, make) : make();
|
|
2014
|
-
|
|
1742
|
+
reads.set(key, read);
|
|
2015
1743
|
}
|
|
2016
|
-
|
|
1744
|
+
const v = read();
|
|
1745
|
+
return v instanceof Boxed ? v.c : v;
|
|
2017
1746
|
},
|
|
2018
1747
|
has: (_, key) => key in args(),
|
|
2019
1748
|
ownKeys: () => Reflect.ownKeys(args()),
|
|
@@ -2023,159 +1752,13 @@ function slotArgsProxy(args) {
|
|
|
2023
1752
|
} : undefined
|
|
2024
1753
|
});
|
|
2025
1754
|
}
|
|
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();
|
|
1755
|
+
function slotsFor(props, scope) {
|
|
2168
1756
|
const fillScopes = new Map();
|
|
2169
1757
|
return new Proxy({}, {
|
|
2170
1758
|
get(_, prop) {
|
|
2171
1759
|
if (typeof prop !== "string" || !(prop in props)) return undefined;
|
|
2172
1760
|
return (slotProps, ctx) => {
|
|
2173
1761
|
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
1762
|
const prevFill = key !== undefined && fillScopes.get(key);
|
|
2180
1763
|
if (prevFill) {
|
|
2181
1764
|
fillScopes.delete(key);
|
|
@@ -2185,7 +1768,11 @@ function slotsFor(props) {
|
|
|
2185
1768
|
const fill = props[prop];
|
|
2186
1769
|
if (typeof fill !== "function") {
|
|
2187
1770
|
{
|
|
2188
|
-
slotShapeFinding(
|
|
1771
|
+
slotShapeFinding({
|
|
1772
|
+
reason: "fill-shape",
|
|
1773
|
+
occurrence: key,
|
|
1774
|
+
shape: typeof fill
|
|
1775
|
+
}, `[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
1776
|
}
|
|
2190
1777
|
return undefined;
|
|
2191
1778
|
}
|
|
@@ -2197,10 +1784,12 @@ function slotsFor(props) {
|
|
|
2197
1784
|
});
|
|
2198
1785
|
runWithOwner(owner, () => {
|
|
2199
1786
|
const args = ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotArgsProxy(() => slotProps);
|
|
2200
|
-
|
|
1787
|
+
tierLoads.bind.r.bind(fill, args, ctx, `the \`${prop}\` binding-slot fill` );
|
|
2201
1788
|
});
|
|
2202
1789
|
return undefined;
|
|
2203
1790
|
}
|
|
1791
|
+
const range = ctx && ctx.range;
|
|
1792
|
+
if (!range) return undefined;
|
|
2204
1793
|
const fillOwner = streamInvoke ? createOwner() : null;
|
|
2205
1794
|
if (fillOwner && key !== undefined && ctx) {
|
|
2206
1795
|
fillScopes.set(key, fillOwner);
|
|
@@ -2209,42 +1798,31 @@ function slotsFor(props) {
|
|
|
2209
1798
|
fillOwner.dispose();
|
|
2210
1799
|
});
|
|
2211
1800
|
}
|
|
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
1801
|
const evaluate = () => {
|
|
2222
1802
|
const v = props[prop];
|
|
2223
1803
|
if (typeof v === "function" && ctx && ctx.invoked) {
|
|
2224
|
-
|
|
1804
|
+
const fillProps = ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotArgsProxy(() => slotProps);
|
|
1805
|
+
return untrack(() => v(fillProps), `the \`${prop}\` template-slot fill` );
|
|
2225
1806
|
}
|
|
2226
1807
|
return v;
|
|
2227
1808
|
};
|
|
2228
1809
|
const adopted = !!(ctx && ctx.frame && ctx.adopted && ctx.existing && ctx.existing.length);
|
|
2229
1810
|
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);
|
|
1811
|
+
const value = fillOwner ? runWithOwner(fillOwner, () => adopted ? claimRender(prefix, ctx.existing, evaluate, scope) : evaluate()) : adopted ? claimRender(prefix, ctx.existing, evaluate, scope) : evaluate();
|
|
1812
|
+
const owner = fillOwner || createOwner({
|
|
1813
|
+
transparent: true
|
|
1814
|
+
});
|
|
1815
|
+
if (!fillOwner) {
|
|
1816
|
+
fillScopes.set(key, owner);
|
|
2238
1817
|
ctx.onCleanup(() => {
|
|
2239
|
-
if (
|
|
1818
|
+
if (fillScopes.get(key) === owner) fillScopes.delete(key);
|
|
2240
1819
|
owner.dispose();
|
|
2241
1820
|
});
|
|
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
1821
|
}
|
|
2247
|
-
|
|
1822
|
+
const end = range.end;
|
|
1823
|
+
const bind = () => insert(end.parentNode, value, end, [...ctx.existing]);
|
|
1824
|
+
runWithOwner(owner, () => adopted ? claimRender(prefix, ctx.existing, bind, scope, true) : bind());
|
|
1825
|
+
return undefined;
|
|
2248
1826
|
};
|
|
2249
1827
|
}
|
|
2250
1828
|
});
|
|
@@ -2267,12 +1845,8 @@ function boundaryScope(owner) {
|
|
|
2267
1845
|
function boundaryComponent(host, fnId) {
|
|
2268
1846
|
return (props, binding) => {
|
|
2269
1847
|
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;
|
|
1848
|
+
const id = binding ? contentAddress(binding()) : fnId;
|
|
1849
|
+
const [failed, onApply] = failing();
|
|
2276
1850
|
const {
|
|
2277
1851
|
element,
|
|
2278
1852
|
frame,
|
|
@@ -2283,30 +1857,12 @@ function boundaryComponent(host, fnId) {
|
|
|
2283
1857
|
slots: slotsFor(props),
|
|
2284
1858
|
ownerScope: boundaryScope(owner),
|
|
2285
1859
|
reveal: revealSeam(owner),
|
|
2286
|
-
onApply
|
|
2287
|
-
applied = true;
|
|
2288
|
-
if (release) {
|
|
2289
|
-
release();
|
|
2290
|
-
release = undefined;
|
|
2291
|
-
}
|
|
2292
|
-
setGate && setGate(undefined);
|
|
2293
|
-
}
|
|
1860
|
+
onApply
|
|
2294
1861
|
});
|
|
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
1862
|
onCleanup(dispose);
|
|
2307
|
-
if (
|
|
2308
|
-
|
|
2309
|
-
return createMemo(() => (
|
|
1863
|
+
if (!binding) return landing(host, id, element, failed);
|
|
1864
|
+
followAddress(host, frame, binding);
|
|
1865
|
+
return createMemo(() => landing(host, contentAddress(binding()), element, failed));
|
|
2310
1866
|
};
|
|
2311
1867
|
}
|
|
2312
1868
|
const claimedBoundaries = new Set();
|
|
@@ -2321,7 +1877,7 @@ function pumpLiveChannel() {
|
|
|
2321
1877
|
const pump = () => reader.read().then(r => {
|
|
2322
1878
|
if (r.done) return;
|
|
2323
1879
|
const op = r.value;
|
|
2324
|
-
liveOps.set(`${
|
|
1880
|
+
for (const m of op.type === "ops" ? op.ops : [op]) liveOps.set(`${m.type}:${m.fid || ""}:${m.key || ""}`, m);
|
|
2325
1881
|
for (const apply of liveAppliers) apply(op);
|
|
2326
1882
|
return pump();
|
|
2327
1883
|
});
|
|
@@ -2331,7 +1887,7 @@ function pumpLiveChannel() {
|
|
|
2331
1887
|
let boundaryIndex = null;
|
|
2332
1888
|
const isBoundaryId = id => !id.includes(".");
|
|
2333
1889
|
function indexBoundaries(root) {
|
|
2334
|
-
root.querySelectorAll(
|
|
1890
|
+
root.querySelectorAll(FRAME_SELECTOR).forEach(el => {
|
|
2335
1891
|
const key = el.getAttribute(FRAME_ID_ATTR);
|
|
2336
1892
|
if (key && isBoundaryId(key) && !boundaryIndex.has(key)) boundaryIndex.set(key, el);
|
|
2337
1893
|
});
|
|
@@ -2341,10 +1897,14 @@ function findBoundaryElement(id) {
|
|
|
2341
1897
|
boundaryIndex = new Map();
|
|
2342
1898
|
if (typeof document !== "undefined" && document.body) indexBoundaries(document.body);
|
|
2343
1899
|
}
|
|
2344
|
-
|
|
1900
|
+
for (let n = 0;; n++) {
|
|
1901
|
+
const key = n ? id + "~" + (n + 1) : id;
|
|
1902
|
+
if (!claimedBoundaries.has(key)) return boundaryIndex.get(key);
|
|
1903
|
+
}
|
|
2345
1904
|
}
|
|
2346
|
-
const boundaryWaiters = new Map();
|
|
2347
1905
|
const arrivals = new Map();
|
|
1906
|
+
const FRAME_SELECTOR = `[${FRAME_ID_ATTR}]`;
|
|
1907
|
+
const disposedFrames = new WeakSet();
|
|
2348
1908
|
function awaitBoundary(id) {
|
|
2349
1909
|
let arrival = arrivals.get(id);
|
|
2350
1910
|
if (!arrival) {
|
|
@@ -2363,21 +1923,20 @@ function boundaryMayArrive() {
|
|
|
2363
1923
|
return !hy.done || !!(hy.fr && hy.fr.pending());
|
|
2364
1924
|
}
|
|
2365
1925
|
function installRevealHook() {
|
|
1926
|
+
installServerComponentHydration();
|
|
2366
1927
|
const hy = globalThis._$HY;
|
|
2367
1928
|
if (!hy || hy.$sc || !hy.fr) return;
|
|
2368
1929
|
hy.$sc = true;
|
|
1930
|
+
hy.fa = pl => {
|
|
1931
|
+
const el = pl.closest(FRAME_SELECTOR);
|
|
1932
|
+
return !!el && !disposedFrames.has(el);
|
|
1933
|
+
};
|
|
2369
1934
|
hy.fr.subscribe((_id, parent) => {
|
|
2370
1935
|
if (!boundaryIndex) return;
|
|
2371
1936
|
const root = parent || (typeof document !== "undefined" ? document.body : null);
|
|
2372
1937
|
if (root) indexBoundaries(root);
|
|
2373
|
-
if (!
|
|
1938
|
+
if (!arrivals.size) return;
|
|
2374
1939
|
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
1940
|
for (const [id, arrival] of arrivals) {
|
|
2382
1941
|
const el = boundaryIndex && boundaryIndex.get(id);
|
|
2383
1942
|
if (!el && !exhausted) continue;
|
|
@@ -2388,59 +1947,59 @@ function installRevealHook() {
|
|
|
2388
1947
|
}
|
|
2389
1948
|
function documentBoundary(host, id, props, binding) {
|
|
2390
1949
|
installRevealHook();
|
|
2391
|
-
const
|
|
2392
|
-
const el = !claimed ? findBoundaryElement(id) : undefined;
|
|
1950
|
+
const el = findBoundaryElement(id);
|
|
2393
1951
|
if (el) return adoptBoundary(host, id, el, props, binding);
|
|
2394
|
-
if (!
|
|
1952
|
+
if (!claimedBoundaries.has(id) && boundaryMayArrive()) {
|
|
2395
1953
|
const owner = getOwner();
|
|
2396
|
-
|
|
2397
|
-
onCleanup(() =>
|
|
2398
|
-
return createMemo(() =>
|
|
2399
|
-
|
|
1954
|
+
let live = true;
|
|
1955
|
+
onCleanup(() => live = false);
|
|
1956
|
+
return createMemo(() => awaitBoundary(id).then(() => live && runWithOwner(owner, () => {
|
|
1957
|
+
const node = findBoundaryElement(id);
|
|
1958
|
+
return node ? adoptBoundary(host, id, node, props, binding) : boundaryComponent(host, id)(props, binding);
|
|
1959
|
+
})));
|
|
2400
1960
|
}
|
|
2401
1961
|
return boundaryComponent(host, id)(props, binding);
|
|
2402
1962
|
}
|
|
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
1963
|
function adoptBoundary(host, id, el, props, binding) {
|
|
2411
|
-
|
|
2412
|
-
|
|
1964
|
+
const siteId = el.getAttribute(FRAME_ID_ATTR);
|
|
1965
|
+
claimedBoundaries.add(siteId);
|
|
1966
|
+
const address = binding ? contentAddress(binding()) : id;
|
|
2413
1967
|
const appliedRecords = new Set();
|
|
2414
|
-
const
|
|
2415
|
-
const
|
|
2416
|
-
const
|
|
2417
|
-
if (!
|
|
1968
|
+
const reportedFragments = new Set();
|
|
1969
|
+
const reportRegionFragments = root => {
|
|
1970
|
+
const hy = globalThis._$HY;
|
|
1971
|
+
if (!hy || !hy.r) return;
|
|
2418
1972
|
root.querySelectorAll('template[id^="pl-"]').forEach(tpl => {
|
|
2419
1973
|
const fragId = tpl.id.slice(3);
|
|
2420
|
-
if (
|
|
2421
|
-
|
|
2422
|
-
|
|
1974
|
+
if (reportedFragments.has(fragId)) return;
|
|
1975
|
+
reportedFragments.add(fragId);
|
|
1976
|
+
const ref = hy.r[fragId + "_fr"];
|
|
1977
|
+
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
1978
|
});
|
|
2424
1979
|
};
|
|
2425
1980
|
const drainRecords = () => {
|
|
2426
1981
|
const hy = globalThis._$HY;
|
|
2427
1982
|
if (!hy || !hy.r) return;
|
|
2428
1983
|
pumpLiveChannel();
|
|
2429
|
-
const slotPrefix = `sc:slot:${
|
|
1984
|
+
const slotPrefix = `sc:slot:${siteId}:`;
|
|
2430
1985
|
for (const key of Object.keys(hy.r)) {
|
|
2431
1986
|
if (appliedRecords.has(key)) continue;
|
|
2432
1987
|
if (key.startsWith(slotPrefix)) {
|
|
2433
1988
|
appliedRecords.add(key);
|
|
2434
|
-
host.apply({
|
|
1989
|
+
const apply = args => host.apply({
|
|
2435
1990
|
type: "slot",
|
|
2436
1991
|
id: address,
|
|
2437
1992
|
version: 0,
|
|
2438
1993
|
key: key.slice(slotPrefix.length),
|
|
2439
|
-
args
|
|
1994
|
+
args
|
|
2440
1995
|
});
|
|
1996
|
+
const value = hy.r[key];
|
|
1997
|
+
if (value && typeof value.then === "function") {
|
|
1998
|
+
if (value.s === 1) apply(value.v);else if (value.s === 2) value.then(undefined, () => {});else value.then(apply, () => {});
|
|
1999
|
+
} else apply(value);
|
|
2441
2000
|
} else if (key.startsWith("sc:region:")) {
|
|
2442
2001
|
const childId = key.slice("sc:region:".length);
|
|
2443
|
-
if (childId.startsWith(
|
|
2002
|
+
if (childId.startsWith(siteId + ".")) {
|
|
2444
2003
|
appliedRecords.add(key);
|
|
2445
2004
|
const val = hy.r[key];
|
|
2446
2005
|
const apply = html => host.apply({
|
|
@@ -2454,14 +2013,22 @@ function adoptBoundary(host, id, el, props, binding) {
|
|
|
2454
2013
|
}
|
|
2455
2014
|
}
|
|
2456
2015
|
};
|
|
2457
|
-
|
|
2016
|
+
reportRegionFragments(el);
|
|
2017
|
+
const scope = claimScope(el);
|
|
2458
2018
|
const fr = globalThis._$HY?.fr;
|
|
2019
|
+
let frame;
|
|
2459
2020
|
const unsubscribe = fr ? fr.subscribe((_fragId, parent) => {
|
|
2460
|
-
|
|
2021
|
+
const inside = !!parent && el.contains(parent);
|
|
2022
|
+
inside && scope.index(parent);
|
|
2023
|
+
inside && reportRegionFragments(parent);
|
|
2461
2024
|
drainRecords();
|
|
2025
|
+
if (inside && frame) frame.apply({
|
|
2026
|
+
version: frame.version ?? 0,
|
|
2027
|
+
r: {}
|
|
2028
|
+
});
|
|
2462
2029
|
}) : undefined;
|
|
2463
2030
|
const applyLiveOp = op => {
|
|
2464
|
-
if (op.
|
|
2031
|
+
if (op.fid && op.fid !== siteId) return;
|
|
2465
2032
|
host.apply({
|
|
2466
2033
|
...op,
|
|
2467
2034
|
id: address,
|
|
@@ -2472,55 +2039,41 @@ function adoptBoundary(host, id, el, props, binding) {
|
|
|
2472
2039
|
onCleanup(() => {
|
|
2473
2040
|
liveAppliers.delete(applyLiveOp);
|
|
2474
2041
|
unsubscribe && unsubscribe();
|
|
2475
|
-
if (fr && fr.release) for (const fragId of claimedFragments) fr.release(fragId);
|
|
2476
2042
|
});
|
|
2477
2043
|
drainRecords();
|
|
2478
2044
|
for (const op of liveOps.values()) applyLiveOp(op);
|
|
2479
2045
|
const owner = getOwner();
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2046
|
+
const sc = sharedConfig;
|
|
2047
|
+
const [failed, onApply] = failing();
|
|
2048
|
+
frame = createFrame(el, {
|
|
2483
2049
|
adopt: true,
|
|
2484
2050
|
host,
|
|
2485
2051
|
id: address,
|
|
2486
|
-
slots: slotsFor(props),
|
|
2052
|
+
slots: slotsFor(props, scope),
|
|
2487
2053
|
ownerScope: boundaryScope(owner),
|
|
2488
2054
|
reveal: revealSeam(owner),
|
|
2489
|
-
onApply
|
|
2490
|
-
|
|
2491
|
-
release();
|
|
2492
|
-
release = undefined;
|
|
2493
|
-
}
|
|
2494
|
-
setGate && setGate(undefined);
|
|
2495
|
-
},
|
|
2055
|
+
onApply,
|
|
2056
|
+
hold: () => sc.isHydrationInProgress?.() ? runWithOwner(owner, () => untrack(() => sc.holdBoundary("sc:" + siteId))) : () => {},
|
|
2496
2057
|
...{
|
|
2497
|
-
|
|
2498
|
-
if (document.readyState === "loading") return true;
|
|
2499
|
-
const hy = globalThis._$HY;
|
|
2500
|
-
return !!(hy && hy.fr && hy.fr.pending());
|
|
2501
|
-
},
|
|
2502
|
-
drainRecords,
|
|
2503
|
-
claimScope: id
|
|
2058
|
+
claimScope: siteId
|
|
2504
2059
|
}
|
|
2505
2060
|
});
|
|
2506
2061
|
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), () => {});
|
|
2062
|
+
followAddress(host, frame, binding);
|
|
2063
|
+
const source = createMemo(() => landing(host, contentAddress(binding()), true, failed));
|
|
2064
|
+
createRenderEffect(() => source()(), () => {});
|
|
2518
2065
|
}
|
|
2519
|
-
onCleanup(() =>
|
|
2066
|
+
onCleanup(() => {
|
|
2067
|
+
frame.dispose();
|
|
2068
|
+
disposedFrames.add(el);
|
|
2069
|
+
el.querySelectorAll(FRAME_SELECTOR).forEach(e => disposedFrames.add(e));
|
|
2070
|
+
});
|
|
2520
2071
|
return el;
|
|
2521
2072
|
}
|
|
2522
|
-
function installServerComponents(host = getFrameHost()) {
|
|
2073
|
+
function installServerComponents(host = getFrameHost(), options) {
|
|
2523
2074
|
const g = globalThis;
|
|
2075
|
+
Object.assign(tierLoaders, options?.tiers);
|
|
2076
|
+
g._$HY?.r?.["sc:tiers"]?.forEach(prepareTier);
|
|
2524
2077
|
if (!g._$SC) {
|
|
2525
2078
|
g._$SC = {
|
|
2526
2079
|
c: {},
|
|
@@ -2545,13 +2098,11 @@ function installServerComponents(host = getFrameHost()) {
|
|
|
2545
2098
|
const handler = createServerComponentHandler({
|
|
2546
2099
|
host,
|
|
2547
2100
|
component: fnId => g._$SC.r(fnId),
|
|
2548
|
-
onStream: address => beginStream(address),
|
|
2549
2101
|
intercept: ({
|
|
2550
2102
|
id
|
|
2551
2103
|
}) => {
|
|
2552
|
-
if (claimedBoundaries.has(id)) return undefined;
|
|
2553
2104
|
if (findBoundaryElement(id)) return true;
|
|
2554
|
-
if (!boundaryMayArrive()) return undefined;
|
|
2105
|
+
if (claimedBoundaries.has(id) || !boundaryMayArrive()) return undefined;
|
|
2555
2106
|
installRevealHook();
|
|
2556
2107
|
return awaitBoundary(id);
|
|
2557
2108
|
}
|
|
@@ -2565,4 +2116,4 @@ function installServerComponents(host = getFrameHost()) {
|
|
|
2565
2116
|
});
|
|
2566
2117
|
}
|
|
2567
2118
|
|
|
2568
|
-
export { FRAME_APPLIED_EVENT,
|
|
2119
|
+
export { FRAME_APPLIED_EVENT, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents, isAsyncValue, isFrameStreamResponse };
|