@solidjs/web 2.0.0-rc.11 → 2.0.0-rc.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/server.dev.js +705 -151
  2. package/dist/server.js +604 -123
  3. package/dist/server.observe.js +617 -124
  4. package/dist/web.dev.js +102 -41
  5. package/dist/web.js +75 -37
  6. package/dist/web.observe.js +75 -39
  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 +693 -919
  11. package/frames/dist/client.js +636 -917
  12. package/frames/dist/client.observe.js +637 -917
  13. package/frames/dist/regions.js +130 -0
  14. package/frames/dist/server.dev.js +607 -212
  15. package/frames/dist/server.js +554 -212
  16. package/frames/dist/server.observe.js +554 -212
  17. package/frames/dist/trace.js +42 -0
  18. package/frames/dist/wire.js +133 -0
  19. package/package.json +30 -3
  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 +37 -8
  24. package/serialization/dist/serialization.js +39 -10
  25. package/serialization/types/serializer-decode.d.ts +24 -2
  26. package/server-functions/dist/client.dev.js +178 -72
  27. package/server-functions/dist/client.js +99 -61
  28. package/server-functions/dist/client.observe.js +178 -72
  29. package/server-functions/dist/server.dev.js +117 -56
  30. package/server-functions/dist/server.js +117 -56
  31. package/server-functions/dist/server.observe.js +117 -56
  32. package/skills/server-components/SKILL.md +228 -0
  33. package/types/client.d.ts +37 -2
  34. package/types/constants.d.ts +2 -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 -96
  40. package/types/frames/frame-container-plugin.d.ts +2 -10
  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 +53 -1
  46. package/types/frames/trace-tier.d.ts +2 -0
  47. package/types/frames/tree-rewrite.d.ts +39 -0
  48. package/types/frames/wire-tier.d.ts +116 -0
  49. package/types/index.d.ts +38 -0
  50. package/types/index.server.d.ts +10 -1
  51. package/types/jsx.d.ts +11 -1
  52. package/types/observe.d.ts +182 -12
  53. package/types/request-error-hook.d.ts +5 -0
  54. package/types/serializer-decode.d.ts +24 -2
  55. package/types/server-functions/client.d.ts +26 -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 +13 -1
  59. package/types/server-observe.d.ts +8 -0
  60. package/types/server.d.ts +125 -12
@@ -1,7 +1,7 @@
1
- import { getOwner, onCleanup, createMemo, runWithOwner, createSignal, createRenderEffect, createLoadingBoundary, createOwner, sharedConfig } from 'solid-js';
2
- import { delegateEvents, insert } from '@solidjs/web';
3
- import { LIVE_WIRE, isEventStream, ChunkReader, frameAddress, SINGLE_FLIGHT_HEADER, deserializeStream, getServerFunctionsCodec, createChunk, deliverFlightData, ERROR_HEADER, hasFlightMetadata, configureServerFunctionsClient } from '@solidjs/web/server-functions/client';
4
- import { materializeContainerTrace } from 'solid-js/internal';
1
+ import { getOwner, onCleanup, createMemo, runWithOwner, untrack, createRenderEffect, createSignal, createOwner } from 'solid-js';
2
+ import { insert } from '@solidjs/web';
3
+ import { LIVE_WIRE, ChunkReader, frameAddress, SINGLE_FLIGHT_HEADER, deserializeStream, getServerFunctionsCodec, createChunk, deliverFlightData, ERROR_HEADER, hasFlightMetadata, configureServerFunctionsClient } from '@solidjs/web/server-functions/client';
4
+ import { sharedConfig, createLoadingBoundary } from 'solid-js/internal';
5
5
 
6
6
  const ELEMENT_NODE = 1;
7
7
  const TEXT_NODE = 3;
@@ -16,71 +16,6 @@ function claimNode(handlers, el) {
16
16
  for (let i = 0; i < handlers.length; i++) handlers[i](el);
17
17
  }
18
18
  const claimedAttr = name => name === "href" || name === "action";
19
- const BOUND_SEAM = Symbol.for("solid.bnd");
20
- const boundSeam = globalThis[BOUND_SEAM] || (globalThis[BOUND_SEAM] = {});
21
- const BND_ATTR = "_bnd";
22
- const BND_SELECTOR = "[_bnd]";
23
- function bndMap(el) {
24
- const s = el.getAttribute(BND_ATTR);
25
- if (!s) return undefined;
26
- const map = {};
27
- for (const entry of s.split(",")) {
28
- const eq = entry.indexOf("=");
29
- if (eq < 1) continue;
30
- const pos = entry.slice(0, eq);
31
- const prop = decodeURIComponent(entry.slice(eq + 1));
32
- const prev = map[pos];
33
- if (prev === undefined) map[pos] = prop;else if (Array.isArray(prev)) prev.push(prop);else map[pos] = [prev, prop];
34
- }
35
- return map;
36
- }
37
- boundSeam.resolve = (el, type) => {
38
- const frame = el._$bndFrame;
39
- if (!frame) return undefined;
40
- const map = bndMap(el);
41
- const prop = map && map[type];
42
- if (typeof prop !== "string") return undefined;
43
- return claimFn(frame, type, prop);
44
- };
45
- function claimFn(frame, pos, prop) {
46
- const fn = frame.clientProp(prop);
47
- if (typeof fn === "function") return fn;
48
- return undefined;
49
- }
50
- function sweepBound(root, frame, delegate, scope) {
51
- const isElement = root.nodeType === ELEMENT_NODE;
52
- if (!isElement && root.nodeType !== 11 ) return;
53
- let els;
54
- if (isElement && root.hasAttribute(BND_ATTR)) (els = []).push(root);
55
- const found = root.querySelectorAll(BND_SELECTOR);
56
- if (found.length) {
57
- els || (els = []);
58
- for (let i = 0; i < found.length; i++) els.push(found[i]);
59
- }
60
- if (!els) return;
61
- const run = () => {
62
- let types;
63
- for (const el of els) {
64
- el._$bndFrame = frame;
65
- const map = bndMap(el);
66
- if (!map) continue;
67
- for (const pos in map) {
68
- if (pos === "ref") fireRefs(frame, el, map.ref);else (types || (types = [])).push(pos);
69
- }
70
- }
71
- if (types && delegate) delegate(types);
72
- };
73
- scope ? scope(run) : run();
74
- }
75
- function fireRefs(frame, el, prop) {
76
- const fired = el._$bndFired || (el._$bndFired = new Set());
77
- for (const p of Array.isArray(prop) ? prop : [prop]) {
78
- if (fired.has(p)) continue;
79
- fired.add(p);
80
- const fn = claimFn(frame, "ref", p);
81
- if (fn) fn(el);
82
- }
83
- }
84
19
  function claimTree(handlers, root) {
85
20
  const isElement = root.nodeType === ELEMENT_NODE;
86
21
  if (!isElement && root.nodeType !== 11 ) return;
@@ -92,6 +27,18 @@ const placeholderId = name => `pl-${name}`;
92
27
  const SLOT_START = /^slot:(.+):start$/;
93
28
  const SLOT_END = /^slot:(.+):end$/;
94
29
  const slotEnd = id => `slot:${id}:end`;
30
+ const SLOT_MARKER = "_s:";
31
+ const SLOT_TEXT = SLOT_MARKER + "t=";
32
+ const SLOT_TEXT_END = "/" + SLOT_MARKER + "t";
33
+ const isTextStart = n => n.nodeType === COMMENT_NODE && n.data.startsWith(SLOT_TEXT);
34
+ function hasSlotMarker(el) {
35
+ const attrs = el.attributes;
36
+ for (let i = 0; i < attrs.length; i++) if (attrs[i].name.startsWith(SLOT_MARKER)) return true;
37
+ return false;
38
+ }
39
+ function isAsyncValue(v) {
40
+ return v !== null && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
41
+ }
95
42
  function chunkToRecords(chunk) {
96
43
  switch (chunk.type) {
97
44
  case "start":
@@ -151,9 +98,12 @@ function chunkToRecords(chunk) {
151
98
  digest: chunk.digest
152
99
  }
153
100
  };
101
+ case "ops":
102
+ return Object.assign({}, ...chunk.ops.map(chunkToRecords));
154
103
  case "complete":
155
104
  return {
156
- ":complete": true
105
+ ":complete": true,
106
+ ":bound": chunk.bound
157
107
  };
158
108
  case "error":
159
109
  if (!chunk.key) return {
@@ -177,11 +127,20 @@ function createFrameHost(options = {}) {
177
127
  });
178
128
  return store;
179
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
+ };
180
139
  const write = (store, version, records) => {
181
140
  if (store.version !== undefined && version < store.version) return false;
182
141
  if (store.version === undefined || version > store.version) {
183
142
  store.version = version;
184
- clearStreamRecords(store.records);
143
+ store.records = {};
185
144
  }
186
145
  const assets = records["seg::assets"];
187
146
  const previous = assets && store.records["seg::assets"];
@@ -197,19 +156,47 @@ function createFrameHost(options = {}) {
197
156
  }
198
157
  return true;
199
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
+ };
200
186
  return {
201
- delegate: options.delegate,
202
187
  register(id, frame) {
203
188
  let set = frames.get(id);
204
189
  if (!set) frames.set(id, set = new Set());
205
190
  set.add(frame);
206
191
  const store = stores.get(id);
207
192
  if (store && store.version !== undefined) {
208
- frame.apply({
193
+ if (!store.open) frame.apply({
209
194
  version: store.version,
210
195
  r: store.records
196
+ });else if (store.shown) frame.apply({
197
+ version: store.shownVersion,
198
+ r: store.shown
211
199
  });
212
- frame.rebase && frame.rebase();
213
200
  }
214
201
  },
215
202
  unregister(id, frame) {
@@ -227,26 +214,65 @@ function createFrameHost(options = {}) {
227
214
  value: html
228
215
  };
229
216
  if (store.version === undefined) store.version = 0;
217
+ store.shown = store.records;
218
+ store.shownVersion = store.version;
230
219
  }
231
220
  }
232
221
  }
233
222
  }
234
- if (!frame) stores.delete(id);
223
+ if (!frame) {
224
+ stores.delete(id);
225
+ landings.delete(id);
226
+ }
235
227
  },
236
228
  apply(chunk) {
237
229
  if (chunk.type === "data") {
238
- 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);
239
234
  return;
240
235
  }
241
236
  const records = chunkToRecords(chunk);
242
- if (!write(storeFor(chunk.id), chunk.version, records)) return;
243
- const set = frames.get(chunk.id);
244
- if (set) {
245
- for (const frame of set) frame.apply({
246
- version: chunk.version,
247
- r: records
248
- });
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));
249
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);
250
276
  },
251
277
  get(id) {
252
278
  const set = frames.get(id);
@@ -256,66 +282,66 @@ function createFrameHost(options = {}) {
256
282
  if (!options.serialize) throw new Error("host has no serializer");
257
283
  return options.serialize(value);
258
284
  },
259
- resolve(ref, frameId) {
260
- return options.resolve ? options.resolve(ref, frameId) : undefined;
261
- },
262
285
  revive: options.revive,
263
- isContainer: options.isContainer,
264
286
  prepareData: options.prepareData
265
287
  };
