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

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 (55) hide show
  1. package/README.md +1 -1
  2. package/dist/server.dev.js +361 -483
  3. package/dist/server.js +346 -391
  4. package/dist/server.observe.js +346 -391
  5. package/dist/web.dev.js +110 -55
  6. package/dist/web.js +51 -50
  7. package/dist/web.observe.js +61 -55
  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 +793 -424
  13. package/frames/dist/server.js +792 -371
  14. package/frames/dist/server.observe.js +792 -371
  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 +13 -22
  21. package/server-functions/dist/client.js +11 -22
  22. package/server-functions/dist/client.observe.js +13 -22
  23. package/server-functions/dist/rich-args.js +84 -1
  24. package/server-functions/dist/server.dev.js +194 -20
  25. package/server-functions/dist/server.js +194 -20
  26. package/server-functions/dist/server.observe.js +194 -20
  27. package/skills/server-components/SKILL.md +74 -185
  28. package/types/client.d.ts +27 -5
  29. package/types/diagnostics.d.ts +16 -0
  30. package/types/frames/assets-tier.d.ts +2 -2
  31. package/types/frames/client.d.ts +8 -3
  32. package/types/frames/frame-client.d.ts +121 -157
  33. package/types/frames/frame-morph.d.ts +28 -0
  34. package/types/frames/frame-sink.d.ts +13 -9
  35. package/types/frames/frame-transport.d.ts +30 -1
  36. package/types/frames/regions-tier.d.ts +15 -0
  37. package/types/frames/serializer-decode.d.ts +2 -2
  38. package/types/frames/server.d.ts +0 -52
  39. package/types/frames/wire-tier.d.ts +54 -1
  40. package/types/index.d.ts +2 -2
  41. package/types/jsx.d.ts +11 -5
  42. package/types/observe.d.ts +14 -7
  43. package/types/render.d.ts +3 -1
  44. package/types/response.d.ts +5 -4
  45. package/types/serializer-decode.d.ts +2 -2
  46. package/types/server-functions/argument-codec.d.ts +30 -0
  47. package/types/server-functions/client.d.ts +27 -9
  48. package/types/server-functions/server.d.ts +23 -2
  49. package/types/server-functions/shared.d.ts +19 -0
  50. package/types/server-functions/uploads.d.ts +50 -0
  51. package/types/server-observe.d.ts +3 -2
  52. package/types/server.d.ts +58 -77
  53. package/frames/dist/bind.dev.js +0 -326
  54. package/frames/dist/bind.js +0 -295
  55. package/types/frames/bind-tier.d.ts +0 -60
@@ -1,10 +1,9 @@
1
- import { getOwner, onCleanup, createMemo, runWithOwner, untrack, createRenderEffect, createSignal, createOwner } from 'solid-js';
1
+ import { getOwner, onCleanup, createMemo, runWithOwner, untrack, createRenderEffect, onHydrationEnd, createSignal, createOwner } from 'solid-js';
2
2
  import { installServerComponentHydration, insert } from '@solidjs/web';
3
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';
4
+ import { setSignalIdentities, sharedConfig, createLoadingBoundary, setWriteHook, signalName, storeName } from 'solid-js/internal';
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,43 @@ 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
+ } else if (lands(records)) {
245
173
  store.open = false;
246
174
  store.shown = r = store.records;
247
- store.shownVersion = chunk.version;
248
- const landed = landings.get(chunk.id);
175
+ store.shownVersion = msg.version;
176
+ const landed = landings.get(msg.id);
249
177
  if (landed && !(":complete" in records && ":error" in r)) {
250
- landings.delete(chunk.id);
178
+ landings.delete(msg.id);
251
179
  ":error" in records ? landed.j(records[":error"]) : landed.r();
252
180
  }
253
181
  }
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"]);
182
+ applyTo(msg.id, msg.version, r);
183
+ if (":complete" in records || ":error" in records) options.closeData && options.closeData(msg.id, msg.version, records[":error"]);
256
184
  },
257
185
  landing(id) {
258
186
  const store = stores.get(id);
@@ -265,14 +193,17 @@ function createFrameHost(options = {}) {
265
193
  }
266
194
  return wait.p;
267
195
  },
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);
196
+ preview(msg) {
197
+ const set = frames.get(msg.id);
198
+ if (!set || !msg.r) return;
199
+ let records;
200
+ for (const key in msg.r) if (key.startsWith("slot:")) {
201
+ const record = (records ??= {})[key] = {
202
+ ...msg.r[key]
203
+ };
204
+ settleArgs(storeFor(msg.id), key, record, msg);
205
+ }
206
+ if (records) for (const frame of set) frame.preview && frame.preview(records);
276
207
  },
