@solidjs/web 2.0.0-rc.15 → 2.0.0-rc.16

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 (53) hide show
  1. package/README.md +1 -1
  2. package/dist/server.dev.js +358 -479
  3. package/dist/server.js +343 -387
  4. package/dist/server.observe.js +343 -387
  5. package/dist/web.dev.js +57 -54
  6. package/dist/web.js +47 -49
  7. package/dist/web.observe.js +57 -54
  8. package/frames/dist/client.dev.js +610 -621
  9. package/frames/dist/client.js +540 -566
  10. package/frames/dist/client.observe.js +571 -573
  11. package/frames/dist/regions.js +43 -2
  12. package/frames/dist/server.dev.js +514 -423
  13. package/frames/dist/server.js +514 -370
  14. package/frames/dist/server.observe.js +514 -370
  15. package/frames/dist/wire.js +371 -6
  16. package/package.json +11 -11
  17. package/serialization/dist/decode.js +9 -7
  18. package/serialization/dist/serialization.js +9 -7
  19. package/serialization/types/serializer-decode.d.ts +2 -2
  20. package/server-functions/dist/client.dev.js +3 -1
  21. package/server-functions/dist/client.js +1 -1
  22. package/server-functions/dist/client.observe.js +3 -1
  23. package/server-functions/dist/rich-args.js +33 -1
  24. package/server-functions/dist/server.dev.js +127 -18
  25. package/server-functions/dist/server.js +127 -18
  26. package/server-functions/dist/server.observe.js +127 -18
  27. package/skills/server-components/SKILL.md +74 -185
  28. package/types/client.d.ts +15 -5
  29. package/types/frames/assets-tier.d.ts +2 -2
  30. package/types/frames/client.d.ts +8 -3
  31. package/types/frames/frame-client.d.ts +121 -157
  32. package/types/frames/frame-morph.d.ts +28 -0
  33. package/types/frames/frame-sink.d.ts +13 -9
  34. package/types/frames/frame-transport.d.ts +30 -1
  35. package/types/frames/regions-tier.d.ts +15 -0
  36. package/types/frames/serializer-decode.d.ts +2 -2
  37. package/types/frames/server.d.ts +0 -52
  38. package/types/frames/wire-tier.d.ts +54 -1
  39. package/types/index.d.ts +2 -2
  40. package/types/jsx.d.ts +11 -5
  41. package/types/observe.d.ts +14 -7
  42. package/types/render.d.ts +3 -1
  43. package/types/response.d.ts +5 -4
  44. package/types/serializer-decode.d.ts +2 -2
  45. package/types/server-functions/argument-codec.d.ts +21 -0
  46. package/types/server-functions/client.d.ts +14 -5
  47. package/types/server-functions/server.d.ts +6 -2
  48. package/types/server-functions/shared.d.ts +19 -0
  49. package/types/server-observe.d.ts +3 -2
  50. package/types/server.d.ts +57 -76
  51. package/frames/dist/bind.dev.js +0 -326
  52. package/frames/dist/bind.js +0 -295
  53. package/types/frames/bind-tier.d.ts +0 -60
@@ -1,10 +1,9 @@
1
1
  import * as core from 'solid-js';
2
- import { getOwner, onCleanup, createMemo, runWithOwner, untrack, createRenderEffect, createSignal, createOwner } from 'solid-js';
2
+ import { OBSERVE, getOwner, onCleanup, createMemo, runWithOwner, untrack, createRenderEffect, onHydrationEnd, createSignal, createOwner } from 'solid-js';
3
3
  import { installServerComponentHydration, insert } from '@solidjs/web';
4
4
  import { frameAddress, SINGLE_FLIGHT_HEADER, LIVE_WIRE, deserializeStream, getServerFunctionsCodec, createChunk, deliverFlightData, ERROR_HEADER, hasFlightMetadata, ChunkReader, configureServerFunctionsClient } from '@solidjs/web/server-functions/client';
5
5
 
6
6
  const ELEMENT_NODE = 1;
7
- const TEXT_NODE = 3;
8
7
  const COMMENT_NODE = 8;
9
8
  const CLAIM_SEAM = Symbol.for("solid.element-claims");
10
9
  const CLAIMED_ELEMENTS = "a[href], form[action]";
@@ -12,110 +11,29 @@ function claimHandlers() {
12
11
  const handlers = globalThis[CLAIM_SEAM];
13
12
  return handlers !== undefined && handlers.length !== 0 ? handlers : undefined;
14
13
  }