266
288
  }
267
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");
268
312
  class FrameImpl {
269
313
  #element;
270
- #start;
271
- #end;
272
314
  #options;
315
+ #outer;
273
316
  #version;
274
317
  #store = Object.create(null);
275
- #appliedRootValue;
318
+ #appliedRoot;
319
+ #appliedError;
276
320
  #hasContent = false;
277
- #errorNotified = false;
278
- #revealed = new Set();
279
- #fallbackShown = new Set();
280
321
  #appliedHoles = new Map();
281
- #have;
282
322
  #slots;
283
323
  #mountedSlots = new Set();
284
324
  #slotCleanups = new Map();
285
325
  #slotArgs = new Map();
286
326
  #slotUpdaters = new Map();
287
- #slotRegions = new Map();
288
- #slotResolvedRefs = new Map();
289
- #slotNodes = new Map();
290
- #processedAssets = new WeakSet();
291
- #recordRefresh = null;
327
+ #hold;
328
+ #heldRecords = new Map();
292
329
  #disposed = false;
293
- #styleFlush = () => {
294
- if (!this.#disposed) this.#flush();
295
- };
296
330
  #claimTree = (node, direct) => {
297
- if (!direct && node.nodeType !== TEXT_NODE && node.nodeType !== COMMENT_NODE) {
298
- const o = this.#options;
299
- sweepBound(node, this, o.delegate || o.host && o.host.delegate, o.ownerScope);
300
- }
301
331
  const handlers = claimHandlers();
302
332
  if (!handlers) return;
303
333
  this.#scoped(() => direct ? claimNode(handlers, node) : claimTree(handlers, node));
304
334
  };
305
- clientProp(name) {
306
- const props = this.#options.props;
307
- return props ? props[name] : undefined;
308
- }
309
335
  #scoped(fn) {
310
336
  const scope = this.#options.ownerScope;
311
337
  return scope ? scope(fn) : fn();
312
338
  }
313
- constructor(element, start, end, options = {}) {
339
+ constructor(element, options = {}) {
314
340
  this.#element = element;
315
- this.#start = start;
316
- this.#end = end;
317
341
  this.#options = options;
318
342
  this.#slots = options.slots;
343
+ this.#outer = options.parent;
344
+ liveFrames.add(this);
319
345
  if (options.adopt) {
320
346
  this.#hasContent = true;
321
347
  this.#claimContent();
@@ -325,15 +351,12 @@ class FrameImpl {
325
351
  }
326
352
  if (options.adopt && this.#version === undefined) this.#syncSlots();
327
353
  }
328
- #parent() {
329
- return this.#element ?? this.#start.parentNode;
330
- }
331
354
  #applied(version, reason) {
332
355
  this.#options.onApply?.({
333
356
  version,
334
357
  reason
335
358
  });
336
- const parent = this.#parent();
359
+ const parent = this.#element;
337
360
  const Ev = parent && (parent.ownerDocument || parent).defaultView?.CustomEvent;
338
361
  if (Ev) {
339
362
  parent.dispatchEvent(new Ev(FRAME_APPLIED_EVENT, {
@@ -346,18 +369,12 @@ class FrameImpl {
346
369
  }));
347
370
  }
348
371
  }
349
- #firstContent() {
350
- return this.#start ? this.#start.nextSibling : this.#parent().firstChild;
351
- }
352
372
  get version() {
353
373
  return this.#version;
354
374
  }
355
375
  get store() {
356
376
  return this.#store;
357
377
  }
358
- isRevealed(segment) {
359
- return this.#revealed.has(segment);
360
- }
361
378
  get error() {
362
379
  return this.#store[":error"];
363
380
  }
@@ -372,68 +389,59 @@ class FrameImpl {
372
389
  this.#version = v;
373
390
  this.#resetStreamState();
374
391
  }
375
- for (const key in write.r) {
376
- const incoming = write.r[key];
377
- if (incoming && incoming.kind === "slot" && key.charCodeAt(0) === 115 && key.startsWith("slot:")) {
378
- const existing = this.#store[key];
379
- if (existing && existing.kind === "slot" && argsEquivalent(existing.args, incoming.args)) {
380
- continue;
381
- }
382
- }
383
- this.#store[key] = incoming;
384
- }
392
+ for (const key in write.r) this.#store[key] = write.r[key];
385
393
  this.#flush();
386
394
  }
387
- #resetStreamState(root) {
388
- this.#revealed.clear();
389
- 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;
390
417
  this.#appliedHoles.clear();
391
- this.#processedAssets = new WeakSet();
392
- this.#errorNotified = false;
393
- clearStreamRecords(this.#store, root);
394
418
  }
395
419
  #flush() {
396
420
  if (this.#disposed) return;
397
421
  const version = this.#version;
398
422
  const root = this.#store[""];
399
- if (root && root.kind === "html" && root.value !== this.#appliedRootValue) {
423
+ if (root && root.kind === "html" && root !== this.#appliedRoot) {
400
424
  const reason = this.#hasContent ? "morph" : "materialize";
401
425
  this.#applyRoot(root.value);
402
- this.#appliedRootValue = root.value;
403
- this.#have = root.digest === undefined ? undefined : {
404
- "": root.digest,
405
- ...root.holes
406
- };
426
+ this.#appliedRoot = root;
427
+ this.#recordHave("", root);
407
428
  this.#applied(version, reason);
408
429
  }
409
- if (this.#store[":error"] && !this.#errorNotified) {
410
- this.#errorNotified = true;
430
+ const error = this.#store[":error"];
431
+ if (error && error !== this.#appliedError) {
432
+ this.#appliedError = error;
411
433
  this.#applied(version, "error");
412
434
  }
413
- let progressed = true;
414
- while (progressed) {
415
- progressed = false;
416
- for (const key in this.#store) {
417
- const name = segmentName(key);
418
- if (name === null || this.#revealed.has(name)) continue;
419
- if (this.#segmentReady(name)) {
420
- this.#revealSegment(name);
421
- this.#applied(version, "reveal");
422
- progressed = true;
423
- }
424
- }
425
- for (const key in this.#store) {
426
- const m = /^seg:([^:]+):fallback$/.exec(key);
427
- if (!m) continue;
428
- const name = m[1];
429
- if (this.#revealed.has(name) || this.#fallbackShown.has(name)) continue;
430
- if (this.#showFallback(name)) {
431
- this.#fallbackShown.add(name);
432
- this.#applied(version, "reveal");
433
- progressed = true;
434
- }
435
- }
436
- }
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;
437
445
  for (const key in this.#store) {
438
446
  const record = this.#store[key];
439
447
  if (!record || this.#appliedHoles.get(key) === record) continue;
@@ -443,110 +451,102 @@ class FrameImpl {
443
451
  } else if (this.#applyHole(key.slice(5), record.value)) {
444
452
  this.#appliedHoles.set(key, record);
445
453
  this.#recordHave(key.slice(5), record);
446
- this.#applied(version, "morph");
454
+ morphed = true;
447
455
  }
448
456
  } else if (key.startsWith("attr:")) {
449
457
  if (this.#applyAttrs(key.slice(5), record.value, record.removed)) {
450
458
  this.#appliedHoles.set(key, record);
451
459
  this.#recordHave("lha:" + key.slice(5), record);
452
- this.#applied(version, "morph");
460
+ morphed = true;
453
461
  }
454
462
  }
455
463
  }
456
- for (const key in this.#store) {
457
- const record = this.#store[key];
458
- if (!key.endsWith(":assets") || !record || this.#processedAssets.has(record)) {
459
- continue;
460
- }
461
- this.#processedAssets.add(record);
462
- if (record.modules) {
463
- for (const href of record.modules) ensureModulePreload(href);
464
- }
465
- if (record.preloads) {
466
- for (const entry of record.preloads) ensurePreload(entry);
467
- }
468
- }
464
+ if (morphed) this.#applied(version, "morph");
469
465
  this.#syncSlots();
470
466
  }
471
467
  #resolveSlot(prop) {
472
- return this.#slots?.[prop] ?? this.#options.resolveSlot?.(prop);
468
+ return this.#slots?.[prop] ?? (this.#outer && this.#outer.#resolveSlot(prop));
473
469
  }
474
470
  #resolveSlotRecord(occurrence) {
475
471
  const record = this.#store[`slot:${occurrence}`];
476
472
  if (record !== undefined) return record;
477
- return this.#options.resolveSlotRecord?.(occurrence);
473
+ return this.#outer && this.#outer.#resolveSlotRecord(occurrence);
478
474
  }
479
475
  #removeSlotRecord(occurrence) {
480
476
  const key = `slot:${occurrence}`;
481
477
  if (key in this.#store) {
482
478
  if (!this.#mountedSlots.has(occurrence)) delete this.#store[key];
483
- } else this.#options.removeSlotRecord?.(occurrence);
479
+ } else this.#outer && this.#outer.#removeSlotRecord(occurrence);
484
480
  }
485
481
  #syncSlots(root) {