277
208
  get(id) {
278
209
  const set = frames.get(id);
@@ -290,6 +221,26 @@ const FRAME_APPLIED_EVENT = "frame:applied";
290
221
  const tierLoaders = {};
291
222
  const tierLoads = {};
292
223
  const liveFrames = new Set();
224
+ let deferDriver = null;
225
+ function setDeferDriver(driver) {
226
+ deferDriver = driver;
227
+ }
228
+ function deferredFrames() {
229
+ return [...liveFrames].filter(f => f.deferred);
230
+ }
231
+ function releaseDeferHolds() {
232
+ for (const f of liveFrames) f.releaseDeferHold();
233
+ }
234
+ function hasSlotRange(root) {
235
+ const w = root.ownerDocument.createTreeWalker(root, 0x80);
236
+ for (let n; n = w.nextNode();) if (n.data.startsWith("slot:")) return true;
237
+ return false;
238
+ }
239
+ function liveFrameAt(node) {
240
+ let hit;
241
+ for (const f of liveFrames) if (f.el.contains(node) && (!hit || hit.el.contains(f.el))) hit = f;
242
+ return hit;
243
+ }
293
244
  function prepareTier(name) {
294
245
  let load = tierLoads[name];
295
246
  if (!load) {
@@ -305,6 +256,7 @@ function prepareTier(name) {
305
256
  }
306
257
  return load;
307
258
  }
259
+ const prepareMorph = () => liveFrames.size && prepareTier("wire");
308
260
  const tierReady = name => !tierLoaders[name] || prepareTier(name).r;
309
261
  const needsRegions = record => record.regions && !tierReady("regions");
310
262
  const carriesTrace = value => value != null && typeof value === "object" && (value.$tr != null || Object.values(value).some(carriesTrace));
@@ -315,10 +267,14 @@ class FrameImpl {
315
267
  #outer;
316
268
  #version;
317
269
  #store = Object.create(null);
270
+ #content = new Set();
318
271
  #appliedRoot;
319
272
  #appliedError;
320
273
  #hasContent = false;
321
274
  #appliedHoles = new Map();
275
+ #liveTargets = new Map();
276
+ #shows = {};
277
+ #liveMount;
322
278
  #slots;
323
279
  #mountedSlots = new Set();
324
280
  #slotCleanups = new Map();
@@ -326,11 +282,19 @@ class FrameImpl {
326
282
  #slotUpdaters = new Map();
327
283
  #hold;
328
284
  #heldRecords = new Map();
285
+ #found;
286
+ #waiting = new Set();
329
287
  #disposed = false;
330
- #claimTree = (node, direct) => {
288
+ #defers = false;
289
+ #deferred = false;
290
+ #deferFound;
291
+ #deferWaiting = false;
292
+ #deferMounted = new Map();
293
+ #deferHold;
294
+ #claimTree = (node, direct, adopter) => {
331
295
  const handlers = claimHandlers();
332
296
  if (!handlers) return;
333
- this.#scoped(() => direct ? claimNode(handlers, node) : claimTree(handlers, node));
297
+ this.#scoped(() => direct ? claimNode(handlers, node) : claimTree(handlers, node, adopter));
334
298
  };
335
299
  #scoped(fn) {
336
300
  const scope = this.#options.ownerScope;
@@ -345,11 +309,16 @@ class FrameImpl {
345
309
  if (options.adopt) {
346
310
  this.#hasContent = true;
347
311
  this.#claimContent();
312
+ this.#defers = !!deferDriver && !!(options.defer || this.#outer?.defers);
313
+ this.#deferred = this.#defers && !!(this.#slots || this.#outer) && hasSlotRange(element);
348
314
  }
349
315
  if (options.host && options.id !== undefined) {
350
316
  options.host.register(options.id, this);
351
317
  }
352
- if (options.adopt && this.#version === undefined) this.#syncSlots();
318
+ if (this.#deferred) {
319
+ this.#deferHold = options.hold?.();
320
+ deferDriver(this);
321
+ } else if (options.adopt && this.#version === undefined) this.#syncSlots();
353
322
  }
354
323
  #applied(version, reason) {
355
324
  this.#options.onApply?.({
@@ -389,8 +358,15 @@ class FrameImpl {
389
358
  this.#version = v;
390
359
  this.#resetStreamState();
391
360
  }
392
- for (const key in write.r) this.#store[key] = write.r[key];
393
- this.#flush();
361
+ let only = [];
362
+ for (const key in write.r) {
363
+ const prev = this.#store[key];
364
+ const occurrence = key.slice(5);
365
+ if (this.#deferred && prev?.kind === "slot" && !prev.pending && !this.#mountedSlots.has(occurrence)) this.#heldRecords.has(occurrence) || this.#heldRecords.set(occurrence, prev);
366
+ this.#store[key] = write.r[key];
367
+ if (key.startsWith("slot:")) only?.push(occurrence);else this.#content.add(key), only = undefined;
368
+ }
369
+ this.#flush(only?.length ? only : undefined);
394
370
  }
395
371
  preview(records, inherited) {
396
372
  const adopted = new Set();
@@ -412,17 +388,25 @@ class FrameImpl {
412
388
  return adopted;
413
389
  }
414
390
  #resetStreamState() {
391
+ if (this.#hasContent) prepareTier("wire");
392
+ this.#found = undefined;
415
393
  this.#store = Object.create(null);
394
+ this.#content.clear();
416
395
  this.#appliedRoot = this.#appliedError = undefined;
417
396
  this.#appliedHoles.clear();
397
+ this.#liveTargets.clear();
398
+ this.#shows = {};
418
399
  }
419
- #flush() {
400
+ #flush(only) {
420
401
  if (this.#disposed) return;
421
402
  const version = this.#version;
422
403
  const root = this.#store[""];
404
+ const applied = this.#appliedRoot;
423
405
  if (root && root.kind === "html" && root !== this.#appliedRoot) {
424
- const reason = this.#hasContent ? "morph" : "materialize";
425
- this.#applyRoot(root.value);
406
+ const wire = this.#hasContent ? tierReady("wire") : null;
407
+ if (wire === undefined) return;
408
+ const reason = wire ? "morph" : "materialize";
409
+ this.#applyRoot(root.value, wire);
426
410
  this.#appliedRoot = root;
427
411
  this.#recordHave("", root);
428
412
  this.#applied(version, reason);
@@ -432,7 +416,7 @@ class FrameImpl {
432
416
  this.#appliedError = error;
433
417
  this.#applied(version, "error");
434
418
  }
435
- for (const key in this.#store) {
419
+ for (const key of this.#content) {
436
420
  const record = this.#store[key];
437
421
  if (!key.endsWith(":assets") || !record || this.#appliedHoles.get(key) === record) continue;
438
422
  const tier = tierReady("assets");
@@ -440,28 +424,57 @@ class FrameImpl {
440
424
  this.#appliedHoles.set(key, record);
441
425
  tier.apply(record);
442
426
  }
443
- this.#revealSegments();
427
+ const revealed = this.#revealSegments();
444
428
  let morphed = false;
445
- for (const key in this.#store) {
429
+ const index = {};
430
+ let wire;
431
+ for (const key of this.#content) {
446
432
  const record = this.#store[key];
447
433
  if (!record || this.#appliedHoles.get(key) === record) continue;
448
434
  if (key.startsWith("hole:")) {
449
435
  if (key.endsWith(":error")) {
450
436
  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;
437
+ continue;
461
438
  }
439
+ } else if (!key.startsWith("attr:")) continue;
440
+ if (!this.#hasContent || !(wire ??= tierReady("wire"))) continue;
441
+ const name = key.slice(5);
442
+ const attr = key[0] === "a";
443
+ if (!attr) this.#found = undefined;
444
+ if (attr ? wire.attrs(this.#live, name, record) : wire.hole(this.#live, name, record, index)) {
445
+ this.#appliedHoles.set(key, record);
446
+ this.#recordHave(attr ? "lha:" + name : name, record);
447
+ morphed = true;
462
448
  }
463
449
  }
450
+ if (index.r?.size) wire.graft(index.g, index.r);
464
451
  if (morphed) this.#applied(version, "morph");
452
+ if (this.#deferred) {
453
+ if (!morphed && this.#appliedRoot === applied) {
454
+ if (revealed || !only) this.#deferFound = undefined;
455
+ const mounted = only ? new Map() : new Map(this.#deferMounted);
456
+ if (only) for (const id of only) {
457
+ const start = this.#deferMounted.get(id);
458
+ if (start) mounted.set(id, start);else if (!this.#deferFound?.has(id)) this.#deferFound = undefined;
459
+ }
460
+ if (mounted.size) this.#deferWaiting = this.#mountFound(mounted) || this.#deferWaiting;
461
+ return;
462
+ }
463
+ this.#deferred = false;
464
+ this.#deferFound = undefined;
465
+ this.#deferMounted.clear();
466
+ }
467
+ const found = this.#found;
468
+ if (only && found && this.#appliedRoot === applied) {
469
+ const sub = new Map();
470
+ for (const id of only) {
471
+ const start = found.get(id);
472
+ if (!start?.isConnected) return this.#syncSlots();
473
+ sub.set(id, start);
474
+ }
475
+ this.#mountFound(sub);
476
+ return this.#holdIf(this.#waiting.size);
477
+ }
465
478
  this.#syncSlots();
466
479
  }
467
480
  #resolveSlot(prop) {
@@ -481,25 +494,36 @@ class FrameImpl {
481
494
  #syncSlots(root) {
482
495
  if (!this.#slots && !this.#outer) return;
483
496
  const found = new Map();
484
- if (root) collectSlots(root, found, found);else this.#collectSlots(found, found);
497
+ this.#collectSlots(found, root);
498
+ if (root) this.#found = undefined;else this.#found = found, this.#waiting.clear();
499
+ const waiting = this.#mountFound(found);
500
+ if (!root) {
501
+ for (const occurrence of [...this.#mountedSlots]) {
502
+ if (!found.has(occurrence)) this.#unmountSlot(occurrence);
503
+ }
504
+ this.#holdIf(waiting);
505
+ }
506
+ }
507
+ #holdIf(waiting) {
508
+ if (waiting && !this.#hold) this.#hold = this.#options.hold?.();else if (!waiting && this.#hold) this.#releaseHold();
509
+ }
510
+ #mountFound(found) {
485
511
  let waiting = false;
486
512
  const R = tierLoads.regions?.r;
487
- const B = tierLoads.bind?.r;
488
513
  for (const [occurrence, start] of found) {
514
+ this.#waiting.delete(occurrence);
489
515
  const callback = this.#resolveSlot(propOf(occurrence));
490
- const consumers = Array.isArray(start) ? start : null;
491
- if (!callback) {
492
- continue;
493
- }
516
+ if (!callback) continue;
494
517
  const record = this.#resolveSlotRecord(occurrence);
495
518
  const mounted = this.#mountedSlots.has(occurrence);
496
519
  if (record === undefined && isCalled(occurrence)) {
497
- waiting ||= !mounted;
520
+ if (!mounted) waiting = true, this.#waiting.add(occurrence);
498
521
  continue;
499
522
  }
500
523
  if (!mounted && record && (record.pending || needsRegions(record) || needsTrace(record.args))) {
501
524
  waiting = true;
502
- if (this.#options.adopt && !consumers) this.#heldRecords.has(occurrence) || this.#heldRecords.set(occurrence, record);
525
+ this.#waiting.add(occurrence);
526
+ if (this.#options.adopt) this.#heldRecords.has(occurrence) || this.#heldRecords.set(occurrence, record);
503
527
  continue;
504
528
  }
505
529
  if (!mounted) {
@@ -507,12 +531,10 @@ class FrameImpl {
507
531
  this.#heldRecords.delete(occurrence);
508
532
  const mountRecord = held || record;
509
533
  this.#invokeSlot(occurrence, callback, mountRecord, start, this.#options.adopt);
510
- if (consumers) B.sync(this, occurrence, consumers);
511
534
  this.#mountedSlots.add(occurrence);
512
535
  R?.bind(this, occurrence);
513
536
  if (mountRecord === record || !record || record.kind !== "slot") continue;
514
537
  }
515
- if (consumers) B.sync(this, occurrence, consumers);
516
538
  if (record !== this.#slotArgs.get(occurrence)) {
517
539
  if (needsRegions(record) || needsTrace(record.args)) continue;
518
540
  const update = this.#slotUpdaters.get(occurrence);
@@ -527,13 +549,77 @@ class FrameImpl {
527
549
  R?.bind(this, occurrence);
528
550
  }
529
551
  }
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);
552
+ return waiting;
553
+ }
554
+ get el() {
555
+ return this.#element;
556
+ }
557
+ get defers() {
558
+ return this.#defers;
559
+ }
560
+ get deferred() {
561
+ return this.#deferred;
562
+ }
563
+ mountEnclosing(target) {
564
+ if (!this.#deferred) return false;
565
+ const root = this.#element;
566
+ let outer;
567
+ for (let node = target; node && node !== root; node = node.parentNode) {
568
+ let depth = 0;
569
+ for (let s = node.previousSibling; s; s = s.previousSibling) {
570
+ if (s.nodeType !== COMMENT_NODE || !s.data.startsWith("slot:")) continue;
571
+ if (SLOT_END.test(s.data)) depth++;else if (depth) depth--;else outer = s;
534
572
  }
535
- if (waiting && !this.#hold) this.#hold = this.#options.hold?.();else if (!waiting && this.#hold) this.#releaseHold();
536
573
  }
574
+ const id = outer && slotStartId(outer);
575
+ if (!id || this.#mountedSlots.has(id)) return false;
576
+ return this.#mountOne(id, outer);
577
+ }
578
+ #mountOne(id, start) {
579
+ const mount = () => {
580
+ this.#deferWaiting = this.#mountFound(new Map([[id, start]])) || this.#deferWaiting;
581
+ };
582
+ mount();
583
+ if (!this.#mountedSlots.has(id)) return false;
584
+ this.#deferMounted.set(id, start);
585
+ return true;
586
+ }
587
+ mountDeferred(deadline) {
588
+ if (!this.#deferred) return true;
589
+ let found = this.#deferFound;
590
+ if (!found) {
591
+ found = this.#deferFound = new Map();
592
+ this.#collectSlots(found);
593
+ }
594
+ for (const [id, start] of found) {
595
+ found.delete(id);
596
+ if (this.#mountedSlots.has(id)) this.#deferWaiting = this.#mountFound(new Map([[id, start]])) || this.#deferWaiting;else this.#mountOne(id, start);
597
+ if (deadline !== undefined && found.size && performance.now() > deadline) return false;
598
+ }
599
+ this.#deferred = false;
600
+ this.#deferFound = undefined;
601
+ this.#deferMounted.clear();
602
+ if (this.#deferWaiting && !this.#hold) this.#hold = this.#options.hold?.();
603
+ return true;
604
+ }
605
+ mountOccurrence(id) {
606
+ if (!this.#deferred) return false;
607
+ if (this.#mountedSlots.has(id)) return true;
608
+ let found = this.#deferFound;
609
+ if (!found) {
610
+ found = this.#deferFound = new Map();
611
+ this.#collectSlots(found);
612
+ }
613
+ const start = found.get(id);
614
+ if (!start) return false;
615
+ found.delete(id);
616
+ this.#mountOne(id, start);
617
+ return true;
618
+ }
619
+ releaseDeferHold() {
620
+ const release = this.#deferHold;
621
+ this.#deferHold = undefined;
622
+ release && release();
537
623
  }
538
624
  #releaseHold() {
539
625
  const release = this.#hold;
@@ -545,8 +631,7 @@ class FrameImpl {
545
631
  const cleanups = this.#slotCleanups.get(occurrence) ?? [];
546
632
  let existing = [];
547
633
  let end = null;
548
- const positions = Array.isArray(start) ? start : undefined;
549
- if (start && !positions) end = eachInRange(start, occurrence, n => existing.push(n));
634
+ if (start) end = eachInRange(start, occurrence, n => existing.push(n));
550
635
  const ctx = {
551
636
  frame: this.#options.claimScope ?? this.#options.id,
552
637
  key: occurrence,
@@ -558,9 +643,7 @@ class FrameImpl {
558
643
  range: end ? {
559
644
  start,
560
645
  end
561
- } : undefined,
562
- positions,
563
- onRebind: positions ? fn => tierLoads.bind.r.rebinder(this, occurrence, fn) : undefined
646
+ } : undefined
564
647
  };
565
648
  const props = record && record.kind === "slot" ? this.#resolveArgs(occurrence, record, adopted, start) : {};
566
649
  this.#scoped(() => callback(props, ctx));
@@ -575,7 +658,6 @@ class FrameImpl {
575
658
  this.#removeSlotRecord(key);
576
659
  this.#runSlotCleanups(key);
577
660
  tierLoads.regions?.r?.unmount(this, key);
578
- tierLoads.bind?.r?.unmount(this, key);
579
661
  }
580
662
  #runSlotCleanups(key) {
581
663
  const cleanups = this.#slotCleanups.get(key);
@@ -602,8 +684,8 @@ class FrameImpl {
602
684
  if (regions) tierLoads.regions.r.resolve(this, slotKey, regions, props, claiming && start);
603
685
  return props;
604
686
  }
605
- #collectSlots(found, elements) {
606
- collectSlots(this.#element, found, elements);
687
+ #collectSlots(found, root) {
688
+ collectSlots(root || this.#element, found);
607
689
  }
608
690
  #findPlaceholder(name, root) {
609
691
  return findPlaceholder((root || this.#element).firstChild, null, placeholderId(name));
@@ -630,7 +712,23 @@ class FrameImpl {
630
712
  this.#resetStreamState();
631
713
  if (host) host.register(id, this);
632
714
  }
715
+ get #live() {
716
+ return this.#liveMount ??= {
717
+ e: this.#element,
718
+ t: this.#liveTargets,
719
+ c: this.#claimTree,
720
+ k: found => this.#collectSlots(found),
721
+ s: () => this.#shows,
722
+ x: (key, record) => (this.#appliedHoles.set(key, record), tierLoads.wire.r.cancel(this.#options.host, this.#options.id)),
723
+ w: false
724
+ };
725
+ }
633
726
  #recordHave(key, record) {
727
+ this.#shows = key ? Object.assign(this.#shows, {
728
+ [key]: record.digest
729
+ }, record.holes) : {
730
+ ...record.holes
731
+ };
634
732
  tierLoads.wire?.r?.have(this, key, record);
635
733
  }
636
734
  dispose() {
@@ -643,12 +741,16 @@ class FrameImpl {
643
741
  this.#disposed = true;
644
742
  liveFrames.delete(this);
645
743
  this.#releaseHold();
744
+ this.releaseDeferHold();
646
745
  for (const key of [...this.#slotCleanups.keys()]) this.#runSlotCleanups(key);
647
746
  for (const key of this.#mountedSlots) this.#removeSlotRecord(key);
648
747
  tierLoads.regions?.r?.unmount(this);
649
748
  this.#mountedSlots.clear();
650
749
  }
651
- #applyRoot(html) {
750
+ #applyRoot(html, wire) {
751
+ this.#found = undefined;
752
+ this.#liveTargets.clear();
753
+ this.#shows = {};
652
754
  const fragment = parseFragment(html);
653
755
  const parent = this.#element;
654
756
  if (!this.#hasContent) {
@@ -660,62 +762,16 @@ class FrameImpl {
660
762
  const claim = this.#claimTree;
661
763
  const ranges = new Map();
662
764
  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;
765
+ wire.morph(parent, fragment, claim, ranges);
675
766
  }
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);
710
- }
711
- return true;
712
767
  }
713
768
  #claimContent() {
714
- for (let n = this.#element.firstChild; n; n = n.nextSibling) this.#claimTree(n);
769
+ for (let n = this.#element.firstChild; n; n = n.nextSibling) this.#claimTree(n, false, this);
715
770
  }
716
771
  #revealSegments(root) {
717
772
  const version = this.#version;
718
- for (const key in this.#store) {
773
+ let revealed = false;
774
+ for (const key of this.#content) {
719
775
  const record = this.#store[key];
720
776
  const name = segmentName(key);
721
777
  if (name === null || !record || this.#appliedHoles.get(key) === record) continue;
@@ -723,9 +779,10 @@ class FrameImpl {
723
779
  this.#appliedHoles.set(key, record);
724
780
  this.#revealSegment(name, root);
725
781
  this.#applied(version, "reveal");
782
+ revealed = true;
726
783
  }
727
784
  }
728
- for (const key in this.#store) {
785
+ for (const key of this.#content) {
729
786
  const m = /^seg:([^:]+):fallback$/.exec(key);
730
787
  if (!m || this.#appliedHoles.has(key) || this.#appliedHoles.has(`seg:${m[1]}`)) continue;
731
788
  if (this.#showFallback(m[1], root)) {
@@ -733,6 +790,7 @@ class FrameImpl {
733
790
  this.#applied(version, "reveal");
734
791
  }
735
792
  }
793
+ return revealed;
736
794
  }
737
795
  #segmentReady(name, root) {
738
796
  const content = this.#store[`seg:${name}`];
@@ -745,6 +803,7 @@ class FrameImpl {
745
803
  #revealSegment(name, root) {
746
804
  const tpl = this.#findPlaceholder(name, root);
747
805
  if (!tpl) return;
806
+ this.#found = undefined;
748
807
  const content = this.#store[`seg:${name}`];
749
808
  const closing = rangeClose(tpl, placeholderId(name));
750
809
  if (!closing) {
@@ -804,9 +863,6 @@ function makeFrameElement(id) {
804
863
  if (id !== undefined) el.setAttribute(FRAME_ID_ATTR, id);
805
864
  return el;
806
865
  }
807
- function isFrameElement(node) {
808
- return node.nodeType === ELEMENT_NODE && node.hasAttribute(FRAME_ID_ATTR);
809
- }
810
866
  function segmentName(key) {
811
867
  const m = /^seg:([^:]+)$/.exec(key);
812
868
  return m ? m[1] : null;
@@ -845,20 +901,6 @@ function rangeClose(start, id) {
845
901
  }
846
902
  return null;
847
903
  }
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
904
  function findPlaceholder(n, end, id) {
863
905
  while (n && n !== end) {
864
906
  if (isPlaceholderStart(n, id)) return n;
@@ -870,38 +912,23 @@ function findPlaceholder(n, end, id) {
870
912
  }
871
913
  return null;
872
914
  }
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);
915
+ function collectSlots(root, out) {
916
+ const w = root.ownerDocument.createTreeWalker(root, 0x80);
878
917
  let n, p;
879
918
  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;
919
+ if (!n.data.startsWith("slot:")) continue;
920
+ const id = slotStartId(n);
921
+ if (!id) continue;
922
+ for (p = n.parentNode; p !== root; p = p.parentNode) if (p.hasAttribute(FRAME_ID_ATTR)) break;
923
+ if (p !== root) continue;
924
+ if (!out.has(id)) out.set(id, n);
925
+ const end = findMarker(n, slotEnd(id));
926
+ if (end) {
927
+ w.currentNode = end;
903
928
  continue;
904
929
  }
930
+ p = n.parentNode;
931
+ if (p === root) return;
905
932
  while (p.lastChild) p = p.lastChild;
906
933
  w.currentNode = p;
907
934
  }
@@ -921,74 +948,6 @@ function slotStartId(node) {
921
948
  const m = SLOT_START.exec(node.data);
922
949
  return m ? m[1] : null;
923
950
  }
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
951
  function findMarker(start, end) {
993
952
  let n = start.nextSibling;
994
953
  while (n) {
@@ -997,163 +956,6 @@ function findMarker(start, end) {
997
956
  }
998
957
  return null;
999
958
  }
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
959
 
1158
960
  const FRAME_STREAM_HEADER = "X-Frame-Stream";
1159
961
  const FRAME_TIERS_HEADER = "X-Frame-Tiers";
@@ -1161,6 +963,11 @@ function isFrameStreamResponse(response) {
1161
963
  return response.headers.has(FRAME_STREAM_HEADER);
1162
964
  }
1163
965
  const applyFrameResponse = applyFrames;
966
+ const ends = msg => !!msg.r && (":complete" in msg.r || ":error" in msg.r);
967
+ const readsData = msg => {
968
+ 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;
969
+ return false;
970
+ };
1164
971
  function applyFrames(response, host, options = {}, observation) {
1165
972
  const rootId = response.headers.get(FRAME_STREAM_HEADER) ?? "";
1166
973
  response.headers.get(FRAME_TIERS_HEADER)?.split(",").forEach(prepareTier);
@@ -1170,11 +977,12 @@ function applyFrames(response, host, options = {}, observation) {
1170
977
  const reader = options[LIVE_WIRE] || new ChunkReader(response.body);
1171
978
  const open = new Map();
1172
979
  const errorRecord = (id, error) => ({
1173
- type: "error",
1174
980
  id,
1175
981
  version: open.get(id),
1176
- error: {
1177
- message: String(error && error.message)
982
+ r: {
983
+ ":error": {
984
+ message: String(error && error.message)
985
+ }
1178
986
  }
1179
987
  });
1180
988
  const drain = async () => {
@@ -1191,9 +999,9 @@ function applyFrames(response, host, options = {}, observation) {
1191
999
  if (v === undefined) perFrame.set(chunk.id, v = version(chunk.id));
1192
1000
  chunk.version = v;
1193
1001
  } else if (version !== undefined) chunk.version = version;
1194
- if (chunk.type === "start") open.set(chunk.id, chunk.version);else if (chunk.type === "complete" || chunk.type === "error" && !chunk.key) open.delete(chunk.id);
1002
+ if (chunk.type === "start") open.set(chunk.id, chunk.version);else if (ends(chunk)) open.delete(chunk.id);
1195
1003
  const needs = chunk.tiers?.map(prepareTier) || [];
1196
- if (chunk.type === "data" || chunk.type === "slot" && Object.values(chunk.args).some(v => v && v.$ref)) await Promise.all([host.prepareData?.(), ...needs]);
1004
+ if (chunk.type === "data" || readsData(chunk)) await Promise.all([host.prepareData?.(), ...needs]);
1197
1005
  host.apply(chunk);
1198
1006
  }
1199
1007
  result = await reader.next();
@@ -1353,7 +1161,7 @@ function createServerComponentHandler({
1353
1161
  return {
1354
1162
  intercept: intercept && (info => {
1355
1163
  const hit = intercept(info);
1356
- if (hit === undefined) return undefined;
1164
+ if (hit === undefined) return void prepareMorph();
1357
1165
  const address = frameAddress(info.id, info.args);
1358
1166
  if (!info.meta?.live) calls.set(address, info);
1359
1167
  const binding = () => bindingFor(address, info.id);
@@ -1384,11 +1192,12 @@ function createServerComponentHandler({
1384
1192
  as: address,
1385
1193
  version: frameId => frameId === address ? version : bump(frameId)
1386
1194
  }).catch(err => target.apply({
1387
- type: "error",
1388
1195
  id: address,
1389
1196
  version,
1390
- error: {
1391
- message: String(err && err.message)
1197
+ r: {
1198
+ ":error": {
1199
+ message: String(err && err.message)
1200
+ }
1392
1201
  }
1393
1202
  }));
1394
1203
  return entry ? applied.then(() => settled(address, binding)) : binding;
@@ -1450,7 +1259,6 @@ const TRACE_STATE = Symbol.for("solid.container-trace-state");
1450
1259
  tierLoaders.trace = () => import('@solidjs/web/frames/trace');
1451
1260
  tierLoaders.regions = () => import('@solidjs/web/frames/regions');
1452
1261
  tierLoaders.assets = () => import('@solidjs/web/frames/assets');
1453
- tierLoaders.bind = () => import('@solidjs/web/frames/bind');
1454
1262
  tierLoaders.wire = () => import('@solidjs/web/frames/wire');
1455
1263
  function asyncArg(value) {
1456
1264
  return value;
@@ -1491,7 +1299,8 @@ function landing(host, address, value, failed) {
1491
1299
  if (state > 1) throw frame.error;
1492
1300
  const wait = host.landing(address);
1493
1301
  if (!wait) return value;
1494
- return (state ? reask(address, wait) : wait).then(() => value);
1302
+ const landed = (state ? reask(address, wait) : wait).then(() => value);
1303
+ return landed;
1495
1304
  });
1496
1305
  }
1497
1306
  function reask(address, wait) {
@@ -1538,15 +1347,13 @@ function claimScope(el) {
1538
1347
  index
1539
1348
  };
1540
1349
  }
1541
- function claimRender(prefix, existing, render, scope, bound) {
1350
+ function claimRender(prefix, owner, existing, render, scope, bound) {
1542
1351
  const sc = sharedConfig;
1543
- if (!sc.hydrateWindow || !sc.registry) return render();
1352
+ if (!sc.hydrateWindow || !sc.registry) return runWithOwner(owner, render);
1544
1353
  const prevRoots = sc.claimRoots;
1545
1354
  sc.claimRoots = existing;
1546
1355
  try {
1547
- return runWithOwner(createOwner({
1548
- id: prefix
1549
- }), () => sc.hydrateWindow(bound ? undefined : prefix, render, scope));
1356
+ return runWithOwner(owner, () => sc.hydrateWindow(bound ? undefined : prefix, render, scope));
1550
1357
  } finally {
1551
1358
  sc.claimRoots = prevRoots;
1552
1359
  }
@@ -1597,6 +1404,7 @@ function slotArgsProxy(args) {
1597
1404
  reads.set(key, read);
1598
1405
  }
1599
1406
  const v = read();
1407
+ if (v instanceof Element) tierLoads.regions.r.place(v);
1600
1408
  return v instanceof Boxed ? v.c : v;
1601
1409
  },
1602
1410
  has: (_, key) => key in args(),
@@ -1612,40 +1420,24 @@ function slotsFor(props, scope) {
1612
1420
  return new Proxy({}, {
1613
1421
  get(_, prop) {
1614
1422
  if (typeof prop !== "string" || !(prop in props)) return undefined;
1615
- return (slotProps, ctx) => {
1423
+ const mount = (slotProps, ctx) => {
1616
1424
  const key = ctx && ctx.key;
1617
1425
  const prevFill = key !== undefined && fillScopes.get(key);
1618
1426
  if (prevFill) {
1619
1427
  fillScopes.delete(key);
1620
1428
  prevFill.dispose();
1621
1429
  }
1622
- if (ctx && ctx.positions) {
1623
- const fill = props[prop];
1624
- if (typeof fill !== "function") {
1625
- return undefined;
1626
- }
1627
- const owner = createOwner();
1628
- fillScopes.set(key, owner);
1629
- ctx.onCleanup(() => {
1630
- if (fillScopes.get(key) === owner) fillScopes.delete(key);
1631
- owner.dispose();
1632
- });
1633
- runWithOwner(owner, () => {
1634
- const args = ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotArgsProxy(() => slotProps);
1635
- tierLoads.bind.r.bind(fill, args, ctx, undefined);
1636
- });
1637
- return undefined;
1638
- }
1639
1430
  const range = ctx && ctx.range;
1640
1431
  if (!range) return undefined;
1641
1432
  const fillOwner = streamInvoke ? createOwner() : null;
1642
- if (fillOwner && key !== undefined && ctx) {
1643
- fillScopes.set(key, fillOwner);
1644
- ctx.onCleanup(() => {
1645
- if (fillScopes.get(key) === fillOwner) fillScopes.delete(key);
1646
- fillOwner.dispose();
1647
- });
1648
- }
1433
+ const owner = fillOwner || createOwner({
1434
+ transparent: true
1435
+ });
1436
+ fillScopes.set(key, owner);
1437
+ ctx.onCleanup(() => {
1438
+ if (fillScopes.get(key) === owner) fillScopes.delete(key);
1439
+ owner.dispose();
1440
+ });
1649
1441
  const evaluate = () => {
1650
1442
  const v = props[prop];
1651
1443
  if (typeof v === "function" && ctx && ctx.invoked) {
@@ -1656,22 +1448,19 @@ function slotsFor(props, scope) {
1656
1448
  };
1657
1449
  const adopted = !!(ctx && ctx.frame && ctx.adopted && ctx.existing && ctx.existing.length);
1658
1450
  const prefix = ctx && ctx.frame ? `sc-${ctx.frame}-${ctx.key}-` : "";
1659
- const value = fillOwner ? runWithOwner(fillOwner, () => adopted ? claimRender(prefix, ctx.existing, evaluate, scope) : evaluate()) : adopted ? claimRender(prefix, ctx.existing, evaluate, scope) : evaluate();
1660
- const owner = fillOwner || createOwner({
1661
- transparent: true
1662
- });
1663
- if (!fillOwner) {
1664
- fillScopes.set(key, owner);
1665
- ctx.onCleanup(() => {
1666
- if (fillScopes.get(key) === owner) fillScopes.delete(key);
1667
- owner.dispose();
1668
- });
1669
- }
1451
+ const claim = adopted && runWithOwner(owner, () => createOwner({
1452
+ id: prefix
1453
+ }));
1454
+ const value = adopted ? claimRender(prefix, claim, ctx.existing, evaluate, scope) : fillOwner ? runWithOwner(fillOwner, evaluate) : evaluate();
1670
1455
  const end = range.end;
1671
1456
  const bind = () => insert(end.parentNode, value, end, [...ctx.existing]);
1672
- runWithOwner(owner, () => adopted ? claimRender(prefix, ctx.existing, bind, scope, true) : bind());
1457
+ adopted ? claimRender(prefix, claim, ctx.existing, bind, scope, true) : runWithOwner(owner, bind);
1673
1458
  return undefined;
1674
1459
  };
1460
+ return (slotProps, ctx) => {
1461
+ const R = tierLoads.regions?.r;
1462
+ R ? R.nest(mount, slotProps, ctx) : mount(slotProps, ctx);
1463
+ };
1675
1464
  }
1676
1465
  });
1677
1466
  }
@@ -1725,7 +1514,12 @@ function pumpLiveChannel() {
1725
1514
  const pump = () => reader.read().then(r => {
1726
1515
  if (r.done) return;
1727
1516
  const op = r.value;
1728
- for (const m of op.type === "ops" ? op.ops : [op]) liveOps.set(`${m.type}:${m.fid || ""}:${m.key || ""}`, m);
1517
+ for (const key in op.r) liveOps.set(`${op.fid || ""}:${key}`, {
1518
+ fid: op.fid,
1519
+ r: {
1520
+ [key]: op.r[key]
1521
+ }
1522
+ });
1729
1523
  for (const apply of liveAppliers) apply(op);
1730
1524
  return pump();
1731
1525
  });
@@ -1740,14 +1534,18 @@ function indexBoundaries(root) {
1740
1534
  if (key && isBoundaryId(key) && !boundaryIndex.has(key)) boundaryIndex.set(key, el);
1741
1535
  });
1742
1536
  }
1743
- function findBoundaryElement(id) {
1537
+ function findBoundaryElement(id, address) {
1744
1538
  if (!boundaryIndex) {
1745
1539
  boundaryIndex = new Map();
1746
1540
  if (typeof document !== "undefined" && document.body) indexBoundaries(document.body);
1747
1541
  }
1542
+ const args = address && address.slice(id.length + 1);
1543
+ let first, el;
1748
1544
  for (let n = 0;; n++) {
1749
1545
  const key = n ? id + "~" + (n + 1) : id;
1750
- if (!claimedBoundaries.has(key)) return boundaryIndex.get(key);
1546
+ if (claimedBoundaries.has(key)) continue;
1547
+ if (!(el = boundaryIndex.get(key)) || !args || el.dataset.fa == args) return el || first;
1548
+ first = first || el;
1751
1549
  }
1752
1550
  }
1753
1551
  const arrivals = new Map();
@@ -1758,17 +1556,29 @@ function awaitBoundary(id) {
1758
1556
  if (!arrival) {
1759
1557
  let resolve;
1760
1558
  const promise = new Promise(r => resolve = r);
1559
+ if (!resolve) return promise;
1761
1560
  arrivals.set(id, arrival = {
1762
1561
  promise,
1763
1562
  resolve
1764
1563
  });
1564
+ onHydrationEnd(releaseArrivals);
1765
1565
  }
1766
1566
  return arrival.promise;
1767
1567
  }
1568
+ function releaseArrivals() {
1569
+ if (!arrivals.size) return;
1570
+ const exhausted = !boundaryMayArrive();
1571
+ for (const [id, arrival] of arrivals) {
1572
+ const el = boundaryIndex && boundaryIndex.get(id);
1573
+ if (!el && !exhausted) continue;
1574
+ arrivals.delete(id);
1575
+ arrival.resolve(!!el);
1576
+ }
1577
+ }
1768
1578
  function boundaryMayArrive() {
1769
1579
  const hy = globalThis._$HY;
1770
1580
  if (!hy) return false;
1771
- return !hy.done || !!(hy.fr && hy.fr.pending());
1581
+ return !(hy.done || sharedConfig.done) || !!(hy.fr && hy.fr.pending());
1772
1582
  }
1773
1583
  function installRevealHook() {
1774
1584
  installServerComponentHydration();
@@ -1783,26 +1593,20 @@ function installRevealHook() {
1783
1593
  if (!boundaryIndex) return;
1784
1594
  const root = parent || (typeof document !== "undefined" ? document.body : null);
1785
1595
  if (root) indexBoundaries(root);
1786
- if (!arrivals.size) return;
1787
- const exhausted = hy.done && !hy.fr.pending();
1788
- for (const [id, arrival] of arrivals) {
1789
- const el = boundaryIndex && boundaryIndex.get(id);
1790
- if (!el && !exhausted) continue;
1791
- arrivals.delete(id);
1792
- arrival.resolve(!!el);
1793
- }
1596
+ releaseArrivals();
1794
1597
  });
1795
1598
  }
1796
1599
  function documentBoundary(host, id, props, binding) {
1797
1600
  installRevealHook();
1798
- const el = findBoundaryElement(id);
1601
+ const address = binding && contentAddress(binding());
1602
+ const el = findBoundaryElement(id, address);
1799
1603
  if (el) return adoptBoundary(host, id, el, props, binding);
1800
1604
  if (!claimedBoundaries.has(id) && boundaryMayArrive()) {
1801
1605
  const owner = getOwner();
1802
1606
  let live = true;
1803
1607
  onCleanup(() => live = false);
1804
1608
  return createMemo(() => awaitBoundary(id).then(() => live && runWithOwner(owner, () => {
1805
- const node = findBoundaryElement(id);
1609
+ const node = findBoundaryElement(id, address);
1806
1610
  return node ? adoptBoundary(host, id, node, props, binding) : boundaryComponent(host, id)(props, binding);
1807
1611
  })));
1808
1612
  }
@@ -1811,6 +1615,7 @@ function documentBoundary(host, id, props, binding) {
1811
1615
  function adoptBoundary(host, id, el, props, binding) {
1812
1616
  const siteId = el.getAttribute(FRAME_ID_ATTR);
1813
1617
  claimedBoundaries.add(siteId);
1618
+ edgeRoots.set(siteId, el);
1814
1619
  const address = binding ? contentAddress(binding()) : id;
1815
1620
  const appliedRecords = new Set();
1816
1621
  const drainRecords = () => {
@@ -1823,11 +1628,14 @@ function adoptBoundary(host, id, el, props, binding) {
1823
1628
  if (key.startsWith(slotPrefix)) {
1824
1629
  appliedRecords.add(key);
1825
1630
  const apply = args => host.apply({
1826
- type: "slot",
1827
1631
  id: address,
1828
1632
  version: 0,
1829
- key: key.slice(slotPrefix.length),
1830
- args
1633
+ r: {
1634
+ [`slot:${key.slice(slotPrefix.length)}`]: {
1635
+ kind: "slot",
1636
+ args
1637
+ }
1638
+ }
1831
1639
  });
1832
1640
  const value = hy.r[key];
1833
1641
  if (value && typeof value.then === "function") {
@@ -1839,10 +1647,14 @@ function adoptBoundary(host, id, el, props, binding) {
1839
1647
  appliedRecords.add(key);
1840
1648
  const val = hy.r[key];
1841
1649
  const apply = html => host.apply({
1842
- type: "html",
1843
1650
  id: childId,
1844
1651
  version: 0,
1845
- html
1652
+ r: {
1653
+ "": {
1654
+ kind: "html",
1655
+ value: html
1656
+ }
1657
+ }
1846
1658
  });
1847
1659
  val && typeof val.then === "function" ? val.then(apply) : apply(val);
1848
1660
  }
@@ -1864,9 +1676,9 @@ function adoptBoundary(host, id, el, props, binding) {
1864
1676
  const applyLiveOp = op => {
1865
1677
  if (op.fid && op.fid !== siteId) return;
1866
1678
  host.apply({
1867
- ...op,
1868
1679
  id: address,
1869
- version: 0
1680
+ version: 0,
1681
+ r: op.r
1870
1682
  });
1871
1683
  };
1872
1684
  liveAppliers.add(applyLiveOp);
@@ -1881,6 +1693,7 @@ function adoptBoundary(host, id, el, props, binding) {
1881
1693
  const [failed, onApply] = failing();
1882
1694
  frame = createFrame(el, {
1883
1695
  adopt: true,
1696
+ defer: true,
1884
1697
  host,
1885
1698
  id: address,
1886
1699
  slots: slotsFor(props, scope),
@@ -1904,6 +1717,163 @@ function adoptBoundary(host, id, el, props, binding) {
1904
1717
  });
1905
1718
  return el;
1906
1719
  }
1720
+ const DEFER_EVENTS = ["click", "input", "change", "keydown", "pointerdown", "submit", "focusin"];
1721
+ const DEFER_BUDGET = 8;
1722
+ let mounting = false;
1723
+ const idleTick = () => new Promise(r => typeof requestIdleCallback === "function" ? requestIdleCallback(() => r(), {
1724
+ timeout: 100
1725
+ }) : setTimeout(r, 0));
1726
+ function wakeAt(e) {
1727
+ const target = e.target;
1728
+ if (!target || mounting) return;
1729
+ mounting = true;
1730
+ try {
1731
+ for (let f; (f = liveFrameAt(target)) && f.mountEnclosing(target););
1732
+ } finally {
1733
+ mounting = false;
1734
+ }
1735
+ deferDone();
1736
+ }
1737
+ function mountAllDeferred() {
1738
+ if (mounting || sharedConfig.hydrating) return;
1739
+ mounting = true;
1740
+ try {
1741
+ for (let frames; (frames = deferredFrames()).length;) for (const f of frames) f.mountDeferred();
1742
+ } finally {
1743
+ mounting = false;
1744
+ }
1745
+ deferDone();
1746
+ }
1747
+ const edgeRoots = new Map();
1748
+ let edgeIndex;
1749
+ const DEPS = "sc:deps:";
1750
+ function buildEdgeIndex() {
1751
+ const r = globalThis._$HY?.r;
1752
+ if (!r) return undefined;
1753
+ const idx = {
1754
+ readers: new Map(),
1755
+ wide: new Set(),
1756
+ untracked: [],
1757
+ sites: new Set(),
1758
+ starts: new Map()
1759
+ };
1760
+ for (const site of edgeRoots.keys()) for (let n = 0, batch; batch = r[DEPS + site + ":" + n]; n++) {
1761
+ if (typeof batch !== "object") return undefined;
1762
+ idx.sites.add(site);
1763
+ for (const sid in batch) {
1764
+ const occs = unpackOccurrences(batch[sid]);
1765
+ if (sid === "*") occs.forEach(w => idx.wide.add(w));else if (sid === "!") occs.forEach(o => idx.untracked.push([site, o]));else {
1766
+ let list = idx.readers.get(sid);
1767
+ if (!list) idx.readers.set(sid, list = []);
1768
+ for (const o of occs) list.push([site, o]);
1769
+ }
1770
+ }
1771
+ }
1772
+ return idx;
1773
+ }
1774
+ function unpackOccurrences(packed) {
1775
+ const out = [];
1776
+ for (const part of packed.split(" ")) {
1777
+ const m = /^(.*)#(\d+)-(\d+)$/.exec(part);
1778
+ if (!m) part && out.push(part);else for (let i = +m[2]; i <= +m[3]; i++) out.push(m[1] + "#" + i);
1779
+ }
1780
+ return out;
1781
+ }
1782
+ function startOf(idx, site, occ) {
1783
+ let m = idx.starts.get(site);
1784
+ if (!m) {
1785
+ idx.starts.set(site, m = new Map());
1786
+ const root = edgeRoots.get(site);
1787
+ if (root) {
1788
+ const w = document.createTreeWalker(root, 128 );
1789
+ for (let c = w.nextNode(); c; c = w.nextNode()) {
1790
+ const d = c.data;
1791
+ if (d.startsWith("slot:") && d.endsWith(":start")) m.set(d.slice(5, -6), c);
1792
+ }
1793
+ }
1794
+ }
1795
+ return m.get(occ);
1796
+ }
1797
+ function edgesCover(idx) {
1798
+ outer: for (const f of deferredFrames()) {
1799
+ for (const [site, root] of edgeRoots) if (idx.sites.has(site) && root.contains(f.el)) continue outer;
1800
+ return false;
1801
+ }
1802
+ return true;
1803
+ }
1804
+ function mountForWrite(node) {
1805
+ if (mounting || sharedConfig.hydrating) return;
1806
+ const sid = signalName(node) ?? storeName(node);
1807
+ if (sid === undefined || document.readyState === "loading") return mountAllDeferred();
1808
+ const idx = edgeIndex ||= buildEdgeIndex();
1809
+ if (!idx || idx.wide.has(sid) || !edgesCover(idx)) return mountAllDeferred();
1810
+ const readers = idx.readers.get(sid);
1811
+ if (!readers && !idx.untracked.length) return;
1812
+ mounting = true;
1813
+ try {
1814
+ for (const list of [readers || [], idx.untracked]) for (const [site, occ] of list) {
1815
+ const root = edgeRoots.get(site);
1816
+ if (root && deferredFrames().some(f => root.contains(f.el) && f.mountOccurrence(occ))) continue;
1817
+ const start = startOf(idx, site, occ);
1818
+ const target = start && (start.nextSibling || start);
1819
+ if (target) for (let f; (f = liveFrameAt(target)) && f.mountEnclosing(target););
1820
+ }
1821
+ } finally {
1822
+ mounting = false;
1823
+ }
1824
+ deferDone();
1825
+ }
1826
+ let idlePass;
1827
+ function mountIdle() {
1828
+ return idlePass ||= (async () => {
1829
+ if (document.readyState !== "complete") await new Promise(r => addEventListener("load", r, {
1830
+ once: true
1831
+ }));
1832
+ globalThis._$HY?.r?.["sc:tiers"]?.forEach(prepareTier);
1833
+ await Promise.all(Object.values(tierLoads)).catch(() => {});
1834
+ for (let frames; (frames = deferredFrames()).length;) {
1835
+ await idleTick();
1836
+ const deadline = performance.now() + DEFER_BUDGET;
1837
+ mounting = true;
1838
+ try {
1839
+ for (const f of frames) if (!f.mountDeferred(deadline) || performance.now() > deadline) break;
1840
+ } finally {
1841
+ mounting = false;
1842
+ }
1843
+ }
1844
+ idlePass = undefined;
1845
+ deferDone();
1846
+ })();
1847
+ }
1848
+ function deferDone() {
1849
+ if (deferredFrames().length) return;
1850
+ if (deferring) {
1851
+ deferring = false;
1852
+ edgeIndex = undefined;
1853
+ setWriteHook(null);
1854
+ DEFER_EVENTS.forEach(t => document.removeEventListener(t, wakeAt, true));
1855
+ }
1856
+ releaseDeferHolds();
1857
+ }
1858
+ let deferHydration = true;
1859
+ function setDeferredHydration(on) {
1860
+ deferHydration = on;
1861
+ setDeferDriver(on && typeof document !== "undefined" ? deferFrame : null);
1862
+ setSignalIdentities(on && typeof document !== "undefined");
1863
+ }
1864
+ let deferring = false;
1865
+ function deferFrame(frame) {
1866
+ if (!deferring) {
1867
+ deferring = true;
1868
+ setWriteHook(mountForWrite);
1869
+ DEFER_EVENTS.forEach(t => document.addEventListener(t, wakeAt, true));
1870
+ }
1871
+ const queued = sharedConfig.events;
1872
+ if (queued && queued.length) for (const [el, e] of queued) if (frame.el.contains(el)) wakeAt({
1873
+ target: e.target ?? el
1874
+ });
1875
+ mountIdle();
1876
+ }
1907
1877
  function installServerComponents(host = getFrameHost(), options) {
1908
1878
  const g = globalThis;
1909
1879
  Object.assign(tierLoaders, options?.tiers);
@@ -1929,6 +1899,10 @@ function installServerComponents(host = getFrameHost(), options) {
1929
1899
  }
1930
1900
  g._$SC.impl = (id, props, binding) => documentBoundary(host, id, props, binding);
1931
1901
  installRevealHook();
1902
+ if (typeof document !== "undefined" && deferHydration) {
1903
+ setDeferDriver(deferFrame);
1904
+ setSignalIdentities(true);
1905
+ }
1932
1906
  const handler = createServerComponentHandler({
1933
1907
  host,
1934
1908
  component: fnId => g._$SC.r(fnId),
@@ -1950,4 +1924,4 @@ function installServerComponents(host = getFrameHost(), options) {
1950
1924
  });
1951
1925
  }
1952
1926
 
1953
- export { FRAME_APPLIED_EVENT, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents, isAsyncValue, isFrameStreamResponse };
1927
+ export { FRAME_APPLIED_EVENT, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents, isFrameStreamResponse, setDeferredHydration };