15
- function claimNode(handlers, el) {
14
+ function claimNode(handlers, el, adopter) {
15
+ if (adopter) {
16
+ const by = adoptedBy.get(el);
17
+ if (by && liveFrames.has(by)) return;
18
+ adoptedBy.set(el, adopter);
19
+ }
16
20
  for (let i = 0; i < handlers.length; i++) handlers[i](el);
17
21
  }
18
- const claimedAttr = name => name === "href" || name === "action";
19
- function claimTree(handlers, root) {
22
+ function claimTree(handlers, root, adopter) {
20
23
  const isElement = root.nodeType === ELEMENT_NODE;
21
24
  if (!isElement && root.nodeType !== 11 ) return;
22
- if (isElement && root.matches(CLAIMED_ELEMENTS)) claimNode(handlers, root);
25
+ if (isElement && root.matches(CLAIMED_ELEMENTS)) claimNode(handlers, root, adopter);
23
26
  const found = root.querySelectorAll(CLAIMED_ELEMENTS);
24
- for (let i = 0; i < found.length; i++) claimNode(handlers, found[i]);
27
+ for (let i = 0; i < found.length; i++) claimNode(handlers, found[i], adopter);
25
28
  }
29
+ const adoptedBy = new WeakMap();
26
30
  const placeholderId = name => `pl-${name}`;
27
31
  const SLOT_START = /^slot:(.+):start$/;
28
32
  const SLOT_END = /^slot:(.+):end$/;
29
33
  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
34
  function isAsyncValue(v) {
40
35
  return v !== null && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
41
36
  }
42
- function chunkToRecords(chunk) {
43
- switch (chunk.type) {
44
- case "start":
45
- case "data":
46
- return {};
47
- case "html":
48
- return {
49
- "": {
50
- kind: "html",
51
- value: chunk.html,
52
- digest: chunk.digest,
53
- holes: chunk.holes
54
- }
55
- };
56
- case "fragment":
57
- return {
58
- [`seg:${chunk.key}`]: {
59
- kind: "html",
60
- value: chunk.html,
61
- digest: chunk.digest,
62
- holes: chunk.holes
63
- }
64
- };
65
- case "reveal":
66
- {
67
- const records = {};
68
- const gate = chunk.fallback ? "fallback" : "reveal";
69
- for (const key of chunk.keys) records[`seg:${key}:${gate}`] = true;
70
- return records;
71
- }
72
- case "assets":
73
- return {
74
- [`seg:${chunk.key}:assets`]: chunk
75
- };
76
- case "slot":
77
- return {
78
- [`slot:${chunk.key}`]: {
79
- kind: "slot",
80
- args: chunk.args
81
- }
82
- };
83
- case "hole":
84
- return {
85
- [`hole:${chunk.key}`]: {
86
- kind: "html",
87
- value: chunk.html,
88
- digest: chunk.digest,
89
- holes: chunk.holes
90
- }
91
- };
92
- case "attr":
93
- return {
94
- [`attr:${chunk.key}`]: {
95
- kind: "attrs",
96
- value: chunk.attrs,
97
- removed: chunk.removed,
98
- digest: chunk.digest
99
- }
100
- };
101
- case "ops":
102
- return Object.assign({}, ...chunk.ops.map(chunkToRecords));
103
- case "complete":
104
- return {
105
- ":complete": true,
106
- ":bound": chunk.bound
107
- };
108
- case "error":
109
- if (!chunk.key) return {
110
- ":error": chunk.error
111
- };
112
- return {
113
- [`${/^lha?:/.test(chunk.key) ? "hole" : "seg"}:${chunk.key}:error`]: chunk.error
114
- };
115
- default:
116
- return {};
117
- }
118
- }
119
37
  function createFrameHost(options = {}) {
120
38
  const frames = new Map();
121
39
  const stores = new Map();
@@ -144,15 +62,16 @@ function createFrameHost(options = {}) {
144
62
  }
145
63
  const assets = records["seg::assets"];
146
64
  const previous = assets && store.records["seg::assets"];
147
- if (!previous || previous === assets) {
148
- Object.assign(store.records, records);
149
- } else {
65
+ Object.assign(store.records, records);
66
+ if (previous && previous !== assets) {
67
+ const merged = {
68
+ ...previous
69
+ };
150
70
  for (const name in assets) {
151
71
  const values = assets[name];
152
- if (Array.isArray(values)) {
153
- previous[name] ? previous[name].push(...values) : previous[name] = values;
154
- }
72
+ if (Array.isArray(values)) merged[name] = previous[name] ? previous[name].concat(values) : values;
155
73
  }
74
+ store.records["seg::assets"] = merged;
156
75
  }
157
76
  return true;
158
77
  };
@@ -225,34 +144,47 @@ function createFrameHost(options = {}) {
225
144
  landings.delete(id);
226
145
  }
227
146
  },
228
- apply(chunk) {
229
- if (chunk.type === "data") {
230
- const store = stores.get(chunk.id);
147
+ apply(msg) {
148
+ if (msg.type === "data") {
149
+ const store = stores.get(msg.id);
231
150
  const current = store && store.version;
232
- if (store && chunk.version < current) return;
233
- options.applyData && options.applyData(chunk, current);
151
+ if (store && msg.version < current) return;
152
+ options.applyData && options.applyData(msg, current);
234
153
  return;
235
154
  }
236
- const records = chunkToRecords(chunk);
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);
155
+ let records = msg.r || {};
156
+ let slots;
157
+ for (const key in records) if (key.startsWith("slot:")) {
158
+ if (!slots) records = {
159
+ ...records
160
+ };
161
+ (slots ??= []).push(key);
162
+ records[key] = {
163
+ ...records[key]
164
+ };
242
165
  }
166
+ const store = storeFor(msg.id);
167
+ if (!write(store, msg.version, records)) return;
168
+ if (slots) for (const key of slots) settleArgs(store, key, records[key], msg);
243
169
  let r = records;
244
- if (chunk.type === "start") store.open = true;else if (lands(records)) {
170
+ if (msg.type === "start") {
171
+ store.open = true;
172
+ if (store.startedVersion !== msg.version) {
173
+ store.startedVersion = msg.version;
174
+ store.startedAt = msg.startedAt ?? performance.now();
175
+ }
176
+ } else if (lands(records)) {
245
177
  store.open = false;
246
178
  store.shown = r = store.records;
247
- store.shownVersion = chunk.version;
248
- const landed = landings.get(chunk.id);
179
+ store.shownVersion = msg.version;
180
+ const landed = landings.get(msg.id);
249
181
  if (landed && !(":complete" in records && ":error" in r)) {
250
- landings.delete(chunk.id);
182
+ landings.delete(msg.id);
251
183
  ":error" in records ? landed.j(records[":error"]) : landed.r();
252
184
  }
253
185
  }
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"]);
186
+ applyTo(msg.id, msg.version, r);
187
+ if (":complete" in records || ":error" in records) options.closeData && options.closeData(msg.id, msg.version, records[":error"]);
256
188
  },
257
189
  landing(id) {
258
190
  const store = stores.get(id);
@@ -262,17 +194,21 @@ function createFrameHost(options = {}) {
262
194
  if (!wait) {
263
195
  landings.set(id, wait = {});
264
196
  wait.p = new Promise((r, j) => (wait.r = r, wait.j = j));
197
+ if (store.open) OBSERVE.attribution.markFlight(wait.p, store.startedAt);
265
198
  }
266
199
  return wait.p;
267
200
  },
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);
201
+ preview(msg) {
202
+ const set = frames.get(msg.id);
203
+ if (!set || !msg.r) return;
204
+ let records;
205
+ for (const key in msg.r) if (key.startsWith("slot:")) {
206
+ const record = (records ??= {})[key] = {
207
+ ...msg.r[key]
208
+ };
209
+ settleArgs(storeFor(msg.id), key, record, msg);
210
+ }
211
+ if (records) for (const frame of set) frame.preview && frame.preview(records);
276
212
  },
277
213
  get(id) {
278
214
  const set = frames.get(id);
@@ -290,6 +226,26 @@ const FRAME_APPLIED_EVENT = "frame:applied";
290
226
  const tierLoaders = {};
291
227
  const tierLoads = {};
292
228
  const liveFrames = new Set();
229
+ let deferDriver = null;
230
+ function setDeferDriver(driver) {
231
+ deferDriver = driver;
232
+ }
233
+ function deferredFrames() {
234
+ return [...liveFrames].filter(f => f.deferred);
235
+ }
236
+ function releaseDeferHolds() {
237
+ for (const f of liveFrames) f.releaseDeferHold();
238
+ }
239
+ function hasSlotRange(root) {
240
+ const w = root.ownerDocument.createTreeWalker(root, 0x80);
241
+ for (let n; n = w.nextNode();) if (n.data.startsWith("slot:")) return true;
242
+ return false;
243
+ }
244
+ function liveFrameAt(node) {
245
+ let hit;
246
+ for (const f of liveFrames) if (f.el.contains(node) && (!hit || hit.el.contains(f.el))) hit = f;
247
+ return hit;
248
+ }
293
249
  function prepareTier(name) {
294
250
  let load = tierLoads[name];
295
251
  if (!load) {
@@ -305,6 +261,7 @@ function prepareTier(name) {
305
261
  }
306
262
  return load;
307
263
  }
264
+ const prepareMorph = () => liveFrames.size && prepareTier("wire");
308
265
  const tierReady = name => !tierLoaders[name] || prepareTier(name).r;
309
266
  const needsRegions = record => record.regions && !tierReady("regions");
310
267
  const carriesTrace = value => value != null && typeof value === "object" && (value.$tr != null || Object.values(value).some(carriesTrace));
@@ -315,10 +272,14 @@ class FrameImpl {
315
272
  #outer;
316
273
  #version;
317
274
  #store = Object.create(null);
275
+ #content = new Set();
318
276
  #appliedRoot;
319
277
  #appliedError;
320
278
  #hasContent = false;
321
279
  #appliedHoles = new Map();
280
+ #liveTargets = new Map();
281
+ #shows = {};
282
+ #liveMount;
322
283
  #slots;
323
284
  #mountedSlots = new Set();
324
285
  #slotCleanups = new Map();
@@ -326,11 +287,19 @@ class FrameImpl {
326
287
  #slotUpdaters = new Map();
327
288
  #hold;
328
289
  #heldRecords = new Map();
290
+ #found;
291
+ #waiting = new Set();
329
292
  #disposed = false;
330
- #claimTree = (node, direct) => {
293
+ #defers = false;
294
+ #deferred = false;
295
+ #deferFound;
296
+ #deferWaiting = false;
297
+ #deferMounted = new Map();
298
+ #deferHold;
299
+ #claimTree = (node, direct, adopter) => {
331
300
  const handlers = claimHandlers();
332
301
  if (!handlers) return;
333
- this.#scoped(() => direct ? claimNode(handlers, node) : claimTree(handlers, node));
302
+ this.#scoped(() => direct ? claimNode(handlers, node) : claimTree(handlers, node, adopter));
334
303
  };
335
304
  #scoped(fn) {
336
305
  const scope = this.#options.ownerScope;
@@ -345,11 +314,16 @@ class FrameImpl {
345
314
  if (options.adopt) {
346
315
  this.#hasContent = true;
347
316
  this.#claimContent();
317
+ this.#defers = !!deferDriver && !!(options.defer || this.#outer?.defers);
318
+ this.#deferred = this.#defers && !!(this.#slots || this.#outer) && hasSlotRange(element);
348
319
  }
349
320
  if (options.host && options.id !== undefined) {
350
321
  options.host.register(options.id, this);
351
322
  }
352
- if (options.adopt && this.#version === undefined) this.#syncSlots();
323
+ if (this.#deferred) {
324
+ this.#deferHold = options.hold?.();
325
+ deferDriver(this);
326
+ } else if (options.adopt && this.#version === undefined) this.#syncSlots();
353
327
  }
354
328
  #applied(version, reason) {
355
329
  this.#options.onApply?.({
@@ -389,8 +363,15 @@ class FrameImpl {
389
363
  this.#version = v;
390
364
  this.#resetStreamState();
391
365
  }
392
- for (const key in write.r) this.#store[key] = write.r[key];
393
- this.#flush();
366
+ let only = [];
367
+ for (const key in write.r) {
368
+ const prev = this.#store[key];
369
+ const occurrence = key.slice(5);
370
+ if (this.#deferred && prev?.kind === "slot" && !prev.pending && !this.#mountedSlots.has(occurrence)) this.#heldRecords.has(occurrence) || this.#heldRecords.set(occurrence, prev);
371
+ this.#store[key] = write.r[key];
372
+ if (key.startsWith("slot:")) only?.push(occurrence);else this.#content.add(key), only = undefined;
373
+ }
374
+ this.#flush(only?.length ? only : undefined);
394
375
  }
395
376
  preview(records, inherited) {
396
377
  const adopted = new Set();
@@ -412,17 +393,25 @@ class FrameImpl {
412
393
  return adopted;
413
394
  }
414
395
  #resetStreamState() {
396
+ if (this.#hasContent) prepareTier("wire");
397
+ this.#found = undefined;
415
398
  this.#store = Object.create(null);
399
+ this.#content.clear();
416
400
  this.#appliedRoot = this.#appliedError = undefined;
417
401
  this.#appliedHoles.clear();
402
+ this.#liveTargets.clear();
403
+ this.#shows = {};
418
404
  }
419
- #flush() {
405
+ #flush(only) {
420
406
  if (this.#disposed) return;
421
407
  const version = this.#version;
422
408
  const root = this.#store[""];
409
+ const applied = this.#appliedRoot;
423
410
  if (root && root.kind === "html" && root !== this.#appliedRoot) {
424
- const reason = this.#hasContent ? "morph" : "materialize";
425
- this.#applyRoot(root.value);
411
+ const wire = this.#hasContent ? tierReady("wire") : null;
412
+ if (wire === undefined) return;
413
+ const reason = wire ? "morph" : "materialize";
414
+ this.#applyRoot(root.value, wire);
426
415
  this.#appliedRoot = root;
427
416
  this.#recordHave("", root);
428
417
  this.#applied(version, reason);
@@ -432,7 +421,7 @@ class FrameImpl {
432
421
  this.#appliedError = error;
433
422
  this.#applied(version, "error");
434
423
  }
435
- for (const key in this.#store) {
424
+ for (const key of this.#content) {
436
425
  const record = this.#store[key];
437
426
  if (!key.endsWith(":assets") || !record || this.#appliedHoles.get(key) === record) continue;
438
427
  const tier = tierReady("assets");
@@ -440,28 +429,57 @@ class FrameImpl {
440
429
  this.#appliedHoles.set(key, record);
441
430
  tier.apply(record);
442
431
  }
443
- this.#revealSegments();
432
+ const revealed = this.#revealSegments();
444
433
  let morphed = false;
445
- for (const key in this.#store) {
434
+ const index = {};
435
+ let wire;
436
+ for (const key of this.#content) {
446
437
  const record = this.#store[key];
447
438
  if (!record || this.#appliedHoles.get(key) === record) continue;
448
439
  if (key.startsWith("hole:")) {
449
440
  if (key.endsWith(":error")) {
450
441
  this.#appliedHoles.set(key, record);
451
- } else if (this.#applyHole(key.slice(5), record.value)) {
452
- this.#appliedHoles.set(key, record);
453
- this.#recordHave(key.slice(5), record);
454
- morphed = true;
455
- }
456
- } else if (key.startsWith("attr:")) {
457
- if (this.#applyAttrs(key.slice(5), record.value, record.removed)) {
458
- this.#appliedHoles.set(key, record);
459
- this.#recordHave("lha:" + key.slice(5), record);
460
- morphed = true;
442
+ continue;
461
443
  }
444
+ } else if (!key.startsWith("attr:")) continue;
445
+ if (!this.#hasContent || !(wire ??= tierReady("wire"))) continue;
446
+ const name = key.slice(5);
447
+ const attr = key[0] === "a";
448
+ if (!attr) this.#found = undefined;
449
+ if (attr ? wire.attrs(this.#live, name, record) : wire.hole(this.#live, name, record, index)) {
450
+ this.#appliedHoles.set(key, record);
451
+ this.#recordHave(attr ? "lha:" + name : name, record);
452
+ morphed = true;
462
453
  }
463
454
  }
455
+ if (index.r?.size) wire.graft(index.g, index.r);
464
456
  if (morphed) this.#applied(version, "morph");
457
+ if (this.#deferred) {
458
+ if (!morphed && this.#appliedRoot === applied) {
459
+ if (revealed || !only) this.#deferFound = undefined;
460
+ const mounted = only ? new Map() : new Map(this.#deferMounted);
461
+ if (only) for (const id of only) {
462
+ const start = this.#deferMounted.get(id);
463
+ if (start) mounted.set(id, start);else if (!this.#deferFound?.has(id)) this.#deferFound = undefined;
464
+ }
465
+ if (mounted.size) this.#deferWaiting = this.#mountFound(mounted) || this.#deferWaiting;
466
+ return;
467
+ }
468
+ this.#deferred = false;
469
+ this.#deferFound = undefined;
470
+ this.#deferMounted.clear();
471
+ }
472
+ const found = this.#found;
473
+ if (only && found && this.#appliedRoot === applied) {
474
+ const sub = new Map();
475
+ for (const id of only) {
476
+ const start = found.get(id);
477
+ if (!start?.isConnected) return this.#syncSlots();
478
+ sub.set(id, start);
479
+ }
480
+ this.#mountFound(sub);
481
+ return this.#holdIf(this.#waiting.size);
482
+ }
465
483
  this.#syncSlots();
466
484
  }
467
485
  #resolveSlot(prop) {
@@ -481,25 +499,36 @@ class FrameImpl {
481
499
  #syncSlots(root) {
482
500
  if (!this.#slots && !this.#outer) return;
483
501
  const found = new Map();
484
- if (root) collectSlots(root, found, found);else this.#collectSlots(found, found);
502
+ this.#collectSlots(found, root);
503
+ if (root) this.#found = undefined;else this.#found = found, this.#waiting.clear();
504
+ const waiting = this.#mountFound(found);
505
+ if (!root) {
506
+ for (const occurrence of [...this.#mountedSlots]) {
507
+ if (!found.has(occurrence)) this.#unmountSlot(occurrence);
508
+ }
509
+ this.#holdIf(waiting);
510
+ }
511
+ }
512
+ #holdIf(waiting) {
513
+ if (waiting && !this.#hold) this.#hold = this.#options.hold?.();else if (!waiting && this.#hold) this.#releaseHold();
514
+ }
515
+ #mountFound(found) {
485
516
  let waiting = false;
486
517
  const R = tierLoads.regions?.r;
487
- const B = tierLoads.bind?.r;
488
518
  for (const [occurrence, start] of found) {
519
+ this.#waiting.delete(occurrence);
489
520
  const callback = this.#resolveSlot(propOf(occurrence));
490
- const consumers = Array.isArray(start) ? start : null;
491
- if (!callback) {
492
- continue;
493
- }
521
+ if (!callback) continue;
494
522
  const record = this.#resolveSlotRecord(occurrence);
495
523
  const mounted = this.#mountedSlots.has(occurrence);
496
524
  if (record === undefined && isCalled(occurrence)) {
497
- waiting ||= !mounted;
525
+ if (!mounted) waiting = true, this.#waiting.add(occurrence);
498
526
  continue;
499
527
  }
500
528
  if (!mounted && record && (record.pending || needsRegions(record) || needsTrace(record.args))) {
501
529
  waiting = true;
502
- if (this.#options.adopt && !consumers) this.#heldRecords.has(occurrence) || this.#heldRecords.set(occurrence, record);
530
+ this.#waiting.add(occurrence);
531
+ if (this.#options.adopt) this.#heldRecords.has(occurrence) || this.#heldRecords.set(occurrence, record);
503
532
  continue;
504
533
  }
505
534
  if (!mounted) {
@@ -507,12 +536,10 @@ class FrameImpl {
507
536
  this.#heldRecords.delete(occurrence);
508
537
  const mountRecord = held || record;
509
538
  this.#invokeSlot(occurrence, callback, mountRecord, start, this.#options.adopt);
510
- if (consumers) B.sync(this, occurrence, consumers);
511
539
  this.#mountedSlots.add(occurrence);
512
540
  R?.bind(this, occurrence);
513
541
  if (mountRecord === record || !record || record.kind !== "slot") continue;
514
542
  }
515
- if (consumers) B.sync(this, occurrence, consumers);
516
543
  if (record !== this.#slotArgs.get(occurrence)) {
517
544
  if (needsRegions(record) || needsTrace(record.args)) continue;
518
545
  const update = this.#slotUpdaters.get(occurrence);
@@ -527,13 +554,77 @@ class FrameImpl {
527
554
  R?.bind(this, occurrence);
528
555
  }
529
556
  }
530
- if (found.b && !tierReady("bind")) waiting = true;
531
- if (!root) {
532
- for (const occurrence of [...this.#mountedSlots]) {
533
- if (!found.has(occurrence)) this.#unmountSlot(occurrence);
557
+ return waiting;
558
+ }
559
+ get el() {
560
+ return this.#element;
561
+ }
562
+ get defers() {
563
+ return this.#defers;
564
+ }
565
+ get deferred() {
566
+ return this.#deferred;
567
+ }
568
+ mountEnclosing(target) {
569
+ if (!this.#deferred) return false;
570
+ const root = this.#element;
571
+ let outer;
572
+ for (let node = target; node && node !== root; node = node.parentNode) {
573
+ let depth = 0;
574
+ for (let s = node.previousSibling; s; s = s.previousSibling) {
575
+ if (s.nodeType !== COMMENT_NODE || !s.data.startsWith("slot:")) continue;
576
+ if (SLOT_END.test(s.data)) depth++;else if (depth) depth--;else outer = s;
534
577
  }
535
- if (waiting && !this.#hold) this.#hold = this.#options.hold?.();else if (!waiting && this.#hold) this.#releaseHold();
536
578
  }
579
+ const id = outer && slotStartId(outer);
580
+ if (!id || this.#mountedSlots.has(id)) return false;
581
+ return this.#mountOne(id, outer);
582
+ }
583
+ #mountOne(id, start) {
584
+ const mount = () => {
585
+ this.#deferWaiting = this.#mountFound(new Map([[id, start]])) || this.#deferWaiting;
586
+ };
587
+ mount();
588
+ if (!this.#mountedSlots.has(id)) return false;
589
+ this.#deferMounted.set(id, start);
590
+ return true;
591
+ }
592
+ mountDeferred(deadline) {
593
+ if (!this.#deferred) return true;
594
+ let found = this.#deferFound;
595
+ if (!found) {
596
+ found = this.#deferFound = new Map();
597
+ this.#collectSlots(found);
598
+ }
599
+ for (const [id, start] of found) {
600
+ found.delete(id);
601
+ if (this.#mountedSlots.has(id)) this.#deferWaiting = this.#mountFound(new Map([[id, start]])) || this.#deferWaiting;else this.#mountOne(id, start);
602
+ if (deadline !== undefined && found.size && performance.now() > deadline) return false;
603
+ }
604
+ this.#deferred = false;
605
+ this.#deferFound = undefined;
606
+ this.#deferMounted.clear();
607
+ if (this.#deferWaiting && !this.#hold) this.#hold = this.#options.hold?.();
608
+ return true;
609
+ }
610
+ mountOccurrence(id) {
611
+ if (!this.#deferred) return false;
612
+ if (this.#mountedSlots.has(id)) return true;
613
+ let found = this.#deferFound;
614
+ if (!found) {
615
+ found = this.#deferFound = new Map();
616
+ this.#collectSlots(found);
617
+ }
618
+ const start = found.get(id);
619
+ if (!start) return false;
620
+ found.delete(id);
621
+ this.#mountOne(id, start);
622
+ return true;
623
+ }
624
+ releaseDeferHold() {
625
+ const release = this.#deferHold;
626
+ this.#deferHold = undefined;
627
+ release && release();
537
628
  }
538
629
  #releaseHold() {
539
630
  const release = this.#hold;
@@ -545,8 +636,7 @@ class FrameImpl {
545
636
  const cleanups = this.#slotCleanups.get(occurrence) ?? [];
546
637
  let existing = [];
547
638
  let end = null;
548
- const positions = Array.isArray(start) ? start : undefined;
549
- if (start && !positions) end = eachInRange(start, occurrence, n => existing.push(n));
639
+ if (start) end = eachInRange(start, occurrence, n => existing.push(n));
550
640
  const ctx = {
551
641
  frame: this.#options.claimScope ?? this.#options.id,
552
642
  key: occurrence,
@@ -558,9 +648,7 @@ class FrameImpl {
558
648
  range: end ? {
559
649
  start,
560
650
  end
561
- } : undefined,
562
- positions,
563
- onRebind: positions ? fn => tierLoads.bind.r.rebinder(this, occurrence, fn) : undefined
651
+ } : undefined
564
652
  };
565
653
  const props = record && record.kind === "slot" ? this.#resolveArgs(occurrence, record, adopted, start) : {};
566
654
  this.#scoped(() => callback(props, ctx));
@@ -575,7 +663,6 @@ class FrameImpl {
575
663
  this.#removeSlotRecord(key);
576
664
  this.#runSlotCleanups(key);
577
665
  tierLoads.regions?.r?.unmount(this, key);
578
- tierLoads.bind?.r?.unmount(this, key);
579
666
  }
580
667
  #runSlotCleanups(key) {
581
668
  const cleanups = this.#slotCleanups.get(key);
@@ -602,8 +689,8 @@ class FrameImpl {
602
689
  if (regions) tierLoads.regions.r.resolve(this, slotKey, regions, props, claiming && start);
603
690
  return props;
604
691
  }
605
- #collectSlots(found, elements) {
606
- collectSlots(this.#element, found, elements);
692
+ #collectSlots(found, root) {
693
+ collectSlots(root || this.#element, found);
607
694
  }
608
695
  #findPlaceholder(name, root) {
609
696
  return findPlaceholder((root || this.#element).firstChild, null, placeholderId(name));
@@ -630,7 +717,23 @@ class FrameImpl {
630
717
  this.#resetStreamState();
631
718
  if (host) host.register(id, this);
632
719
  }
720
+ get #live() {
721
+ return this.#liveMount ??= {
722
+ e: this.#element,
723
+ t: this.#liveTargets,
724
+ c: this.#claimTree,
725
+ k: found => this.#collectSlots(found),
726
+ s: () => this.#shows,
727
+ x: (key, record) => (this.#appliedHoles.set(key, record), tierLoads.wire.r.cancel(this.#options.host, this.#options.id)),
728
+ w: false
729
+ };
730
+ }
633
731
  #recordHave(key, record) {
732
+ this.#shows = key ? Object.assign(this.#shows, {
733
+ [key]: record.digest
734
+ }, record.holes) : {
735
+ ...record.holes
736
+ };
634
737
  tierLoads.wire?.r?.have(this, key, record);
635
738
  }
636
739
  dispose() {
@@ -643,12 +746,16 @@ class FrameImpl {
643
746
  this.#disposed = true;
644
747
  liveFrames.delete(this);
645
748
  this.#releaseHold();
749
+ this.releaseDeferHold();
646
750
  for (const key of [...this.#slotCleanups.keys()]) this.#runSlotCleanups(key);
647
751
  for (const key of this.#mountedSlots) this.#removeSlotRecord(key);
648
752
  tierLoads.regions?.r?.unmount(this);
649
753
  this.#mountedSlots.clear();
650
754
  }
651
- #applyRoot(html) {
755
+ #applyRoot(html, wire) {
756
+ this.#found = undefined;
757
+ this.#liveTargets.clear();
758
+ this.#shows = {};
652
759
  const fragment = parseFragment(html);
653
760
  const parent = this.#element;
654
761
  if (!this.#hasContent) {
@@ -660,62 +767,16 @@ class FrameImpl {
660
767
  const claim = this.#claimTree;
661
768
  const ranges = new Map();
662
769
  this.#collectSlots(ranges);
663
- const grafts = [];
664
- reconcileChildren(parent, fragment, null, null, claim, ranges, grafts);
665
- if (ranges.size) for (const root of grafts) flushGrafts(root, ranges);
666
- }
667
- }
668
- #applyHole(marker, html) {
669
- if (!this.#hasContent) return false;
670
- const open = findLiveTarget(this.#element.firstChild, null, n => n.nodeType === COMMENT_NODE && n.data === marker);
671
- if (!open) return false;
672
- const close = rangeClose(open, "lh:/" + marker.slice(3));
673
- if (!close) {
674
- return false;
675
- }
676
- reconcileChildren(open.parentNode, parseFragment(html), open, close, this.#claimTree);
677
- return true;
678
- }
679
- #applyAttrs(addr, text, removed) {
680
- if (!this.#hasContent) return false;
681
- const el = findLiveTarget(this.#element.firstChild, null, n => n.nodeType === ELEMENT_NODE && n.getAttribute("data-lha") === addr);
682
- if (!el) return false;
683
- const parsed = parseFragment(`<i${text}></i>`).firstChild;
684
- const keepOpen = preservesOpen(el);
685
- const owned = parsed ? ownedPositions(parsed) : null;
686
- const current = el.attributes;
687
- for (let i = current.length - 1; i >= 0; i--) {
688
- const name = current[i].name;
689
- if (name === "data-lha" || keepOpen && name === "open") continue;
690
- if (!parsed || !parsed.hasAttribute(name)) {
691
- if (applyOwned(el, name, "", owned) !== undefined) continue;
692
- el.removeAttribute(name);
693
- }
694
- }
695
- if (parsed) {
696
- for (let i = 0; i < parsed.attributes.length; i++) {
697
- const {
698
- name,
699
- value
700
- } = parsed.attributes[i];
701
- if (keepOpen && name === "open") continue;
702
- if (applyOwned(el, name, value, owned) !== undefined) continue;
703
- if (el.getAttribute(name) !== value) el.setAttribute(name, value);
704
- }
705
- }
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);
770
+ wire.morph(parent, fragment, claim, ranges);
710
771
  }
711
- return true;
712
772
  }
713
773
  #claimContent() {
714
- for (let n = this.#element.firstChild; n; n = n.nextSibling) this.#claimTree(n);
774
+ for (let n = this.#element.firstChild; n; n = n.nextSibling) this.#claimTree(n, false, this);
715
775
  }
716
776
  #revealSegments(root) {
717
777
  const version = this.#version;
718
- for (const key in this.#store) {
778
+ let revealed = false;
779
+ for (const key of this.#content) {
719
780
  const record = this.#store[key];
720
781
  const name = segmentName(key);
721
782
  if (name === null || !record || this.#appliedHoles.get(key) === record) continue;
@@ -723,9 +784,10 @@ class FrameImpl {
723
784
  this.#appliedHoles.set(key, record);
724
785
  this.#revealSegment(name, root);
725
786
  this.#applied(version, "reveal");
787
+ revealed = true;
726
788
  }
727
789
  }
728
- for (const key in this.#store) {
790
+ for (const key of this.#content) {
729
791
  const m = /^seg:([^:]+):fallback$/.exec(key);
730
792
  if (!m || this.#appliedHoles.has(key) || this.#appliedHoles.has(`seg:${m[1]}`)) continue;
731
793
  if (this.#showFallback(m[1], root)) {
@@ -733,6 +795,7 @@ class FrameImpl {
733
795
  this.#applied(version, "reveal");
734
796
  }
735
797
  }
798
+ return revealed;
736
799
  }
737
800
  #segmentReady(name, root) {
738
801
  const content = this.#store[`seg:${name}`];
@@ -745,6 +808,7 @@ class FrameImpl {
745
808
  #revealSegment(name, root) {
746
809
  const tpl = this.#findPlaceholder(name, root);
747
810
  if (!tpl) return;
811
+ this.#found = undefined;
748
812
  const content = this.#store[`seg:${name}`];
749
813
  const closing = rangeClose(tpl, placeholderId(name));
750
814
  if (!closing) {
@@ -804,9 +868,6 @@ function makeFrameElement(id) {
804
868
  if (id !== undefined) el.setAttribute(FRAME_ID_ATTR, id);
805
869
  return el;
806
870
  }
807
- function isFrameElement(node) {
808
- return node.nodeType === ELEMENT_NODE && node.hasAttribute(FRAME_ID_ATTR);
809
- }
810
871
  function segmentName(key) {
811
872
  const m = /^seg:([^:]+)$/.exec(key);
812
873
  return m ? m[1] : null;
@@ -845,20 +906,6 @@ function rangeClose(start, id) {
845
906
  }
846
907
  return null;
847
908
  }
848
- function findLiveTarget(n, end, test) {
849
- while (n && n !== end) {
850
- if (n.nodeType === ELEMENT_NODE) {
851
- const fid = isFrameElement(n) ? n.getAttribute(FRAME_ID_ATTR) : null;
852
- if (fid === null || fid.includes(".")) {
853
- if (test(n)) return n;
854
- const found = findLiveTarget(n.firstChild, null, test);
855
- if (found) return found;
856
- }
857
- } else if (test(n)) return n;
858
- n = n.nextSibling;
859
- }
860
- return null;
861
- }
862
909
  function findPlaceholder(n, end, id) {
863
910
  while (n && n !== end) {
864
911
  if (isPlaceholderStart(n, id)) return n;
@@ -870,38 +917,23 @@ function findPlaceholder(n, end, id) {
870
917
  }
871
918
  return null;
872
919
  }
873
- function collectSlots(root, out, elements) {
874
- let announced;
875
- const bind = elements && (tierLoads.bind || !(announced = globalThis._$HY?.r?.["sc:tiers"]) || announced.includes("bind"));
876
- const B = bind && tierLoads.bind?.r;
877
- const w = root.ownerDocument.createTreeWalker(root, bind ? 0x81 : 0x80);
920
+ function collectSlots(root, out) {
921
+ const w = root.ownerDocument.createTreeWalker(root, 0x80);
878
922
  let n, p;
879
923
  while (n = w.nextNode()) {
880
- if (n.nodeType !== COMMENT_NODE) {
881
- if (!n.hasAttribute(FRAME_ID_ATTR)) {
882
- if (n.hasAttributes()) B ? B.positions(n, elements) : hasSlotMarker(n) && (elements.b = true);
883
- continue;
884
- }
885
- p = n;
886
- } else if (n.data.startsWith("slot:")) {
887
- const id = slotStartId(n);
888
- if (!id) continue;
889
- if (!bind) {
890
- for (p = n.parentNode; p !== root; p = p.parentNode) if (p.hasAttribute(FRAME_ID_ATTR)) break;
891
- if (p !== root) continue;
892
- }
893
- if (!out.has(id)) out.set(id, n);
894
- const end = findMarker(n, slotEnd(id));
895
- if (end) {
896
- w.currentNode = end;
897
- continue;
898
- }
899
- p = n.parentNode;
900
- if (p === root) return;
901
- } else {
902
- if (bind && n.data.startsWith(SLOT_TEXT)) B ? B.text(n, elements) : elements.b = true;
924
+ if (!n.data.startsWith("slot:")) continue;
925
+ const id = slotStartId(n);
926
+ if (!id) continue;
927
+ for (p = n.parentNode; p !== root; p = p.parentNode) if (p.hasAttribute(FRAME_ID_ATTR)) break;
928
+ if (p !== root) continue;
929
+ if (!out.has(id)) out.set(id, n);
930
+ const end = findMarker(n, slotEnd(id));
931
+ if (end) {
932
+ w.currentNode = end;
903
933
  continue;
904
934
  }
935
+ p = n.parentNode;
936
+ if (p === root) return;
905
937
  while (p.lastChild) p = p.lastChild;
906
938
  w.currentNode = p;
907
939
  }
@@ -921,74 +953,6 @@ function slotStartId(node) {
921
953
  const m = SLOT_START.exec(node.data);
922
954
  return m ? m[1] : null;
923
955
  }
924
- function isSlotMarker(node) {
925
- if (node.nodeType !== COMMENT_NODE) return false;
926
- const data = node.data;
927
- return SLOT_START.test(data) || SLOT_END.test(data);
928
- }
929
- function compatible(a, b) {
930
- if (a.nodeType !== b.nodeType) return false;
931
- if (a.nodeType === ELEMENT_NODE) return a.nodeName === b.nodeName && a.getAttribute("_key") === b.getAttribute("_key");
932
- return a.nodeType === TEXT_NODE || a.nodeType === COMMENT_NODE;
933
- }
934
- function preservesOpen(el) {
935
- const t = el.tagName;
936
- return t === "DETAILS" || t === "DIALOG";
937
- }
938
- const ownedPositions = el => {
939
- const B = tierLoads.bind?.r;
940
- return B ? B.owned(el) : null;
941
- };
942
- const applyOwned = (oldEl, name, value, owned) => owned === null ? undefined : tierLoads.bind.r.apply(oldEl, name, value, owned);
943
- function morphAttributes(oldEl, newEl, claim) {
944
- let reclaim = false;
945
- let changed = false;
946
- const keepOpen = preservesOpen(oldEl);
947
- const owned = ownedPositions(newEl);
948
- const oldAttrs = oldEl.attributes;
949
- for (let i = oldAttrs.length - 1; i >= 0; i--) {
950
- const name = oldAttrs[i].name;
951
- if (keepOpen && name === "open") continue;
952
- if (!newEl.hasAttribute(name)) {
953
- const handled = applyOwned(oldEl, name, "", owned);
954
- if (handled !== undefined) {
955
- changed = handled || changed;
956
- continue;
957
- }
958
- oldEl.removeAttribute(name);
959
- changed = true;
960
- reclaim ||= claimedAttr(name);
961
- }
962
- }
963
- const newAttrs = newEl.attributes;
964
- for (let i = 0; i < newAttrs.length; i++) {
965
- const attr = newAttrs[i];
966
- const name = attr.name;
967
- if (keepOpen && name === "open") continue;
968
- const handled = applyOwned(oldEl, name, attr.value, owned);
969
- if (handled !== undefined) {
970
- changed = handled || changed;
971
- continue;
972
- }
973
- if (oldEl.getAttribute(name) !== attr.value) {
974
- oldEl.setAttribute(name, attr.value);
975
- changed = true;
976
- reclaim ||= claimedAttr(name);
977
- }
978
- }
979
- if (claim && (reclaim || changed && oldEl.matches(CLAIMED_ELEMENTS))) claim(oldEl, true);
980
- }
981
- function morphNode(oldNode, newNode, claim, ranges, grafts) {
982
- if (oldNode.nodeType === ELEMENT_NODE) {
983
- if (oldNode.hasAttribute("data-preserve")) return;
984
- morphAttributes(oldNode, newNode, claim);
985
- reconcileChildren(oldNode, newNode, null, null, claim, ranges, grafts);
986
- } else if (oldNode.data !== newNode.data) {
987
- oldNode.data = newNode.data;
988
- }
989
- }
990
- const afterRange = (start, id) => findMarker(start, slotEnd(id))?.nextSibling;
991
- const afterText = start => findMarker(start, SLOT_TEXT_END)?.nextSibling;
992
956
  function findMarker(start, end) {
993
957
  let n = start.nextSibling;
994
958
  while (n) {
@@ -997,170 +961,22 @@ function findMarker(start, end) {
997
961
  }
998
962
  return null;
999
963
  }
1000
- function findRangeStart(from, id, bound) {
1001
- const target = `slot:${id}:start`;
1002
- let n = from;
1003
- while (n && n !== bound) {
1004
- if (n.nodeType === COMMENT_NODE && n.data === target) return n;
1005
- n = n.nextSibling;
1006
- }
1007
- return null;
1008
- }
1009
- function moveRangeBefore(parent, start, id, ref) {
1010
- const end = slotEnd(id);
1011
- let n = start;
1012
- while (n) {
1013
- const next = n.nextSibling;
1014
- const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
1015
- parent.insertBefore(n, ref);
1016
- if (isEnd) break;
1017
- n = next;
1018
- }
1019
- }
1020
- function placeRange(parent, range, id, ref) {
1021
- if (range.nodeType === 11 ) {
1022
- parent.insertBefore(range, ref);
1023
- } else {
1024
- moveRangeBefore(parent, range, id, ref);
1025
- }
1026
- }
1027
- function adoptRange(parent, start, id, ref, claim) {
1028
- const end = slotEnd(id);
1029
- let n = start;
1030
- let after = null;
1031
- while (n) {
1032
- const next = n.nextSibling;
1033
- const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
1034
- parent.insertBefore(n, ref);
1035
- if (claim) claim(n);
1036
- if (isEnd) {
1037
- after = next;
1038
- break;
1039
- }
1040
- n = next;
1041
- }
1042
- return after;
1043
- }
1044
- function reconcileChildren(parent, source, boundStart = null, boundEnd = null, claim = null, ranges = null, grafts = null) {
1045
- let oldChild = boundStart ? boundStart.nextSibling : parent.firstChild;
1046
- let newChild = source.firstChild;
1047
- while (newChild) {
1048
- const nextNew = newChild.nextSibling;
1049
- const pid = slotStartId(newChild);
1050
- const old = oldChild === boundEnd ? null : oldChild;
1051
- if (old && isTextStart(newChild) && old.nodeType === COMMENT_NODE && old.data === newChild.data) {
1052
- oldChild = afterText(old);
1053
- newChild = afterText(newChild);
1054
- continue;
1055
- }
1056
- if (pid !== null) {
1057
- if (old && slotStartId(old) === pid) {
1058
- oldChild = afterRange(old, pid);
1059
- newChild = afterRange(newChild, pid);
1060
- } else {
1061
- const displaced = ranges && ranges.get(pid);
1062
- const existing = displaced || findRangeStart(old, pid, boundEnd);
1063
- if (existing) {
1064
- if (ranges) ranges.delete(pid);
1065
- placeRange(parent, existing, pid, old ?? boundEnd);
1066
- newChild = afterRange(newChild, pid);
1067
- } else {
1068
- newChild = adoptRange(parent, newChild, pid, old ?? boundEnd, claim);
1069
- }
1070
- }
1071
- continue;
1072
- }
1073
- if (!old) {
1074
- parent.insertBefore(newChild, boundEnd);
1075
- if (claim) claim(newChild);
1076
- if (grafts) grafts.push(newChild);
1077
- newChild = nextNew;
1078
- continue;
1079
- }
1080
- if (isSlotMarker(old)) {
1081
- parent.insertBefore(newChild, old);
1082
- if (claim) claim(newChild);
1083
- if (grafts) grafts.push(newChild);
1084
- newChild = nextNew;
1085
- continue;
1086
- }
1087
- if (compatible(old, newChild)) {
1088
- morphNode(old, newChild, claim, ranges, grafts);
1089
- oldChild = old.nextSibling;
1090
- newChild = nextNew;
1091
- continue;
1092
- }
1093
- if (newChild.nodeType === 1) {
1094
- let ahead = old.nextSibling;
1095
- while (ahead && ahead !== boundEnd && !compatible(ahead, newChild)) {
1096
- const aheadPid = slotStartId(ahead);
1097
- ahead = aheadPid !== null ? afterRange(ahead, aheadPid) : ahead.nextSibling;
1098
- }
1099
- if (ahead && ahead !== boundEnd) {
1100
- parent.insertBefore(ahead, old);
1101
- morphNode(ahead, newChild, claim, ranges, grafts);
1102
- newChild = nextNew;
1103
- continue;
1104
- }
1105
- }
1106
- parent.insertBefore(newChild, old);
1107
- if (claim) claim(newChild);
1108
- if (grafts) grafts.push(newChild);
1109
- newChild = nextNew;
1110
- }
1111
- while (oldChild && oldChild !== boundEnd) {
1112
- const next = oldChild.nextSibling;
1113
- const pid = ranges ? slotStartId(oldChild) : null;
1114
- if (pid !== null && ranges.get(pid) === oldChild) {
1115
- const frag = document.createDocumentFragment();
1116
- const after = stashRange(frag, oldChild, pid);
1117
- ranges.set(pid, frag);
1118
- oldChild = after;
1119
- continue;
1120
- }
1121
- parent.removeChild(oldChild);
1122
- oldChild = next;
1123
- }
1124
- }
1125
- function flushGrafts(node, ranges) {
1126
- if (node.nodeType !== ELEMENT_NODE || isFrameElement(node)) return;
1127
- let n = node.firstChild;
1128
- while (n) {
1129
- const id = slotStartId(n);
1130
- if (id !== null) {
1131
- const next = afterRange(n, id);
1132
- const displaced = ranges.get(id);
1133
- if (displaced) {
1134
- ranges.delete(id);
1135
- placeRange(node, displaced, id, n);
1136
- stashRange(document.createDocumentFragment(), n, id);
1137
- }
1138
- n = next;
1139
- continue;
1140
- }
1141
- flushGrafts(n, ranges);
1142
- n = n.nextSibling;
1143
- }
1144
- }
1145
- function stashRange(frag, start, id) {
1146
- const end = slotEnd(id);
1147
- let n = start;
1148
- while (n) {
1149
- const next = n.nextSibling;
1150
- const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
1151
- frag.appendChild(n);
1152
- if (isEnd) return next;
1153
- n = next;
1154
- }
1155
- return null;
1156
- }
1157
964
 
1158
965
  const RECORDS = Symbol.for("@solidjs/signals/observe/records");
1159
966
  function records() {
1160
967
  return globalThis[RECORDS];
1161
968
  }
1162
- function frameCensus(event, type, own) {
1163
- event.chunks++;
969
+ function frameRecordCensus(event, message, own) {
970
+ const r = message.r;
971
+ let counted = !r;
972
+ for (const key in r) {
973
+ if (key === ":complete" || key === ":bound") continue;
974
+ counted = true;
975
+ countEvent(event, key === "" ? "html" : key.endsWith(":error") ? "error" : key.startsWith("slot:") ? "slot" : key.startsWith("seg:") && r[key] && r[key].kind === "html" ? "fragment" : key, own);
976
+ }
977
+ if (counted) event.chunks++;
978
+ }
979
+ function countEvent(event, type, own) {
1164
980
  switch (type) {
1165
981
  case "html":
1166
982
  if (!own) event.regions++;else if (event.shellMs === undefined) event.shellMs = performance.now() - event.at;
@@ -1216,11 +1032,8 @@ function observeFrameApply(response) {
1216
1032
  return;
1217
1033
  }
1218
1034
  if (current === undefined) return;
1219
- if (chunk.type === "complete") {
1220
- if (chunk.id === current.applied) close("complete");
1221
- return;
1222
- }
1223
- frameCensus(current.event, chunk.type, chunk.id === current.applied);
1035
+ frameRecordCensus(current.event, chunk, chunk.id === current.applied);
1036
+ if (chunk.r && ":complete" in chunk.r && chunk.id === current.applied) close("complete");
1224
1037
  },
1225
1038
  end(error) {
1226
1039
  if (current !== undefined) close(error !== undefined ? "error" : "truncated", error);
@@ -1247,6 +1060,11 @@ async function observedApplyFrameResponse(response, host, options = {}) {
1247
1060
  observation.end();
1248
1061
  return applied;
1249
1062
  }
1063
+ const ends = msg => !!msg.r && (":complete" in msg.r || ":error" in msg.r);
1064
+ const readsData = msg => {
1065
+ for (const key in msg.r) if (key.startsWith("slot:")) for (const v of Object.values(msg.r[key].args)) if (v && v.$ref) return true;
1066
+ return false;
1067
+ };
1250
1068
  function applyFrames(response, host, options = {}, observation) {
1251
1069
  const rootId = response.headers.get(FRAME_STREAM_HEADER) ?? "";
1252
1070
  response.headers.get(FRAME_TIERS_HEADER)?.split(",").forEach(prepareTier);
@@ -1256,11 +1074,12 @@ function applyFrames(response, host, options = {}, observation) {
1256
1074
  const reader = options[LIVE_WIRE] || new ChunkReader(response.body);
1257
1075
  const open = new Map();
1258
1076
  const errorRecord = (id, error) => ({
1259
- type: "error",
1260
1077
  id,
1261
1078
  version: open.get(id),
1262
- error: {
1263
- message: String(error && error.message)
1079
+ r: {
1080
+ ":error": {
1081
+ message: String(error && error.message)
1082
+ }
1264
1083
  }
1265
1084
  });
1266
1085
  const drain = async () => {
@@ -1277,10 +1096,10 @@ function applyFrames(response, host, options = {}, observation) {
1277
1096
  if (v === undefined) perFrame.set(chunk.id, v = version(chunk.id));
1278
1097
  chunk.version = v;
1279
1098
  } else if (version !== undefined) chunk.version = version;
1280
- if (chunk.type === "start") open.set(chunk.id, chunk.version);else if (chunk.type === "complete" || chunk.type === "error" && !chunk.key) open.delete(chunk.id);
1099
+ if (chunk.type === "start") open.set(chunk.id, chunk.version);else if (ends(chunk)) open.delete(chunk.id);
1281
1100
  if (observation) observation.chunk(chunk, wireId);
1282
1101
  const needs = chunk.tiers?.map(prepareTier) || [];
1283
- if (chunk.type === "data" || chunk.type === "slot" && Object.values(chunk.args).some(v => v && v.$ref)) await Promise.all([host.prepareData?.(), ...needs]);
1102
+ if (chunk.type === "data" || readsData(chunk)) await Promise.all([host.prepareData?.(), ...needs]);
1284
1103
  host.apply(chunk);
1285
1104
  }
1286
1105
  result = await reader.next();
@@ -1440,7 +1259,7 @@ function createServerComponentHandler({
1440
1259
  return {
1441
1260
  intercept: intercept && (info => {
1442
1261
  const hit = intercept(info);
1443
- if (hit === undefined) return undefined;
1262
+ if (hit === undefined) return void prepareMorph();
1444
1263
  const address = frameAddress(info.id, info.args);
1445
1264
  if (!info.meta?.live) calls.set(address, info);
1446
1265
  const binding = () => bindingFor(address, info.id);
@@ -1465,17 +1284,23 @@ function createServerComponentHandler({
1465
1284
  calls.set(address, ctx);
1466
1285
  const version = bump(address);
1467
1286
  const entry = showing(address) ? stage(address, binding, version) : undefined;
1468
- if (!entry) begin(address, version);
1287
+ if (!entry) host.apply({
1288
+ type: "start",
1289
+ id: address,
1290
+ version,
1291
+ startedAt: ctx.startedAt
1292
+ }) ;
1469
1293
  const target = entry || host;
1470
1294
  const applied = applyFrameResponse(response, target, {
1471
1295
  as: address,
1472
1296
  version: frameId => frameId === address ? version : bump(frameId)
1473
1297
  }).catch(err => target.apply({
1474
- type: "error",
1475
1298
  id: address,
1476
1299
  version,
1477
- error: {
1478
- message: String(err && err.message)
1300
+ r: {
1301
+ ":error": {
1302
+ message: String(err && err.message)
1303
+ }
1479
1304
  }
1480
1305
  }));
1481
1306
  return entry ? applied.then(() => settled(address, binding)) : binding;
@@ -1533,6 +1358,10 @@ function createServerComponentHandler({
1533
1358
  }
1534
1359
  }
1535
1360
 
1361
+ const setWriteHook = core.setWriteHook;
1362
+ const setSignalIdentities = core.setSignalIdentities;
1363
+ const signalName = core.signalName;
1364
+ const storeName = core.storeName;
1536
1365
  const createLoadingBoundary = core.createLoadingBoundary;
1537
1366
  const sharedConfig = core.sharedConfig;
1538
1367
 
@@ -1540,7 +1369,6 @@ const TRACE_STATE = Symbol.for("solid.container-trace-state");
1540
1369
  tierLoaders.trace = () => import('@solidjs/web/frames/trace');
1541
1370
  tierLoaders.regions = () => import('@solidjs/web/frames/regions');
1542
1371
  tierLoaders.assets = () => import('@solidjs/web/frames/assets');
1543
- tierLoaders.bind = () => import('@solidjs/web/frames/bind');
1544
1372
  tierLoaders.wire = () => import('@solidjs/web/frames/wire');
1545
1373
  function asyncArg(value) {
1546
1374
  return value;
@@ -1581,7 +1409,12 @@ function landing(host, address, value, failed) {
1581
1409
  if (state > 1) throw frame.error;
1582
1410
  const wait = host.landing(address);
1583
1411
  if (!wait) return value;
1584
- return (state ? reask(address, wait) : wait).then(() => value);
1412
+ const landed = (state ? reask(address, wait) : wait).then(() => value);
1413
+ if (!state) {
1414
+ const origin = OBSERVE.attribution.flightOrigin(wait);
1415
+ if (origin !== undefined) OBSERVE.attribution.markFlight(landed, origin);
1416
+ }
1417
+ return landed;
1585
1418
  });
1586
1419
  }
1587
1420
  function reask(address, wait) {
@@ -1628,15 +1461,13 @@ function claimScope(el) {
1628
1461
  index
1629
1462
  };
1630
1463
  }
1631
- function claimRender(prefix, existing, render, scope, bound) {
1464
+ function claimRender(prefix, owner, existing, render, scope, bound) {
1632
1465
  const sc = sharedConfig;
1633
- if (!sc.hydrateWindow || !sc.registry) return render();
1466
+ if (!sc.hydrateWindow || !sc.registry) return runWithOwner(owner, render);
1634
1467
  const prevRoots = sc.claimRoots;
1635
1468
  sc.claimRoots = existing;
1636
1469
  try {
1637
- return runWithOwner(createOwner({
1638
- id: prefix
1639
- }), () => sc.hydrateWindow(bound ? undefined : prefix, render, scope));
1470
+ return runWithOwner(owner, () => sc.hydrateWindow(bound ? undefined : prefix, render, scope));
1640
1471
  } finally {
1641
1472
  sc.claimRoots = prevRoots;
1642
1473
  }
@@ -1687,6 +1518,7 @@ function slotArgsProxy(args) {
1687
1518
  reads.set(key, read);
1688
1519
  }
1689
1520
  const v = read();
1521
+ if (v instanceof Element) tierLoads.regions.r.place(v);
1690
1522
  return v instanceof Boxed ? v.c : v;
1691
1523
  },
1692
1524
  has: (_, key) => key in args(),
@@ -1702,40 +1534,24 @@ function slotsFor(props, scope) {
1702
1534
  return new Proxy({}, {
1703
1535
  get(_, prop) {
1704
1536
  if (typeof prop !== "string" || !(prop in props)) return undefined;
1705
- return (slotProps, ctx) => {
1537
+ const mount = (slotProps, ctx) => {
1706
1538
  const key = ctx && ctx.key;
1707
1539
  const prevFill = key !== undefined && fillScopes.get(key);
1708
1540
  if (prevFill) {
1709
1541
  fillScopes.delete(key);
1710
1542
  prevFill.dispose();
1711
1543
  }
1712
- if (ctx && ctx.positions) {
1713
- const fill = props[prop];
1714
- if (typeof fill !== "function") {
1715
- return undefined;
1716
- }
1717
- const owner = createOwner();
1718
- fillScopes.set(key, owner);
1719
- ctx.onCleanup(() => {
1720
- if (fillScopes.get(key) === owner) fillScopes.delete(key);
1721
- owner.dispose();
1722
- });
1723
- runWithOwner(owner, () => {
1724
- const args = ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotArgsProxy(() => slotProps);
1725
- tierLoads.bind.r.bind(fill, args, ctx, undefined);
1726
- });
1727
- return undefined;
1728
- }
1729
1544
  const range = ctx && ctx.range;
1730
1545
  if (!range) return undefined;
1731
1546
  const fillOwner = streamInvoke ? createOwner() : null;
1732
- if (fillOwner && key !== undefined && ctx) {
1733
- fillScopes.set(key, fillOwner);
1734
- ctx.onCleanup(() => {
1735
- if (fillScopes.get(key) === fillOwner) fillScopes.delete(key);
1736
- fillOwner.dispose();
1737
- });
1738
- }
1547
+ const owner = fillOwner || createOwner({
1548
+ transparent: true
1549
+ });
1550
+ fillScopes.set(key, owner);
1551
+ ctx.onCleanup(() => {
1552
+ if (fillScopes.get(key) === owner) fillScopes.delete(key);
1553
+ owner.dispose();
1554
+ });
1739
1555
  const evaluate = () => {
1740
1556
  const v = props[prop];
1741
1557
  if (typeof v === "function" && ctx && ctx.invoked) {
@@ -1746,22 +1562,19 @@ function slotsFor(props, scope) {
1746
1562
  };
1747
1563
  const adopted = !!(ctx && ctx.frame && ctx.adopted && ctx.existing && ctx.existing.length);
1748
1564
  const prefix = ctx && ctx.frame ? `sc-${ctx.frame}-${ctx.key}-` : "";
1749
- const value = fillOwner ? runWithOwner(fillOwner, () => adopted ? claimRender(prefix, ctx.existing, evaluate, scope) : evaluate()) : adopted ? claimRender(prefix, ctx.existing, evaluate, scope) : evaluate();
1750
- const owner = fillOwner || createOwner({
1751
- transparent: true
1752
- });
1753
- if (!fillOwner) {
1754
- fillScopes.set(key, owner);
1755
- ctx.onCleanup(() => {
1756
- if (fillScopes.get(key) === owner) fillScopes.delete(key);
1757
- owner.dispose();
1758
- });
1759
- }
1565
+ const claim = adopted && runWithOwner(owner, () => createOwner({
1566
+ id: prefix
1567
+ }));
1568
+ const value = adopted ? claimRender(prefix, claim, ctx.existing, evaluate, scope) : fillOwner ? runWithOwner(fillOwner, evaluate) : evaluate();
1760
1569
  const end = range.end;
1761
1570
  const bind = () => insert(end.parentNode, value, end, [...ctx.existing]);
1762
- runWithOwner(owner, () => adopted ? claimRender(prefix, ctx.existing, bind, scope, true) : bind());
1571
+ adopted ? claimRender(prefix, claim, ctx.existing, bind, scope, true) : runWithOwner(owner, bind);
1763
1572
  return undefined;
1764
1573
  };
1574
+ return (slotProps, ctx) => {
1575
+ const R = tierLoads.regions?.r;
1576
+ R ? R.nest(mount, slotProps, ctx) : mount(slotProps, ctx);
1577
+ };
1765
1578
  }
1766
1579
  });
1767
1580
  }
@@ -1815,7 +1628,12 @@ function pumpLiveChannel() {
1815
1628
  const pump = () => reader.read().then(r => {
1816
1629
  if (r.done) return;
1817
1630
  const op = r.value;
1818
- for (const m of op.type === "ops" ? op.ops : [op]) liveOps.set(`${m.type}:${m.fid || ""}:${m.key || ""}`, m);
1631
+ for (const key in op.r) liveOps.set(`${op.fid || ""}:${key}`, {
1632
+ fid: op.fid,
1633
+ r: {
1634
+ [key]: op.r[key]
1635
+ }
1636
+ });
1819
1637
  for (const apply of liveAppliers) apply(op);
1820
1638
  return pump();
1821
1639
  });
@@ -1830,14 +1648,18 @@ function indexBoundaries(root) {
1830
1648
  if (key && isBoundaryId(key) && !boundaryIndex.has(key)) boundaryIndex.set(key, el);
1831
1649
  });
1832
1650
  }
1833
- function findBoundaryElement(id) {
1651
+ function findBoundaryElement(id, address) {
1834
1652
  if (!boundaryIndex) {
1835
1653
  boundaryIndex = new Map();
1836
1654
  if (typeof document !== "undefined" && document.body) indexBoundaries(document.body);
1837
1655
  }
1656
+ const args = address && address.slice(id.length + 1);
1657
+ let first, el;
1838
1658
  for (let n = 0;; n++) {
1839
1659
  const key = n ? id + "~" + (n + 1) : id;
1840
- if (!claimedBoundaries.has(key)) return boundaryIndex.get(key);
1660
+ if (claimedBoundaries.has(key)) continue;
1661
+ if (!(el = boundaryIndex.get(key)) || !args || el.dataset.fa == args) return el || first;
1662
+ first = first || el;
1841
1663
  }
1842
1664
  }
1843
1665
  const arrivals = new Map();
@@ -1848,17 +1670,29 @@ function awaitBoundary(id) {
1848
1670
  if (!arrival) {
1849
1671
  let resolve;
1850
1672
  const promise = new Promise(r => resolve = r);
1673
+ if (!resolve) return promise;
1851
1674
  arrivals.set(id, arrival = {
1852
1675
  promise,
1853
1676
  resolve
1854
1677
  });
1678
+ onHydrationEnd(releaseArrivals);
1855
1679
  }
1856
1680
  return arrival.promise;
1857
1681
  }
1682
+ function releaseArrivals() {
1683
+ if (!arrivals.size) return;
1684
+ const exhausted = !boundaryMayArrive();
1685
+ for (const [id, arrival] of arrivals) {
1686
+ const el = boundaryIndex && boundaryIndex.get(id);
1687
+ if (!el && !exhausted) continue;
1688
+ arrivals.delete(id);
1689
+ arrival.resolve(!!el);
1690
+ }
1691
+ }
1858
1692
  function boundaryMayArrive() {
1859
1693
  const hy = globalThis._$HY;
1860
1694
  if (!hy) return false;
1861
- return !hy.done || !!(hy.fr && hy.fr.pending());
1695
+ return !(hy.done || sharedConfig.done) || !!(hy.fr && hy.fr.pending());
1862
1696
  }
1863
1697
  function installRevealHook() {
1864
1698
  installServerComponentHydration();
@@ -1873,26 +1707,20 @@ function installRevealHook() {
1873
1707
  if (!boundaryIndex) return;
1874
1708
  const root = parent || (typeof document !== "undefined" ? document.body : null);
1875
1709
  if (root) indexBoundaries(root);
1876
- if (!arrivals.size) return;
1877
- const exhausted = hy.done && !hy.fr.pending();
1878
- for (const [id, arrival] of arrivals) {
1879
- const el = boundaryIndex && boundaryIndex.get(id);
1880
- if (!el && !exhausted) continue;
1881
- arrivals.delete(id);
1882
- arrival.resolve(!!el);
1883
- }
1710
+ releaseArrivals();
1884
1711
  });
1885
1712
  }
1886
1713
  function documentBoundary(host, id, props, binding) {
1887
1714
  installRevealHook();
1888
- const el = findBoundaryElement(id);
1715
+ const address = binding && contentAddress(binding());
1716
+ const el = findBoundaryElement(id, address);
1889
1717
  if (el) return adoptBoundary(host, id, el, props, binding);
1890
1718
  if (!claimedBoundaries.has(id) && boundaryMayArrive()) {
1891
1719
  const owner = getOwner();
1892
1720
  let live = true;
1893
1721
  onCleanup(() => live = false);
1894
1722
  return createMemo(() => awaitBoundary(id).then(() => live && runWithOwner(owner, () => {
1895
- const node = findBoundaryElement(id);
1723
+ const node = findBoundaryElement(id, address);
1896
1724
  return node ? adoptBoundary(host, id, node, props, binding) : boundaryComponent(host, id)(props, binding);
1897
1725
  })));
1898
1726
  }
@@ -1901,6 +1729,7 @@ function documentBoundary(host, id, props, binding) {
1901
1729
  function adoptBoundary(host, id, el, props, binding) {
1902
1730
  const siteId = el.getAttribute(FRAME_ID_ATTR);
1903
1731
  claimedBoundaries.add(siteId);
1732
+ edgeRoots.set(siteId, el);
1904
1733
  const address = binding ? contentAddress(binding()) : id;
1905
1734
  const appliedRecords = new Set();
1906
1735
  const drainRecords = () => {
@@ -1913,11 +1742,14 @@ function adoptBoundary(host, id, el, props, binding) {
1913
1742
  if (key.startsWith(slotPrefix)) {
1914
1743
  appliedRecords.add(key);
1915
1744
  const apply = args => host.apply({
1916
- type: "slot",
1917
1745
  id: address,
1918
1746
  version: 0,
1919
- key: key.slice(slotPrefix.length),
1920
- args
1747
+ r: {
1748
+ [`slot:${key.slice(slotPrefix.length)}`]: {
1749
+ kind: "slot",
1750
+ args
1751
+ }
1752
+ }
1921
1753
  });
1922
1754
  const value = hy.r[key];
1923
1755
  if (value && typeof value.then === "function") {
@@ -1929,10 +1761,14 @@ function adoptBoundary(host, id, el, props, binding) {
1929
1761
  appliedRecords.add(key);
1930
1762
  const val = hy.r[key];
1931
1763
  const apply = html => host.apply({
1932
- type: "html",
1933
1764
  id: childId,
1934
1765
  version: 0,
1935
- html
1766
+ r: {
1767
+ "": {
1768
+ kind: "html",
1769
+ value: html
1770
+ }
1771
+ }
1936
1772
  });
1937
1773
  val && typeof val.then === "function" ? val.then(apply) : apply(val);
1938
1774
  }
@@ -1954,9 +1790,9 @@ function adoptBoundary(host, id, el, props, binding) {
1954
1790
  const applyLiveOp = op => {
1955
1791
  if (op.fid && op.fid !== siteId) return;
1956
1792
  host.apply({
1957
- ...op,
1958
1793
  id: address,
1959
- version: 0
1794
+ version: 0,
1795
+ r: op.r
1960
1796
  });
1961
1797
  };
1962
1798
  liveAppliers.add(applyLiveOp);
@@ -1971,6 +1807,7 @@ function adoptBoundary(host, id, el, props, binding) {
1971
1807
  const [failed, onApply] = failing();
1972
1808
  frame = createFrame(el, {
1973
1809
  adopt: true,
1810
+ defer: true,
1974
1811
  host,
1975
1812
  id: address,
1976
1813
  slots: slotsFor(props, scope),
@@ -1994,6 +1831,163 @@ function adoptBoundary(host, id, el, props, binding) {
1994
1831
  });
1995
1832
  return el;
1996
1833
  }
1834
+ const DEFER_EVENTS = ["click", "input", "change", "keydown", "pointerdown", "submit", "focusin"];
1835
+ const DEFER_BUDGET = 8;
1836
+ let mounting = false;
1837
+ const idleTick = () => new Promise(r => typeof requestIdleCallback === "function" ? requestIdleCallback(() => r(), {
1838
+ timeout: 100
1839
+ }) : setTimeout(r, 0));
1840
+ function wakeAt(e) {
1841
+ const target = e.target;
1842
+ if (!target || mounting) return;
1843
+ mounting = true;
1844
+ try {
1845
+ for (let f; (f = liveFrameAt(target)) && f.mountEnclosing(target););
1846
+ } finally {
1847
+ mounting = false;
1848
+ }
1849
+ deferDone();
1850
+ }
1851
+ function mountAllDeferred() {
1852
+ if (mounting || sharedConfig.hydrating) return;
1853
+ mounting = true;
1854
+ try {
1855
+ for (let frames; (frames = deferredFrames()).length;) for (const f of frames) f.mountDeferred();
1856
+ } finally {
1857
+ mounting = false;
1858
+ }
1859
+ deferDone();
1860
+ }
1861
+ const edgeRoots = new Map();
1862
+ let edgeIndex;
1863
+ const DEPS = "sc:deps:";
1864
+ function buildEdgeIndex() {
1865
+ const r = globalThis._$HY?.r;
1866
+ if (!r) return undefined;
1867
+ const idx = {
1868
+ readers: new Map(),
1869
+ wide: new Set(),
1870
+ untracked: [],
1871
+ sites: new Set(),
1872
+ starts: new Map()
1873
+ };
1874
+ for (const site of edgeRoots.keys()) for (let n = 0, batch; batch = r[DEPS + site + ":" + n]; n++) {
1875
+ if (typeof batch !== "object") return undefined;
1876
+ idx.sites.add(site);
1877
+ for (const sid in batch) {
1878
+ const occs = unpackOccurrences(batch[sid]);
1879
+ if (sid === "*") occs.forEach(w => idx.wide.add(w));else if (sid === "!") occs.forEach(o => idx.untracked.push([site, o]));else {
1880
+ let list = idx.readers.get(sid);
1881
+ if (!list) idx.readers.set(sid, list = []);
1882
+ for (const o of occs) list.push([site, o]);
1883
+ }
1884
+ }
1885
+ }
1886
+ return idx;
1887
+ }
1888
+ function unpackOccurrences(packed) {
1889
+ const out = [];
1890
+ for (const part of packed.split(" ")) {
1891
+ const m = /^(.*)#(\d+)-(\d+)$/.exec(part);
1892
+ if (!m) part && out.push(part);else for (let i = +m[2]; i <= +m[3]; i++) out.push(m[1] + "#" + i);
1893
+ }
1894
+ return out;
1895
+ }
1896
+ function startOf(idx, site, occ) {
1897
+ let m = idx.starts.get(site);
1898
+ if (!m) {
1899
+ idx.starts.set(site, m = new Map());
1900
+ const root = edgeRoots.get(site);
1901
+ if (root) {
1902
+ const w = document.createTreeWalker(root, 128 );
1903
+ for (let c = w.nextNode(); c; c = w.nextNode()) {
1904
+ const d = c.data;
1905
+ if (d.startsWith("slot:") && d.endsWith(":start")) m.set(d.slice(5, -6), c);
1906
+ }
1907
+ }
1908
+ }
1909
+ return m.get(occ);
1910
+ }
1911
+ function edgesCover(idx) {
1912
+ outer: for (const f of deferredFrames()) {
1913
+ for (const [site, root] of edgeRoots) if (idx.sites.has(site) && root.contains(f.el)) continue outer;
1914
+ return false;
1915
+ }
1916
+ return true;
1917
+ }
1918
+ function mountForWrite(node) {
1919
+ if (mounting || sharedConfig.hydrating) return;
1920
+ const sid = signalName(node) ?? storeName(node);
1921
+ if (sid === undefined || document.readyState === "loading") return mountAllDeferred();
1922
+ const idx = edgeIndex ||= buildEdgeIndex();
1923
+ if (!idx || idx.wide.has(sid) || !edgesCover(idx)) return mountAllDeferred();
1924
+ const readers = idx.readers.get(sid);
1925
+ if (!readers && !idx.untracked.length) return;
1926
+ mounting = true;
1927
+ try {
1928
+ for (const list of [readers || [], idx.untracked]) for (const [site, occ] of list) {
1929
+ const root = edgeRoots.get(site);
1930
+ if (root && deferredFrames().some(f => root.contains(f.el) && f.mountOccurrence(occ))) continue;
1931
+ const start = startOf(idx, site, occ);
1932
+ const target = start && (start.nextSibling || start);
1933
+ if (target) for (let f; (f = liveFrameAt(target)) && f.mountEnclosing(target););
1934
+ }
1935
+ } finally {
1936
+ mounting = false;
1937
+ }
1938
+ deferDone();
1939
+ }
1940
+ let idlePass;
1941
+ function mountIdle() {
1942
+ return idlePass ||= (async () => {
1943
+ if (document.readyState !== "complete") await new Promise(r => addEventListener("load", r, {
1944
+ once: true
1945
+ }));
1946
+ globalThis._$HY?.r?.["sc:tiers"]?.forEach(prepareTier);
1947
+ await Promise.all(Object.values(tierLoads)).catch(() => {});
1948
+ for (let frames; (frames = deferredFrames()).length;) {
1949
+ await idleTick();
1950
+ const deadline = performance.now() + DEFER_BUDGET;
1951
+ mounting = true;
1952
+ try {
1953
+ for (const f of frames) if (!f.mountDeferred(deadline) || performance.now() > deadline) break;
1954
+ } finally {
1955
+ mounting = false;
1956
+ }
1957
+ }
1958
+ idlePass = undefined;
1959
+ deferDone();
1960
+ })();
1961
+ }
1962
+ function deferDone() {
1963
+ if (deferredFrames().length) return;
1964
+ if (deferring) {
1965
+ deferring = false;
1966
+ edgeIndex = undefined;
1967
+ setWriteHook(null);
1968
+ DEFER_EVENTS.forEach(t => document.removeEventListener(t, wakeAt, true));
1969
+ }
1970
+ releaseDeferHolds();
1971
+ }
1972
+ let deferHydration = true;
1973
+ function setDeferredHydration(on) {
1974
+ deferHydration = on;
1975
+ setDeferDriver(on && typeof document !== "undefined" ? deferFrame : null);
1976
+ setSignalIdentities(on && typeof document !== "undefined");
1977
+ }
1978
+ let deferring = false;
1979
+ function deferFrame(frame) {
1980
+ if (!deferring) {
1981
+ deferring = true;
1982
+ setWriteHook(mountForWrite);
1983
+ DEFER_EVENTS.forEach(t => document.addEventListener(t, wakeAt, true));
1984
+ }
1985
+ const queued = sharedConfig.events;
1986
+ if (queued && queued.length) for (const [el, e] of queued) if (frame.el.contains(el)) wakeAt({
1987
+ target: e.target ?? el
1988
+ });
1989
+ mountIdle();
1990
+ }
1997
1991
  function installServerComponents(host = getFrameHost(), options) {
1998
1992
  const g = globalThis;
1999
1993
  Object.assign(tierLoaders, options?.tiers);
@@ -2019,6 +2013,10 @@ function installServerComponents(host = getFrameHost(), options) {
2019
2013
  }
2020
2014
  g._$SC.impl = (id, props, binding) => documentBoundary(host, id, props, binding);
2021
2015
  installRevealHook();
2016
+ if (typeof document !== "undefined" && deferHydration) {
2017
+ setDeferDriver(deferFrame);
2018
+ setSignalIdentities(true);
2019
+ }
2022
2020
  const handler = createServerComponentHandler({
2023
2021
  host,
2024
2022
  component: fnId => g._$SC.r(fnId),
@@ -2040,4 +2038,4 @@ function installServerComponents(host = getFrameHost(), options) {
2040
2038
  });
2041
2039
  }
2042
2040
 
2043
- export { FRAME_APPLIED_EVENT, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents, isAsyncValue, isFrameStreamResponse };
2041
+ export { FRAME_APPLIED_EVENT, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents, isFrameStreamResponse, setDeferredHydration };