486
- if (!this.#slots && !this.#options.resolveSlot) return;
482
+ if (!this.#slots && !this.#outer) return;
487
483
  const found = new Map();
488
- if (root) collectSlots(root.firstChild, null, found);else this.#collectSlots(found);
484
+ if (root) collectSlots(root.firstChild, null, found, found);else this.#collectSlots(found, found);
485
+ let waiting = false;
486
+ const R = tierLoads.regions?.r;
487
+ const B = tierLoads.bind?.r;
489
488
  for (const [occurrence, start] of found) {
490
489
  const callback = this.#resolveSlot(propOf(occurrence));
491
- if (!callback) continue;
490
+ const consumers = Array.isArray(start) ? start : null;
491
+ if (!callback) {
492
+ continue;
493
+ }
492
494
  const record = this.#resolveSlotRecord(occurrence);
493
- if (record && record.kind === "slot" && this.#refsUnresolved(record.args)) continue;
494
- const prev = this.#slotNodes.get(occurrence);
495
- const prevFirst = Array.isArray(prev) ? prev[0] : prev;
496
- const zombie = this.#mountedSlots.has(occurrence) && prevFirst && !prevFirst.parentNode;
497
- if (zombie) {
498
- this.#mountedSlots.delete(occurrence);
499
- this.#runSlotCleanups(occurrence);
495
+ const mounted = this.#mountedSlots.has(occurrence);
496
+ if (record === undefined && isCalled(occurrence)) {
497
+ waiting ||= !mounted;
498
+ continue;
500
499
  }
501
- if (!this.#mountedSlots.has(occurrence)) {
502
- if (record === undefined && !root && this.#options.adopt && this.#options.recordsPending?.()) {
503
- this.#recordRefresh ??= setTimeout(() => {
504
- this.#recordRefresh = null;
505
- if (this.#disposed) return;
506
- this.#options.drainRecords?.();
507
- this.#syncSlots();
508
- });
509
- continue;
510
- }
511
- if (this.#options.adopt) this.#discoverRegions(occurrence, start);
512
- const nodes = this.#invokeSlot(occurrence, callback, record, start, this.#options.adopt);
513
- if (nodes) this.#replaceRange(occurrence, start, nodes);
514
- this.#slotNodes.set(occurrence, nodes);
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);
503
+ continue;
504
+ }
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);
515
511
  this.#mountedSlots.add(occurrence);
516
- if (!this.#options.adopt || nodes) this.#discoverRegions(occurrence, start);
517
- this.#bindRegions(occurrence);
518
- } else if (record !== this.#slotArgs.get(occurrence)) {
519
- if (this.#refArgsUnchanged(occurrence, record)) {
520
- this.#slotArgs.set(occurrence, record);
521
- this.#reconcileRegions(occurrence, record);
522
- continue;
523
- }
512
+ R?.bind(this, occurrence);
513
+ if (mountRecord === record || !record || record.kind !== "slot") continue;
514
+ }
515
+ if (consumers) B.sync(this, occurrence, consumers);
516
+ if (record !== this.#slotArgs.get(occurrence)) {
517
+ if (needsRegions(record) || needsTrace(record.args)) continue;
524
518
  const update = this.#slotUpdaters.get(occurrence);
525
519
  if (update) {
526
- const props = this.#resolveArgs(occurrence, record.args);
520
+ const props = this.#resolveArgs(occurrence, record);
527
521
  this.#slotArgs.set(occurrence, record);
528
522
  update(props);
529
- this.#bindRegions(occurrence);
523
+ R?.bind(this, occurrence);
530
524
  continue;
531
525
  }
532
- const nodes = this.#invokeSlot(occurrence, callback, record, start);
533
- if (nodes) this.#replaceRange(occurrence, start, nodes);
534
- this.#slotNodes.set(occurrence, nodes);
535
- this.#bindRegions(occurrence);
526
+ this.#invokeSlot(occurrence, callback, record, start);
527
+ R?.bind(this, occurrence);
536
528
  }
537
529
  }
530
+ if (found.b && !tierReady("bind")) waiting = true;
538
531
  if (!root) {
539
532
  for (const occurrence of [...this.#mountedSlots]) {
540
533
  if (!found.has(occurrence)) this.#unmountSlot(occurrence);
541
534
  }
535
+ if (waiting && !this.#hold) this.#hold = this.#options.hold?.();else if (!waiting && this.#hold) this.#releaseHold();
542
536
  }
543
537
  }
538
+ #releaseHold() {
539
+ const release = this.#hold;
540
+ this.#hold = undefined;
541
+ release && release();
542
+ }
544
543
  #invokeSlot(occurrence, callback, record, start, adopted) {
545
544
  this.#slotUpdaters.delete(occurrence);
546
545
  const cleanups = this.#slotCleanups.get(occurrence) ?? [];
547
546
  let existing = [];
548
547
  let end = null;
549
- if (start) end = eachInRange(start, occurrence, n => existing.push(n));
548
+ const positions = Array.isArray(start) ? start : undefined;
549
+ if (start && !positions) end = eachInRange(start, occurrence, n => existing.push(n));
550
550
  const ctx = {
551
551
  frame: this.#options.claimScope ?? this.#options.id,
552
552
  key: occurrence,
@@ -558,33 +558,24 @@ class FrameImpl {
558
558
  range: end ? {
559
559
  start,
560
560
  end
561
- } : undefined
561
+ } : undefined,
562
+ positions,
563
+ onRebind: positions ? fn => tierLoads.bind.r.rebinder(this, occurrence, fn) : undefined
562
564
  };
563
- const props = record && record.kind === "slot" ? this.#resolveArgs(occurrence, record.args) : {};
564
- 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));
565
567
  this.#slotArgs.set(occurrence, record);
566
568
  if (cleanups.length) this.#slotCleanups.set(occurrence, cleanups);
567
- if (content == null) return null;
568
- return Array.isArray(content) ? content : [content];
569
- }
570
- #replaceRange(key, start, nodes) {
571
- const parent = start.parentNode;
572
- const end = eachInRange(start, key, n => parent.removeChild(n));
573
- for (const node of nodes) parent.insertBefore(node, end);
574
569
  }
575
570
  #unmountSlot(key) {
576
571
  this.#mountedSlots.delete(key);
577
- this.#slotNodes.delete(key);
578
572
  this.#slotArgs.delete(key);
579
573
  this.#slotUpdaters.delete(key);
580
- this.#slotResolvedRefs.delete(key);
574
+ this.#heldRecords.delete(key);
581
575
  this.#removeSlotRecord(key);
582
576
  this.#runSlotCleanups(key);
583
- const regions = this.#slotRegions.get(key);
584
- if (regions) {
585
- disposeRegions(regions);
586
- this.#slotRegions.delete(key);
587
- }
577
+ tierLoads.regions?.r?.unmount(this, key);
578
+ tierLoads.bind?.r?.unmount(this, key);
588
579
  }
589
580
  #runSlotCleanups(key) {
590
581
  const cleanups = this.#slotCleanups.get(key);
@@ -592,129 +583,33 @@ class FrameImpl {
592
583
  this.#slotCleanups.delete(key);
593
584
  for (const fn of cleanups) fn();
594
585
  }
595
- #refsUnresolved(args) {
596
- const {
597
- host,
598
- id
599
- } = this.#options;
600
- if (host) for (const key in args) {
601
- if (isDataRef(args[key]) && host.resolve(args[key], id) === undefined) return true;
602
- }
603
- return false;
604
- }
605
- #regionsFor(slotKey) {
606
- let regions = this.#slotRegions.get(slotKey);
607
- if (!regions) this.#slotRegions.set(slotKey, regions = new Map());
608
- return regions;
586
+ get options() {
587
+ return this.#options;
609
588
  }
610
- #resolveArgs(slotKey, args) {
611
- const host = this.#options.host;
612
- 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;
613
596
  const props = {};
614
597
  for (const key in args) {
598
+ if (regions && key in regions) continue;
615
599
  const value = args[key];
616
- if (isDataRef(value)) {
617
- const resolved = host ? host.resolve(value, this.#options.id) : undefined;
618
- let cache = this.#slotResolvedRefs.get(slotKey);
619
- if (!cache) this.#slotResolvedRefs.set(slotKey, cache = {});
620
- cache[key] = resolved;
621
- props[key] = resolved;
622
- } else if (isFrameRef(value)) {
623
- let entry = regions.get(key);
624
- if (!entry) {
625
- const element = makeFrameElement(value.$frame);
626
- entry = {
627
- childId: value.$frame,
628
- element,
629
- frame: undefined
630
- };
631
- regions.set(key, entry);
632
- } else if (entry.childId !== value.$frame) {
633
- renameRegion(entry, value.$frame);
634
- }
635
- props[key] = entry.element;
636
- } else {
637
- props[key] = host && host.revive ? host.revive(value) : value;
638
- }
600
+ props[key] = revive && !(decoded && key in decoded) ? revive(value, claiming) : value;
639
601
  }
602
+ if (regions) tierLoads.regions.r.resolve(this, slotKey, regions, props, claiming && start);
640
603
  return props;
641
604
  }
