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