642
- #discoverRegions(slotKey, start) {
643
- if (!start) return;
644
- const regions = this.#regionsFor(slotKey);
645
- eachInRange(start, slotKey, n => collectRegionElements(n, regions));
646
- }
647
- #refArgsUnchanged(occurrence, record) {
648
- const old = this.#slotArgs.get(occurrence);
649
- if (!record || record.kind !== "slot") return false;
650
- if (old && old.kind !== "slot") return false;
651
- const a = old && old.args || {};
652
- const b = record.args || {};
653
- const ka = Object.keys(a);
654
- const kb = Object.keys(b);
655
- if (kb.length !== ka.length) return false;
656
- const cache = this.#slotResolvedRefs.get(occurrence);
657
- for (const key of ka) {
658
- const va = a[key];
659
- const vb = b[key];
660
- if (va === vb) continue;
661
- if (isFrameRef(va) && isFrameRef(vb)) continue;
662
- if (isDataRef(va) && isDataRef(vb) && cache && key in cache) {
663
- const host = this.#options.host;
664
- const next = host ? host.resolve(vb, this.#options.id) : undefined;
665
- if (host && host.isContainer && (host.isContainer(next) || host.isContainer(cache[key]))) {
666
- if (next === cache[key]) continue;
667
- return false;
668
- }
669
- if (isAsyncLike(next) || isAsyncLike(cache[key])) return false;
670
- try {
671
- if (JSON.stringify(next) === JSON.stringify(cache[key])) continue;
672
- } catch (e) {
673
- return false;
674
- }
675
- }
676
- return false;
677
- }
678
- return true;
605
+ #collectSlots(found, elements) {
606
+ collectSlots(this.#element.firstChild, null, found, elements);
679
607
  }
680
- #reconcileRegions(occurrence, record) {
681
- const args = record && record.args;
682
- if (!args) return;
683
- const regions = this.#slotRegions.get(occurrence);
684
- if (!regions) return;
685
- for (const key in args) {
686
- const value = args[key];
687
- if (!isFrameRef(value)) continue;
688
- const entry = regions.get(key);
689
- if (entry && entry.childId !== value.$frame) renameRegion(entry, value.$frame);
690
- }
691
- }
692
- #bindRegions(slotKey) {
693
- const regions = this.#slotRegions.get(slotKey);
694
- if (!regions) return;
695
- for (const entry of regions.values()) {
696
- if (!entry.frame) {
697
- entry.frame = new FrameImpl(entry.element, null, null, {
698
- id: entry.childId,
699
- host: this.#options.host,
700
- adopt: entry.adopt,
701
- claimScope: this.#options.claimScope ?? this.#options.id,
702
- ownerScope: this.#options.ownerScope,
703
- resolveSlot: prop => this.#resolveSlot(prop),
704
- resolveSlotRecord: occurrence => this.#resolveSlotRecord(occurrence),
705
- removeSlotRecord: occurrence => this.#removeSlotRecord(occurrence)
706
- });
707
- }
708
- }
709
- }
710
- #collectSlots(found) {
711
- collectSlots(this.#firstContent(), this.#end, found);
712
- }
713
- #findPlaceholder(name) {
714
- return findPlaceholder(this.#firstContent(), this.#end, placeholderId(name));
608
+ #findPlaceholder(name, root) {
609
+ return findPlaceholder((root || this.#element).firstChild, null, placeholderId(name));
715
610
  }
716
611
  contentHTML() {
717
- if (this.#disposed || !this.#element || !this.#hasContent) return null;
612
+ if (this.#disposed || !this.#hasContent) return null;
718
613
  return this.#element.innerHTML;
719
614
  }
720
615
  rebind(id) {
@@ -732,20 +627,11 @@ class FrameImpl {
732
627
  this.#element.setAttribute(FRAME_ID_ATTR, id);
733
628
  }
734
629
  this.#version = undefined;
735
- this.#appliedRootValue = undefined;
736
- this.#resetStreamState(true);
630
+ this.#resetStreamState();
737
631
  if (host) host.register(id, this);
738
632
  }
739
- rebase() {
740
- this.#version = undefined;
741
- }
742
- have() {
743
- return this.#have;
744
- }
745
633
  #recordHave(key, record) {
746
- if (!this.#have || !record || record.digest === undefined) return;
747
- this.#have[key] = record.digest;
748
- if (record.holes) Object.assign(this.#have, record.holes);
634
+ tierLoads.wire?.r?.have(this, key, record);
749
635
  }
750
636
  dispose() {
751
637
  if (this.#disposed) return;
@@ -755,36 +641,33 @@ class FrameImpl {
755
641
  } = this.#options;
756
642
  if (host && id !== undefined) host.unregister(id, this);
757
643
  this.#disposed = true;
758
- if (this.#recordRefresh) {
759
- clearTimeout(this.#recordRefresh);
760
- this.#recordRefresh = null;
761
- }
644
+ liveFrames.delete(this);
645
+ this.#releaseHold();
762
646
  for (const key of [...this.#slotCleanups.keys()]) this.#runSlotCleanups(key);
763
647
  for (const key of this.#mountedSlots) this.#removeSlotRecord(key);
764
- for (const regions of this.#slotRegions.values()) disposeRegions(regions);
765
- this.#slotRegions.clear();
648
+ tierLoads.regions?.r?.unmount(this);
766
649
  this.#mountedSlots.clear();
767
650
  }
768
651
  #applyRoot(html) {
769
652
  const fragment = parseFragment(html);
770
- const parent = this.#parent();
653
+ const parent = this.#element;
771
654
  if (!this.#hasContent) {
772
- this.#clearContent();
655
+ parent.textContent = "";
773
656
  this.#claimTree(fragment);
774
- parent.insertBefore(fragment, this.#end);
657
+ parent.appendChild(fragment);
775
658
  this.#hasContent = true;
776
659
  } else {
777
660
  const claim = this.#claimTree;
778
661
  const ranges = new Map();
779
662
  this.#collectSlots(ranges);
780
663
  const grafts = [];
781
- reconcileChildren(parent, fragment, this.#start, this.#end, claim, ranges, grafts);
664
+ reconcileChildren(parent, fragment, null, null, claim, ranges, grafts);
782
665
  if (ranges.size) for (const root of grafts) flushGrafts(root, ranges);
783
666
  }
784
667
  }
785
668
  #applyHole(marker, html) {
786
669
  if (!this.#hasContent) return false;
787
- 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);
788
671
  if (!open) return false;
789
672
  const close = rangeClose(open, "lh:/" + marker.slice(3));
790
673
  if (!close) {
@@ -795,15 +678,19 @@ class FrameImpl {
795
678
  }
796
679
  #applyAttrs(addr, text, removed) {
797
680
  if (!this.#hasContent) return false;
798
- 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);
799
682
  if (!el) return false;
800
683
  const parsed = parseFragment(`<i${text}></i>`).firstChild;
801
684
  const keepOpen = preservesOpen(el);
685
+ const owned = parsed ? ownedPositions(parsed) : null;
802
686
  const current = el.attributes;
803
687
  for (let i = current.length - 1; i >= 0; i--) {
804
688
  const name = current[i].name;
805
689
  if (name === "data-lha" || keepOpen && name === "open") continue;
806
- if (!parsed || !parsed.hasAttribute(name)) el.removeAttribute(name);
690
+ if (!parsed || !parsed.hasAttribute(name)) {
691
+ if (applyOwned(el, name, "", owned) !== undefined) continue;
692
+ el.removeAttribute(name);
693
+ }
807
694
  }
808
695
  if (parsed) {
809
696
  for (let i = 0; i < parsed.attributes.length; i++) {
@@ -812,72 +699,76 @@ class FrameImpl {
812
699
  value
813
700
  } = parsed.attributes[i];
814
701
  if (keepOpen && name === "open") continue;
702
+ if (applyOwned(el, name, value, owned) !== undefined) continue;
815
703
  if (el.getAttribute(name) !== value) el.setAttribute(name, value);
816
704
  }
817
705
  }
818
- if (removed) for (const name of removed) if (!(keepOpen && name === "open")) el.removeAttribute(name);
706
+ if (removed) for (const name of removed) {
707
+ if (keepOpen && name === "open") continue;
708
+ if (applyOwned(el, name, "", owned) !== undefined) continue;
709
+ el.removeAttribute(name);
710
+ }
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";
932
- }
933
- function isFrameRef(value) {
934
- return !!value && typeof value.$frame === "string";
818
+ function isCalled(occurrence) {
819
+ return occurrence.indexOf("#") !== -1;
935
820
  }
936
- function 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,7 +870,7 @@ function findPlaceholder(n, end, id) {
1060
870
  }
1061
871
  return null;
1062
872
  }
1063
- function collectSlots(n, end, out) {
873
+ function collectSlots(n, end, out, elements) {
1064
874
  while (n && n !== end) {
1065
875
  const id = slotStartId(n);
1066
876
  if (id !== null) {
@@ -1068,32 +878,19 @@ function collectSlots(n, end, out) {
1068
878
  n = afterRange(n, id);
1069
879
  continue;
1070
880
  }
1071
- if (n.nodeType === ELEMENT_NODE && !isFrameElement(n)) collectSlots(n.firstChild, null, out);
1072
- n = n.nextSibling;
1073
- }
1074
- }
1075
- function collectRegionElements(node, regions) {
1076
- if (node.nodeType !== ELEMENT_NODE) return;
1077
- if (isFrameElement(node)) {
1078
- const childId = node.getAttribute(FRAME_ID_ATTR);
1079
- if (childId && childId.includes(".")) {
1080
- const argKey = childId.slice(childId.lastIndexOf(".") + 1);
1081
- if (!regions.has(argKey)) {
1082
- regions.set(argKey, {
1083
- childId,
1084
- element: node,
1085
- frame: undefined,
1086
- adopt: true
1087
- });
881
+ if (elements !== undefined && isTextStart(n)) {
882
+ const B = tierLoads.bind?.r;
883
+ B ? B.text(n, elements) : elements.b = true;
884
+ }
885
+ if (n.nodeType === ELEMENT_NODE && !isFrameElement(n)) {
886
+ if (elements !== undefined && n.hasAttributes()) {
887
+ const B = tierLoads.bind?.r;
888
+ B ? B.positions(n, elements) : hasSlotMarker(n) && (elements.b = true);
1088
889
  }
890
+ collectSlots(n.firstChild, null, out, elements);
1089
891
  }
1090
- return;
892
+ n = n.nextSibling;
1091
893
  }
1092
- for (let c = node.firstChild; c; c = c.nextSibling) collectRegionElements(c, regions);
1093
- }
1094
- function renameRegion(entry, childId) {
1095
- entry.childId = childId;
1096
- if (entry.frame) entry.frame.rebind(childId);else entry.element.setAttribute(FRAME_ID_ATTR, childId);
1097
894
  }
1098
895
  function eachInRange(start, key, cb) {
1099
896
  const end = slotEnd(key);
@@ -1105,28 +902,6 @@ function eachInRange(start, key, cb) {
1105
902
  }
1106
903
  return n;
1107
904
  }
1108
- function clearStreamRecords(records, root) {
1109
- for (const key in records) {
1110
- if (/^(seg|hole|attr):/.test(key) || key === ":error" || root && key === "") {
1111
- delete records[key];
1112
- }
1113
- }
1114
- }
1115
- function argsEquivalent(a, b) {
1116
- if (a === b) return true;
1117
- if (!a || !b) return false;
1118
- const ka = Object.keys(a);
1119
- const kb = Object.keys(b);
1120
- if (ka.length !== kb.length) return false;
1121
- for (const key of ka) {
1122
- const va = a[key];
1123
- const vb = b[key];
1124
- if (va === vb) continue;
1125
- if (isFrameRef(va) && va.$frame === vb?.$frame) continue;
1126
- return false;
1127
- }
1128
- return true;
1129
- }
1130
905
  function slotStartId(node) {
1131
906
  if (node.nodeType !== COMMENT_NODE) return null;
1132
907
  const m = SLOT_START.exec(node.data);
@@ -1146,15 +921,26 @@ function preservesOpen(el) {
1146
921
  const t = el.tagName;
1147
922
  return t === "DETAILS" || t === "DIALOG";
1148
923
  }
924
+ const ownedPositions = el => {
925
+ const B = tierLoads.bind?.r;
926
+ return B ? B.owned(el) : null;
927
+ };
928
+ const applyOwned = (oldEl, name, value, owned) => owned === null ? undefined : tierLoads.bind.r.apply(oldEl, name, value, owned);
1149
929
  function morphAttributes(oldEl, newEl, claim) {
1150
930
  let reclaim = false;
1151
931
  let changed = false;
1152
932
  const keepOpen = preservesOpen(oldEl);
933
+ const owned = ownedPositions(newEl);
1153
934
  const oldAttrs = oldEl.attributes;
1154
935
  for (let i = oldAttrs.length - 1; i >= 0; i--) {
1155
936
  const name = oldAttrs[i].name;
1156
937
  if (keepOpen && name === "open") continue;
1157
938
  if (!newEl.hasAttribute(name)) {
939
+ const handled = applyOwned(oldEl, name, "", owned);
940
+ if (handled !== undefined) {
941
+ changed = handled || changed;
942
+ continue;
943
+ }
1158
944
  oldEl.removeAttribute(name);
1159
945
  changed = true;
1160
946
  reclaim ||= claimedAttr(name);
@@ -1163,11 +949,17 @@ function morphAttributes(oldEl, newEl, claim) {
1163
949
  const newAttrs = newEl.attributes;
1164
950
  for (let i = 0; i < newAttrs.length; i++) {
1165
951
  const attr = newAttrs[i];
1166
- if (keepOpen && attr.name === "open") continue;
1167
- if (oldEl.getAttribute(attr.name) !== attr.value) {
1168
- oldEl.setAttribute(attr.name, attr.value);
952
+ const name = attr.name;
953
+ if (keepOpen && name === "open") continue;
954
+ const handled = applyOwned(oldEl, name, attr.value, owned);
955
+ if (handled !== undefined) {
956
+ changed = handled || changed;
957
+ continue;
958
+ }
959
+ if (oldEl.getAttribute(name) !== attr.value) {
960
+ oldEl.setAttribute(name, attr.value);
1169
961
  changed = true;
1170
- reclaim ||= claimedAttr(attr.name);
962
+ reclaim ||= claimedAttr(name);
1171
963
  }
1172
964
  }
1173
965
  if (claim && (reclaim || changed && oldEl.matches(CLAIMED_ELEMENTS))) claim(oldEl, true);
@@ -1181,8 +973,9 @@ function morphNode(oldNode, newNode, claim, ranges, grafts) {
1181
973
  oldNode.data = newNode.data;
1182
974
  }
1183
975
  }
1184
- function afterRange(start, id) {
1185
- const end = slotEnd(id);
976
+ const afterRange = (start, id) => afterMarker(start, slotEnd(id));
977
+ const afterText = start => afterMarker(start, SLOT_TEXT_END);
978
+ function afterMarker(start, end) {
1186
979
  let n = start.nextSibling;
1187
980
  while (n) {
1188
981
  if (n.nodeType === COMMENT_NODE && n.data === end) return n.nextSibling;
@@ -1241,6 +1034,11 @@ function reconcileChildren(parent, source, boundStart = null, boundEnd = null, c
1241
1034
  const nextNew = newChild.nextSibling;
1242
1035
  const pid = slotStartId(newChild);
1243
1036
  const old = oldChild === boundEnd ? null : oldChild;
1037
+ if (old && isTextStart(newChild) && old.nodeType === COMMENT_NODE && old.data === newChild.data) {
1038
+ oldChild = afterText(old);
1039
+ newChild = afterText(newChild);
1040
+ continue;
1041
+ }
1244
1042
  if (pid !== null) {
1245
1043
  if (old && slotStartId(old) === pid) {
1246
1044
  oldChild = afterRange(old, pid);
@@ -1344,44 +1142,19 @@ function stashRange(frag, start, id) {
1344
1142
  }
1345
1143
 
1346
1144
  const FRAME_STREAM_HEADER = "X-Frame-Stream";
1347
- const FRAME_HAVE_HEADER = "X-Frame-Have";
1348
- const FRAME_HAVE_BUDGET = 4096;
1349
- function encodeHaveList(have) {
1350
- let out = "";
1351
- for (const key in have) {
1352
- const digest = have[key];
1353
- if (typeof digest !== "string") continue;
1354
- out += (out ? "," : "") + key + "=" + digest;
1355
- if (out.length > FRAME_HAVE_BUDGET) return undefined;
1356
- }
1357
- return out || undefined;
1358
- }
1145
+ const FRAME_TIERS_HEADER = "X-Frame-Tiers";
1359
1146
  function isFrameStreamResponse(response) {
1360
1147
  return response.headers.has(FRAME_STREAM_HEADER);
1361
1148
  }
1362
1149
  const applyFrameResponse = applyFrames;
1363
1150
  function applyFrames(response, host, options = {}, observation) {
1364
1151
  const rootId = response.headers.get(FRAME_STREAM_HEADER) ?? "";
1152
+ response.headers.get(FRAME_TIERS_HEADER)?.split(",").forEach(prepareTier);
1365
1153
  const as = options.as;
1366
1154
  const version = options.version;
1367
1155
  const perFrame = typeof version === "function" ? new Map() : null;
1368
- const wire = options[LIVE_WIRE];
1369
- const connection = wire && wire.connection;
1370
- const reader = wire && isEventStream(response) ? wire.open(response.body) : new ChunkReader(response.body);
1156
+ const reader = options[LIVE_WIRE] || new ChunkReader(response.body);
1371
1157
  const open = new Map();
1372
- let cancelled;
1373
- let resolveEnd;
1374
- if (connection) {
1375
- connection.ended = new Promise(resolve => resolveEnd = resolve);
1376
- connection.cancel = reason => {
1377
- if (cancelled !== undefined) return;
1378
- cancelled = reason;
1379
- try {
1380
- const r = reader.cancel && reader.cancel(reason);
1381
- if (r && typeof r.then === "function") r.then(undefined, () => {});
1382
- } catch {}
1383
- };
1384
- }
1385
1158
  const errorRecord = (id, error) => ({
1386
1159
  type: "error",
1387
1160
  id,
@@ -1405,26 +1178,15 @@ function applyFrames(response, host, options = {}, observation) {
1405
1178
  chunk.version = v;
1406
1179
  } else if (version !== undefined) chunk.version = version;
1407
1180
  if (chunk.type === "start") open.set(chunk.id, chunk.version);else if (chunk.type === "complete" || chunk.type === "error" && !chunk.key) open.delete(chunk.id);
1408
- if (chunk.type === "data" && host.prepareData) await host.prepareData();
1181
+ const needs = chunk.tiers?.map(prepareTier) || [];
1182
+ if (chunk.type === "data" || chunk.type === "slot" && Object.values(chunk.args).some(v => v && v.$ref)) await Promise.all([host.prepareData?.(), ...needs]);
1409
1183
  host.apply(chunk);
1410
1184
  }
1411
1185
  result = await reader.next();
1412
1186
  }
1413
1187
  };
1414
1188
  const end = error => {
1415
- const dead = error || cancelled || new Error("Frame stream ended before the frame completed.");
1416
- const sweep = () => {
1417
- for (const id of open.keys()) host.apply(errorRecord(id, dead));
1418
- };
1419
- if (connection) {
1420
- connection.done = true;
1421
- resolveEnd({
1422
- open: open.size,
1423
- error: dead,
1424
- sweep,
1425
- close: () => {}
1426
- });
1427
- } else if (error === undefined) sweep();
1189
+ if (error === undefined) for (const id of open.keys()) host.apply(errorRecord(id, new Error("Frame stream ended before the frame completed.")));
1428
1190
  };
1429
1191
  return drain().then(() => {
1430
1192
  end(undefined);
@@ -1437,7 +1199,19 @@ function applyFrames(response, host, options = {}, observation) {
1437
1199
  const SERVER_COMPONENT = /*#__PURE__*/Symbol.for("solid.server-component");
1438
1200
  const SERVER_COMPONENT_ADDRESS = /*#__PURE__*/Symbol.for("solid.server-component-address");
1439
1201
  const COMPONENT_BINDING = /*#__PURE__*/Symbol.for("solid.component-binding");
1202
+ const CONTENT_TOKEN = "\u0000";
1203
+ function contentAddress(token) {
1204
+ return token.split(CONTENT_TOKEN)[0];
1205
+ }
1206
+ const stagedContent = {
1207
+ preview() {},
1208
+ commit() {}
1209
+ };
1440
1210
  let resolveServerComponent;
1211
+ const calls = new Map();
1212
+ function callFor(address) {
1213
+ return calls.get(address);
1214
+ }
1441
1215
  function parseServerComponent(value, ctx) {
1442
1216
  return {
1443
1217
  id: ctx.parse(value[SERVER_COMPONENT]),
@@ -1483,7 +1257,6 @@ function flightCodec(codec) {
1483
1257
  function createServerComponentHandler({
1484
1258
  host,
1485
1259
  component,
1486
- onStream,
1487
1260
  intercept
1488
1261
  }) {
1489
1262
  const byFn = new Map();
@@ -1506,46 +1279,78 @@ function createServerComponentHandler({
1506
1279
  }
1507
1280
  return binding;
1508
1281
  };
1509
- resolveServerComponent = (id, address) => bindingFor(address, id);
1282
+ const staged = new Map();
1283
+ const latest = new Map();
1284
+ const stage = (address, base, version) => {
1285
+ if (!base) return undefined;
1286
+ let committed = false;
1287
+ const chunks = [];
1288
+ const token = address + CONTENT_TOKEN + version;
1289
+ const entry = {
1290
+ token,
1291
+ prepareData: host.prepareData,
1292
+ apply(chunk) {
1293
+ if (committed || chunk.type === "data") host.apply(chunk);else chunks.push(chunk);
1294
+ },
1295
+ preview() {
1296
+ if (host.preview) for (const chunk of chunks) host.preview(chunk);
1297
+ },
1298
+ commit() {
1299
+ committed = true;
1300
+ staged.delete(address);
1301
+ for (const chunk of chunks) host.apply(chunk);
1302
+ }
1303
+ };
1304
+ staged.set(address, entry);
1305
+ const comp = base[COMPONENT_BINDING].component;
1306
+ const binding = props => comp(props, () => token);
1307
+ binding[COMPONENT_BINDING] = {
1308
+ component: comp,
1309
+ address: token
1310
+ };
1311
+ latest.set(address, binding);
1312
+ return entry;
1313
+ };
1314
+ const settled = (address, binding) => latest.get(address) || binding;
1315
+ const showing = address => {
1316
+ const frame = host.get(address);
1317
+ return frame !== undefined && frame.error === undefined;
1318
+ };
1319
+ const named = (token, half) => {
1320
+ const entry = staged.get(contentAddress(token));
1321
+ if (entry && entry.token === token) entry[half]();
1322
+ };
1323
+ stagedContent.preview = token => named(token, "preview");
1324
+ stagedContent.commit = token => named(token, "commit");
1325
+ resolveServerComponent = (id, address) => settled(address, bindingFor(address, id));
1510
1326
  const versions = new Map();
1511
- const connections = new Map();
1512
1327
  const bump = address => {
1513
1328
  const version = (versions.get(address) || 0) + 1;
1514
1329
  versions.set(address, version);
1515
- const connection = connections.get(address);
1516
- if (connection) {
1517
- connections.delete(address);
1518
- connection.cancel(new Error("Superseded by a newer response for the address."));
1519
- }
1330
+ staged.delete(address);
1331
+ tierLoads.wire?.r?.cancel(host, address);
1520
1332
  return version;
1521
1333
  };
1522
- const hold = (address, connection) => {
1523
- connections.set(address, connection);
1524
- connection.ended.then(() => {
1525
- if (connections.get(address) === connection) connections.delete(address);
1526
- });
1527
- };
1334
+ const begin = (address, version) => host.apply({
1335
+ type: "start",
1336
+ id: address,
1337
+ version
1338
+ });
1528
1339
  return {
1529
1340
  intercept: intercept && (info => {
1530
1341
  const hit = intercept(info);
1531
1342
  if (hit === undefined) return undefined;
1532
- const binding = () => bindingFor(frameAddress(info.id, info.args), info.id);
1343
+ const address = frameAddress(info.id, info.args);
1344
+ if (!info.meta?.live) calls.set(address, info);
1345
+ const binding = () => bindingFor(address, info.id);
1533
1346
  if (typeof hit.then === "function") return hit.then(landed => landed ? binding() : undefined);
1534
1347
  return binding();
1535
1348
  }),
1349
+ onLive() {
1350
+ prepareTier("wire");
1351
+ },
1536
1352
  resume(info) {
1537
- const address = frameAddress(info.id, info.args);
1538
- const version = versions.get(address);
1539
- const frame = host.get(address);
1540
- const have = frame && frame.have ? frame.have() : undefined;
1541
- if (version === undefined && !have) return undefined;
1542
- const encoded = have && encodeHaveList(have);
1543
- return {
1544
- position: String(version || 0),
1545
- headers: encoded ? {
1546
- [FRAME_HAVE_HEADER]: encoded
1547
- } : undefined
1548
- };
1353
+ return tierLoads.wire?.r?.resume(host, info, versions);
1549
1354
  },
1550
1355
  handle(response, ctx) {
1551
1356
  if (!isFrameStreamResponse(response)) return undefined;
@@ -1555,31 +1360,16 @@ function createServerComponentHandler({
1555
1360
  return applyFlightResponse(response, address, binding);
1556
1361
  }
1557
1362
  const wire = ctx[LIVE_WIRE];
1558
- const connection = wire && wire.connection;
1559
- if (connection) {
1560
- const current = connections.get(address);
1561
- if (current && !current.done) {
1562
- connection.ended = current.ended;
1563
- const body = response.body;
1564
- if (body) body.cancel().catch(() => {});
1565
- return binding;
1566
- }
1567
- const version = bump(address);
1568
- if (onStream) onStream(address, version, response);
1569
- applyFrameResponse(response, host, {
1570
- as: address,
1571
- version,
1572
- [LIVE_WIRE]: wire
1573
- }).catch(() => {});
1574
- hold(address, connection);
1575
- return binding;
1576
- }
1363
+ if (wire) return prepareTier("wire").then(() => tierLoads.wire.r.connect(response, wire, address, binding, host, bump, begin));
1364
+ calls.set(address, ctx);
1577
1365
  const version = bump(address);
1578
- if (onStream) onStream(address, version, response);
1579
- applyFrameResponse(response, host, {
1366
+ const entry = showing(address) ? stage(address, binding, version) : undefined;
1367
+ if (!entry) begin(address, version);
1368
+ const target = entry || host;
1369
+ const applied = applyFrameResponse(response, target, {
1580
1370
  as: address,
1581
1371
  version
1582
- }).catch(err => host.apply({
1372
+ }).catch(err => target.apply({
1583
1373
  type: "error",
1584
1374
  id: address,
1585
1375
  version,
@@ -1587,17 +1377,10 @@ function createServerComponentHandler({
1587
1377
  message: String(err && err.message)
1588
1378
  }
1589
1379
  }));
1590
- return binding;
1380
+ return entry ? applied.then(() => settled(address, binding)) : binding;
1591
1381
  },
1592
1382
  showing(address, functionId) {
1593
1383
  bindingFor(address, functionId);
1594
- const comp = componentFor(functionId);
1595
- if (comp && (typeof comp === "function" || typeof comp === "object") && !comp[COMPONENT_BINDING]) {
1596
- comp[COMPONENT_BINDING] = {
1597
- component: comp,
1598
- address
1599
- };
1600
- }
1601
1384
  }
1602
1385
  };
1603
1386
  async function applyFlightResponse(response, address, binding) {
@@ -1611,11 +1394,26 @@ function createServerComponentHandler({
1611
1394
  });
1612
1395
  const payload = deserializeStream(new Response(source), flightCodec(getServerFunctionsCodec()));
1613
1396
  let carried = false;
1614
- await applyFrameResponse(response, host, {
1397
+ const regions = new Map();
1398
+ const regionOf = id => {
1399
+ for (const [root, entry] of regions) if (id === root || id.startsWith(root + ".")) return entry;
1400
+ };
1401
+ const target = {
1402
+ apply: chunk => {
1403
+ const entry = regionOf(chunk.id);
1404
+ if (entry) entry.apply(chunk);else host.apply(chunk);
1405
+ },
1406
+ prepareData: host.prepareData
1407
+ };
1408
+ await applyFrameResponse(response, target, {
1615
1409
  as,
1616
1410
  version: frameId => {
1617
1411
  const version = bump(frameId);
1618
- if (onStream) onStream(frameId, version, response);
1412
+ let entry = regionOf(frameId);
1413
+ if (!entry && showing(frameId)) {
1414
+ entry = stage(frameId, frameId === as ? binding : byAddress.get(frameId), version);
1415
+ if (entry) regions.set(frameId, entry);
1416
+ }
1619
1417
  return version;
1620
1418
  },
1621
1419
  onOutcome: text => {
@@ -1630,47 +1428,16 @@ function createServerComponentHandler({
1630
1428
  if (response.headers.has(ERROR_HEADER) && !hasFlightMetadata(response)) {
1631
1429
  throw envelope.value;
1632
1430
  }
1633
- return rootId ? binding : envelope.value;
1634
- }
1635
- }
1636
-
1637
- const STATE = Symbol.for("solid.container-trace-state");
1638
- const state = globalThis[STATE] || (globalThis[STATE] = {
1639
- materialized: new WeakMap(),
1640
- materializedValues: new WeakSet()
1641
- });
1642
- function setContainerTraceMaterializer(fn) {
1643
- state.materializeTrace = fn;
1644
- }
1645
- function materialize(marker) {
1646
- let value = state.materialized.get(marker.$tr);
1647
- if (value === undefined) {
1648
- value = state.materializeTrace(marker);
1649
- state.materialized.set(marker.$tr, value);
1650
- if (value !== null && typeof value === "object") state.materializedValues.add(value);
1431
+ return rootId ? settled(address, binding) : envelope.value;
1651
1432
  }
1652
- return value;
1653
- }
1654
- function isMaterializedContainer(value) {
1655
- return value !== null && typeof value === "object" && state.materializedValues.has(value);
1656
- }
1657
- function isContainerTraceMarker(value) {
1658
- if (value == null || typeof value !== "object" || value.$tr == null) return false;
1659
- const tr = value.$tr;
1660
- return tr.__SEROVAL_STREAM__ === true || typeof tr[Symbol.asyncIterator] === "function";
1661
- }
1662
- function reviveContainerTraces(value) {
1663
- if (!state.materializeTrace || value == null || typeof value !== "object") return value;
1664
- if (isContainerTraceMarker(value)) return materialize(value);
1665
- if (Array.isArray(value)) {
1666
- for (let i = 0; i < value.length; i++) value[i] = reviveContainerTraces(value[i]);
1667
- } else if (Object.getPrototypeOf(value) === Object.prototype) {
1668
- for (const key of Object.keys(value)) value[key] = reviveContainerTraces(value[key]);
1669
- }
1670
- return value;
1671
1433
  }
1672
1434
 
1673
- setContainerTraceMaterializer(materializeContainerTrace);
1435
+ const TRACE_STATE = Symbol.for("solid.container-trace-state");
1436
+ tierLoaders.trace = () => import('@solidjs/web/frames/trace');
1437
+ tierLoaders.regions = () => import('@solidjs/web/frames/regions');
1438
+ tierLoaders.assets = () => import('@solidjs/web/frames/assets');
1439
+ tierLoaders.bind = () => import('@solidjs/web/frames/bind');
1440
+ tierLoaders.wire = () => import('@solidjs/web/frames/wire');
1674
1441
  function asyncArg(value) {
1675
1442
  return value;
1676
1443
  }
@@ -1683,117 +1450,119 @@ function loadCodec() {
1683
1450
  });
1684
1451
  }
1685
1452
  const tables = new Map();
1686
- function ensureTable(root) {
1687
- let table = tables.get(root);
1688
- if (!table && codec) tables.set(root, table = codec.createJSONDataTable());
1689
- return table;
1453
+ function tableFor(id, version, current) {
1454
+ let byVersion = tables.get(id);
1455
+ if (!byVersion) tables.set(id, byVersion = new Map());else for (const v of byVersion.keys()) if (v < current) byVersion.delete(v);
1456
+ let t = byVersion.get(version);
1457
+ if (!t && codec) byVersion.set(version, t = codec.createJSONDataTable());
1458
+ return t;
1459
+ }
1460
+ function followAddress(host, frame, binding) {
1461
+ createRenderEffect(() => {
1462
+ const token = binding();
1463
+ stagedContent.preview(token);
1464
+ return token;
1465
+ }, token => {
1466
+ stagedContent.commit(token);
1467
+ frame.rebind(contentAddress(token));
1468
+ });
1469
+ }
1470
+ function landing(host, address, value, failed) {
1471
+ let thrown = host.get(address)?.error;
1472
+ return createMemo(() => {
1473
+ failed();
1474
+ const error = host.get(address)?.error;
1475
+ if (error !== undefined && error !== thrown) {
1476
+ thrown = error;
1477
+ throw error;
1478
+ }
1479
+ const wait = host.landing(address);
1480
+ if (!wait) return value;
1481
+ const asked = error !== undefined ? reask(address) : undefined;
1482
+ return (asked ? asked.then(() => wait) : wait).then(() => value);
1483
+ });
1690
1484
  }
1691
- function tableFor(id) {
1692
- if (tables.has(id)) return ensureTable(id);
1693
- for (const root of tables.keys()) if (id.startsWith(root + ".")) return ensureTable(root);
1694
- return undefined;
1485
+ function reask(address) {
1486
+ const call = callFor(address);
1487
+ return call && call.retry();
1695
1488
  }
1696
- function beginStream(frameId) {
1697
- tables.set(frameId, undefined);
1489
+ function failing() {
1490
+ const [failed, setFailed] = createSignal(0, {
1491
+ ownedWrite: true
1492
+ });
1493
+ return [failed, info => info.reason === "error" && setFailed(n => n + 1)];
1698
1494
  }
1699
1495
  function getFrameHost() {
1700
1496
  if (!sharedHost) {
1701
1497
  sharedHost = createFrameHost({
1702
1498
  prepareData: loadCodec,
1703
- applyData: c => tableFor(c.id)?.apply(c),
1704
- resolve: (ref, id) => tableFor(id)?.resolve(ref),
1705
- revive: reviveContainerTraces,
1706
- isContainer: isMaterializedContainer,
1707
- delegate: delegateEvents
1499
+ applyData: (c, current) => tableFor(c.id, c.version, current)?.apply(c),
1500
+ resolve: (ref, id, version, current) => tableFor(id, version, current)?.resolve(ref),
1501
+ closeData: (id, version, error) => tables.get(id)?.get(version)?.close(error)
1708
1502
  });
1709
1503
  }
1710
1504
  return sharedHost;
1711
1505
  }
1712
- function normalizeSlotContent(value) {
1713
- while (typeof value === "function") value = value();
1714
- if (Array.isArray(value)) {
1715
- const out = [];
1716
- for (const v of value) {
1717
- const n = normalizeSlotContent(v);
1718
- Array.isArray(n) ? out.push(...n) : out.push(n);
1719
- }
1720
- return out;
1721
- }
1722
- if (value == null || typeof value === "boolean") return document.createTextNode("");
1723
- return value instanceof Node ? value : document.createTextNode(String(value));
1724
- }
1725
- function gatherClaims(el, registry) {
1726
- if (el.hasAttribute("_hk")) registry.set(el.getAttribute("_hk"), el);
1727
- if (el.hasAttribute(FRAME_ID_ATTR)) return;
1728
- for (let c = el.firstElementChild; c; c = c.nextElementSibling) gatherClaims(c, registry);
1729
- }
1730
- function hasPendingFragment(existing) {
1731
- for (const n of existing) {
1732
- if (n.nodeType !== 1) continue;
1733
- const el = n;
1734
- if (el.tagName === "TEMPLATE" && el.id.startsWith("pl-")) return true;
1735
- if (el.querySelector?.('template[id^="pl-"]')) return true;
1736
- }
1737
- return false;
1738
- }
1739
- function claimRender(prefix, existing, render) {
1506
+ function claimRender(prefix, existing, render, scope, bound) {
1740
1507
  const sc = sharedConfig;
1741
- if (!sc.getNextContextId) return render();
1742
- const registry = new Map();
1743
- for (const n of existing) {
1744
- if (n.nodeType !== 1) continue;
1745
- gatherClaims(n, registry);
1746
- }
1747
- if (!registry.size && !hasPendingFragment(existing)) return render();
1748
- const prevRegistry = sc.registry;
1749
- const prevHydrating = sc.hydrating;
1750
- const prevClaimRoots = sc.claimRoots;
1751
- if (prevRegistry) for (const key of registry.keys()) prevRegistry.delete(key);
1752
- sc.registry = registry;
1753
- sc.hydrating = true;
1508
+ if (!sc.hydrateWindow || !sc.registry) return render();
1509
+ const prevRoots = sc.claimRoots;
1754
1510
  sc.claimRoots = existing;
1755
1511
  try {
1756
1512
  return runWithOwner(createOwner({
1757
1513
  id: prefix
1758
- }), render);
1514
+ }), () => sc.hydrateWindow(bound ? undefined : prefix, render, scope));
1759
1515
  } finally {
1760
- sc.registry = prevRegistry;
1761
- sc.hydrating = prevHydrating;
1762
- sc.claimRoots = prevClaimRoots;
1516
+ sc.claimRoots = prevRoots;
1763
1517
  }
1764
1518
  }
1765
1519
  function liveSlotProps(initial, ctx) {
1766
- const [args, setArgs] = createSignal(initial);
1520
+ const [args, setArgs] = createSignal(initial, {
1521
+ ownedWrite: true
1522
+ });
1767
1523
  ctx.onUpdate(next => setArgs(() => next));
1768
1524
  return slotArgsProxy(args);
1769
1525
  }
1770
- function isAsyncValue(v) {
1771
- return v !== null && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
1526
+ function sameArg(a, b) {
1527
+ if (a === b) return true;
1528
+ if (!a || !b || typeof a !== "object" || typeof b !== "object") return false;
1529
+ if (a instanceof Boxed || b instanceof Boxed) return a instanceof Boxed && b instanceof Boxed && a.c === b.c;
1530
+ if (isAsyncValue(a) || isAsyncValue(b) || a instanceof Node || b instanceof Node) return false;
1531
+ try {
1532
+ return JSON.stringify(a) === JSON.stringify(b);
1533
+ } catch {
1534
+ return false;
1535
+ }
1536
+ }
1537
+ class Boxed {
1538
+ constructor(c) {
1539
+ this.c = c;
1540
+ }
1772
1541
  }
1773
1542
  function slotArgsProxy(args) {
1774
1543
  const owner = getOwner();
1775
- const asyncReads = new Map();
1544
+ const reads = new Map();
1776
1545
  return new Proxy({}, {
1777
1546
  get: (_, key) => {
1778
- const v = args()[key];
1779
- if (isMaterializedContainer(v)) return v;
1780
- if (!isAsyncValue(v)) return v;
1781
- let read = asyncReads.get(key);
1547
+ let read = reads.get(key);
1782
1548
  if (!read) {
1783
1549
  const make = () => createMemo(() => {
1784
1550
  const raw = args()[key];
1551
+ if (globalThis[TRACE_STATE]?.materializedValues.has(raw)) return new Boxed(raw);
1785
1552
  if (raw != null && typeof raw.then === "function") {
1786
1553
  if (raw.s === 1) return raw.v;
1787
1554
  if (raw.s === 2) throw raw.v;
1788
1555
  }
1789
1556
  return raw;
1790
1557
  }, {
1791
- transparent: true
1558
+ transparent: true,
1559
+ equals: sameArg
1792
1560
  });
1793
1561
  read = owner ? runWithOwner(owner, make) : make();
1794
- asyncReads.set(key, read);
1562
+ reads.set(key, read);
1795
1563
  }
1796
- return read();
1564
+ const v = read();
1565
+ return v instanceof Boxed ? v.c : v;
1797
1566
  },
1798
1567
  has: (_, key) => key in args(),
1799
1568
  ownKeys: () => Reflect.ownKeys(args()),
@@ -1803,31 +1572,37 @@ function slotArgsProxy(args) {
1803
1572
  } : undefined
1804
1573
  });
1805
1574
  }
1806
- function isReactiveContent(value) {
1807
- if (typeof value === "function") return true;
1808
- if (Array.isArray(value)) {
1809
- for (const v of value) if (isReactiveContent(v)) return true;
1810
- }
1811
- return false;
1812
- }
1813
- function slotsFor(props) {
1814
- const bindings = new Map();
1575
+ function slotsFor(props, scope) {
1815
1576
  const fillScopes = new Map();
1816
1577
  return new Proxy({}, {
1817
1578
  get(_, prop) {
1818
1579
  if (typeof prop !== "string" || !(prop in props)) return undefined;
1819
1580
  return (slotProps, ctx) => {
1820
1581
  const key = ctx && ctx.key;
1821
- const prev = key !== undefined && bindings.get(key);
1822
- if (prev) {
1823
- bindings.delete(key);
1824
- prev.dispose();
1825
- }
1826
1582
  const prevFill = key !== undefined && fillScopes.get(key);
1827
1583
  if (prevFill) {
1828
1584
  fillScopes.delete(key);
1829
1585
  prevFill.dispose();
1830
1586
  }
1587
+ if (ctx && ctx.positions) {
1588
+ const fill = props[prop];
1589
+ if (typeof fill !== "function") {
1590
+ return undefined;
1591
+ }
1592
+ const owner = createOwner();
1593
+ fillScopes.set(key, owner);
1594
+ ctx.onCleanup(() => {
1595
+ if (fillScopes.get(key) === owner) fillScopes.delete(key);
1596
+ owner.dispose();
1597
+ });
1598
+ runWithOwner(owner, () => {
1599
+ const args = ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotArgsProxy(() => slotProps);
1600
+ tierLoads.bind.r.bind(fill, args, ctx, undefined);
1601
+ });
1602
+ return undefined;
1603
+ }
1604
+ const range = ctx && ctx.range;
1605
+ if (!range) return undefined;
1831
1606
  const fillOwner = streamInvoke ? createOwner() : null;
1832
1607
  if (fillOwner && key !== undefined && ctx) {
1833
1608
  fillScopes.set(key, fillOwner);
@@ -1836,42 +1611,31 @@ function slotsFor(props) {
1836
1611
  fillOwner.dispose();
1837
1612
  });
1838
1613
  }
1839
- const settle = out => {
1840
- const existing = ctx && ctx.existing || [];
1841
- if (existing.length) {
1842
- const list = Array.isArray(out) ? out : [out];
1843
- const inPlace = list.every(n => existing.some(e => e === n || e.nodeType === 1 && e.contains(n)));
1844
- if (inPlace) return undefined;
1845
- }
1846
- return out;
1847
- };
1848
1614
  const evaluate = () => {
1849
1615
  const v = props[prop];
1850
1616
  if (typeof v === "function" && ctx && ctx.invoked) {
1851
- return v(ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotArgsProxy(() => slotProps));
1617
+ const fillProps = ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotArgsProxy(() => slotProps);
1618
+ return untrack(() => v(fillProps), undefined);
1852
1619
  }
1853
1620
  return v;
1854
1621
  };
1855
1622
  const adopted = !!(ctx && ctx.frame && ctx.adopted && ctx.existing && ctx.existing.length);
1856
1623
  const prefix = ctx && ctx.frame ? `sc-${ctx.frame}-${ctx.key}-` : "";
1857
- const value = fillOwner ? runWithOwner(fillOwner, () => adopted ? claimRender(prefix, ctx.existing, evaluate) : evaluate()) : adopted ? claimRender(prefix, ctx.existing, evaluate) : evaluate();
1858
- if (!isReactiveContent(value)) {
1859
- return settle(normalizeSlotContent(value));
1860
- }
1861
- if (ctx && ctx.range) {
1862
- const source = value;
1863
- const owner = createOwner();
1864
- bindings.set(key, owner);
1624
+ const value = fillOwner ? runWithOwner(fillOwner, () => adopted ? claimRender(prefix, ctx.existing, evaluate, scope) : evaluate()) : adopted ? claimRender(prefix, ctx.existing, evaluate, scope) : evaluate();
1625
+ const owner = fillOwner || createOwner({
1626
+ transparent: true
1627
+ });
1628
+ if (!fillOwner) {
1629
+ fillScopes.set(key, owner);
1865
1630
  ctx.onCleanup(() => {
1866
- if (bindings.get(key) === owner) bindings.delete(key);
1631
+ if (fillScopes.get(key) === owner) fillScopes.delete(key);
1867
1632
  owner.dispose();
1868
1633
  });
1869
- const end = ctx.range.end;
1870
- const bind = () => insert(end.parentNode, () => typeof source === "function" ? source() : source, end, [...ctx.existing]);
1871
- runWithOwner(owner, () => adopted ? claimRender(prefix, ctx.existing, bind) : bind());
1872
- return undefined;
1873
1634
  }
1874
- return settle(normalizeSlotContent(value));
1635
+ const end = range.end;
1636
+ const bind = () => insert(end.parentNode, value, end, [...ctx.existing]);
1637
+ runWithOwner(owner, () => adopted ? claimRender(prefix, ctx.existing, bind, scope, true) : bind());
1638
+ return undefined;
1875
1639
  };
1876
1640
  }
1877
1641
  });
@@ -1894,12 +1658,8 @@ function boundaryScope(owner) {
1894
1658
  function boundaryComponent(host, fnId) {
1895
1659
  return (props, binding) => {
1896
1660
  const owner = getOwner();
1897
- const id = binding ? binding() : fnId;
1898
- let applied = !tables.has(id);
1899
- let release;
1900
- const arm = () => new Promise(r => release = r);
1901
- const mountGate = applied ? undefined : arm();
1902
- let setGate;
1661
+ const id = binding ? contentAddress(binding()) : fnId;
1662
+ const [failed, onApply] = failing();
1903
1663
  const {
1904
1664
  element,
1905
1665
  frame,
@@ -1908,33 +1668,14 @@ function boundaryComponent(host, fnId) {
1908
1668
  host,
1909
1669
  id,
1910
1670
  slots: slotsFor(props),
1911
- props,
1912
1671
  ownerScope: boundaryScope(owner),
1913
1672
  reveal: revealSeam(owner),
1914
- onApply: () => {
1915
- applied = true;
1916
- if (release) {
1917
- release();
1918
- release = undefined;
1919
- }
1920
- setGate && setGate(undefined);
1921
- }
1673
+ onApply
1922
1674
  });
1923
- const [gatePromise, setGatePromise] = createSignal(applied ? undefined : mountGate);
1924
- setGate = setGatePromise;
1925
- if (binding) {
1926
- createRenderEffect(binding, (address, prev) => {
1927
- if (prev !== undefined && address !== prev && tables.has(address)) {
1928
- applied = false;
1929
- setGatePromise(arm());
1930
- }
1931
- frame.rebind(address);
1932
- });
1933
- }
1934
1675
  onCleanup(dispose);
1935
- if (applied && !binding) return element;
1936
- const gate = createMemo(() => gatePromise());
1937
- return createMemo(() => (gate(), element));
1676
+ if (!binding) return landing(host, id, element, failed);
1677
+ followAddress(host, frame, binding);
1678
+ return createMemo(() => landing(host, contentAddress(binding()), element, failed));
1938
1679
  };
1939
1680
  }
1940
1681
  const claimedBoundaries = new Set();
@@ -1949,7 +1690,7 @@ function pumpLiveChannel() {
1949
1690
  const pump = () => reader.read().then(r => {
1950
1691
  if (r.done) return;
1951
1692
  const op = r.value;
1952
- liveOps.set(`${op.type}:${op.fid || ""}:${op.key || ""}`, op);
1693
+ for (const m of op.type === "ops" ? op.ops : [op]) liveOps.set(`${m.type}:${m.fid || ""}:${m.key || ""}`, m);
1953
1694
  for (const apply of liveAppliers) apply(op);
1954
1695
  return pump();
1955
1696
  });
@@ -1959,7 +1700,7 @@ function pumpLiveChannel() {
1959
1700
  let boundaryIndex = null;
1960
1701
  const isBoundaryId = id => !id.includes(".");
1961
1702
  function indexBoundaries(root) {
1962
- root.querySelectorAll(`[${FRAME_ID_ATTR}]`).forEach(el => {
1703
+ root.querySelectorAll(FRAME_SELECTOR).forEach(el => {
1963
1704
  const key = el.getAttribute(FRAME_ID_ATTR);
1964
1705
  if (key && isBoundaryId(key) && !boundaryIndex.has(key)) boundaryIndex.set(key, el);
1965
1706
  });
@@ -1971,8 +1712,9 @@ function findBoundaryElement(id) {
1971
1712
  }
1972
1713
  return boundaryIndex.get(id);
1973
1714
  }
1974
- const boundaryWaiters = new Map();
1975
1715
  const arrivals = new Map();
1716
+ const FRAME_SELECTOR = `[${FRAME_ID_ATTR}]`;
1717
+ const disposedFrames = new WeakSet();
1976
1718
  function awaitBoundary(id) {
1977
1719
  let arrival = arrivals.get(id);
1978
1720
  if (!arrival) {
@@ -1994,18 +1736,16 @@ function installRevealHook() {
1994
1736
  const hy = globalThis._$HY;
1995
1737
  if (!hy || hy.$sc || !hy.fr) return;
1996
1738
  hy.$sc = true;
1739
+ hy.fa = pl => {
1740
+ const el = pl.closest(FRAME_SELECTOR);
1741
+ return !!el && !disposedFrames.has(el);
1742
+ };
1997
1743
  hy.fr.subscribe((_id, parent) => {
1998
1744
  if (!boundaryIndex) return;
1999
1745
  const root = parent || (typeof document !== "undefined" ? document.body : null);
2000
1746
  if (root) indexBoundaries(root);
2001
- if (!boundaryWaiters.size && !arrivals.size) return;
1747
+ if (!arrivals.size) return;
2002
1748
  const exhausted = hy.done && !hy.fr.pending();
2003
- for (const [id, notify] of boundaryWaiters) {
2004
- const el = boundaryIndex && boundaryIndex.get(id);
2005
- if (!el && !exhausted) continue;
2006
- boundaryWaiters.delete(id);
2007
- notify(el);
2008
- }
2009
1749
  for (const [id, arrival] of arrivals) {
2010
1750
  const el = boundaryIndex && boundaryIndex.get(id);
2011
1751
  if (!el && !exhausted) continue;
@@ -2019,37 +1759,21 @@ function documentBoundary(host, id, props, binding) {
2019
1759
  const claimed = claimedBoundaries.has(id);
2020
1760
  const el = !claimed ? findBoundaryElement(id) : undefined;
2021
1761
  if (el) return adoptBoundary(host, id, el, props, binding);
2022
- if (!claimed && !boundaryWaiters.has(id) && boundaryMayArrive()) {
1762
+ if (!claimed && boundaryMayArrive()) {
2023
1763
  const owner = getOwner();
2024
- const arrival = new Promise(resolve => boundaryWaiters.set(id, resolve));
2025
- onCleanup(() => boundaryWaiters.delete(id));
2026
- return createMemo(() => arrival.then(node => runWithOwner(owner, () =>
2027
- node ? adoptBoundary(host, id, node, props, binding) : boundaryComponent(host, id)(props, binding))));
1764
+ let live = true;
1765
+ onCleanup(() => live = false);
1766
+ return createMemo(() => awaitBoundary(id).then(() => live && runWithOwner(owner, () => {
1767
+ const node = claimedBoundaries.has(id) ? undefined : findBoundaryElement(id);
1768
+ return node ? adoptBoundary(host, id, node, props, binding) : boundaryComponent(host, id)(props, binding);
1769
+ })));
2028
1770
  }
2029
1771
  return boundaryComponent(host, id)(props, binding);
2030
1772
  }
2031
- function documentAddress(id) {
2032
- const records = globalThis._$SC?.a;
2033
- if (records) {
2034
- for (const address in records) if (records[address] === id) return address;
2035
- }
2036
- return id;
2037
- }
2038
1773
  function adoptBoundary(host, id, el, props, binding) {
2039
1774
  claimedBoundaries.add(id);
2040
- const address = binding ? binding() : documentAddress(id);
1775
+ const address = binding ? contentAddress(binding()) : id;
2041
1776
  const appliedRecords = new Set();
2042
- const claimedFragments = new Set();
2043
- const claimRegionFragments = root => {
2044
- const fr = globalThis._$HY?.fr;
2045
- if (!fr || !fr.claim) return;
2046
- root.querySelectorAll('template[id^="pl-"]').forEach(tpl => {
2047
- const fragId = tpl.id.slice(3);
2048
- if (claimedFragments.has(fragId)) return;
2049
- claimedFragments.add(fragId);
2050
- fr.claim(fragId);
2051
- });
2052
- };
2053
1777
  const drainRecords = () => {
2054
1778
  const hy = globalThis._$HY;
2055
1779
  if (!hy || !hy.r) return;
@@ -2059,13 +1783,17 @@ function adoptBoundary(host, id, el, props, binding) {
2059
1783
  if (appliedRecords.has(key)) continue;
2060
1784
  if (key.startsWith(slotPrefix)) {
2061
1785
  appliedRecords.add(key);
2062
- host.apply({
1786
+ const apply = args => host.apply({
2063
1787
  type: "slot",
2064
1788
  id: address,
2065
1789
  version: 0,
2066
1790
  key: key.slice(slotPrefix.length),
2067
- args: hy.r[key]
1791
+ args
2068
1792
  });
1793
+ const value = hy.r[key];
1794
+ if (value && typeof value.then === "function") {
1795
+ if (value.s === 1) apply(value.v);else if (value.s === 2) value.then(undefined, () => {});else value.then(apply, () => {});
1796
+ } else apply(value);
2069
1797
  } else if (key.startsWith("sc:region:")) {
2070
1798
  const childId = key.slice("sc:region:".length);
2071
1799
  if (childId.startsWith(id + ".")) {
@@ -2082,14 +1810,18 @@ function adoptBoundary(host, id, el, props, binding) {
2082
1810
  }
2083
1811
  }
2084
1812
  };
2085
- claimRegionFragments(el);
2086
1813
  const fr = globalThis._$HY?.fr;
1814
+ let frame;
2087
1815
  const unsubscribe = fr ? fr.subscribe((_fragId, parent) => {
2088
- if (fr.claim && parent && el.contains(parent)) claimRegionFragments(parent);
1816
+ const inside = !!parent && el.contains(parent);
2089
1817
  drainRecords();
1818
+ if (inside && frame) frame.apply({
1819
+ version: frame.version ?? 0,
1820
+ r: {}
1821
+ });
2090
1822
  }) : undefined;
2091
1823
  const applyLiveOp = op => {
2092
- if (op.type === "slot" && op.fid !== id) return;
1824
+ if (op.fid && op.fid !== id) return;
2093
1825
  host.apply({
2094
1826
  ...op,
2095
1827
  id: address,
@@ -2100,56 +1832,44 @@ function adoptBoundary(host, id, el, props, binding) {
2100
1832
  onCleanup(() => {
2101
1833
  liveAppliers.delete(applyLiveOp);
2102
1834
  unsubscribe && unsubscribe();
2103
- if (fr && fr.release) for (const fragId of claimedFragments) fr.release(fragId);
2104
1835
  });
2105
1836
  drainRecords();
2106
1837
  for (const op of liveOps.values()) applyLiveOp(op);
2107
1838
  const owner = getOwner();
2108
- let release;
2109
- let setGate;
2110
- const frame = createFrame(el, {
1839
+ const sc = sharedConfig;
1840
+ const [failed, onApply] = failing();
1841
+ frame = createFrame(el, {
2111
1842
  adopt: true,
2112
1843
  host,
2113
1844
  id: address,
2114
- slots: slotsFor(props),
2115
- props,
1845
+ slots: slotsFor(props, {
1846
+ registry: sc.registry,
1847
+ gather: sc.gather
1848
+ }),
2116
1849
  ownerScope: boundaryScope(owner),
2117
1850
  reveal: revealSeam(owner),
2118
- onApply: () => {
2119
- if (release) {
2120
- release();
2121
- release = undefined;
2122
- }
2123
- setGate && setGate(undefined);
2124
- },
1851
+ onApply,
1852
+ hold: () => sc.isHydrationInProgress?.() ? runWithOwner(owner, () => untrack(() => sc.holdBoundary("sc:" + id))) : () => {},
2125
1853
  ...{
2126
- recordsPending: () => {
2127
- if (document.readyState === "loading") return true;
2128
- const hy = globalThis._$HY;
2129
- return !!(hy && hy.fr && hy.fr.pending());
2130
- },
2131
- drainRecords,
2132
1854
  claimScope: id
2133
1855
  }
2134
1856
  });
2135
1857
  if (binding) {
2136
- const arm = () => new Promise(r => release = r);
2137
- const [gatePromise, setGatePromise] = createSignal(undefined);
2138
- setGate = setGatePromise;
2139
- const gate = createMemo(() => gatePromise());
2140
- createRenderEffect(binding, (address, prev) => {
2141
- if (prev !== undefined && address !== prev && tables.has(address)) {
2142
- setGatePromise(arm());
2143
- }
2144
- frame.rebind(address);
2145
- });
2146
- createRenderEffect(() => (gate(), undefined), () => {});
1858
+ followAddress(host, frame, binding);
1859
+ const source = createMemo(() => landing(host, contentAddress(binding()), true, failed));
1860
+ createRenderEffect(() => source()(), () => {});
2147
1861
  }
2148
- onCleanup(() => frame.dispose());
1862
+ onCleanup(() => {
1863
+ frame.dispose();
1864
+ disposedFrames.add(el);
1865
+ el.querySelectorAll(FRAME_SELECTOR).forEach(e => disposedFrames.add(e));
1866
+ });
2149
1867
  return el;
2150
1868
  }
2151
- function installServerComponents(host = getFrameHost()) {
1869
+ function installServerComponents(host = getFrameHost(), options) {
2152
1870
  const g = globalThis;
1871
+ Object.assign(tierLoaders, options?.tiers);
1872
+ g._$HY?.r?.["sc:tiers"]?.forEach(prepareTier);
2153
1873
  if (!g._$SC) {
2154
1874
  g._$SC = {
2155
1875
  c: {},
@@ -2174,7 +1894,6 @@ function installServerComponents(host = getFrameHost()) {
2174
1894
  const handler = createServerComponentHandler({
2175
1895
  host,
2176
1896
  component: fnId => g._$SC.r(fnId),
2177
- onStream: address => beginStream(address),
2178
1897
  intercept: ({
2179
1898
  id
2180
1899
  }) => {
@@ -2194,4 +1913,4 @@ function installServerComponents(host = getFrameHost()) {
2194
1913
  });
2195
1914
  }
2196
1915
 
2197
- export { FRAME_APPLIED_EVENT, FRAME_HAVE_BUDGET, FRAME_HAVE_HEADER, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents, isFrameStreamResponse };
1916
+ export { FRAME_APPLIED_EVENT, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents, isAsyncValue, isFrameStreamResponse };