@solidjs/web 2.0.0-rc.10 → 2.0.0-rc.13

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.
@@ -1,7 +1,7 @@
1
- import { DEV, OBSERVE, getOwner, onCleanup, createMemo, runWithOwner, createSignal, createRenderEffect, createLoadingBoundary, createOwner, sharedConfig } from 'solid-js';
2
- import { delegateEvents, insert } from '@solidjs/web';
1
+ import { DEV, OBSERVE, getOwner, onCleanup, createMemo, runWithOwner, createSignal, createRenderEffect, createOwner } from 'solid-js';
2
+ import { insert, assign } from '@solidjs/web';
3
3
  import { frameAddress, SINGLE_FLIGHT_HEADER, LIVE_WIRE, deserializeStream, getServerFunctionsCodec, createChunk, deliverFlightData, ERROR_HEADER, hasFlightMetadata, isEventStream, ChunkReader, configureServerFunctionsClient } from '@solidjs/web/server-functions/client';
4
- import { materializeContainerTrace } from 'solid-js/internal';
4
+ import { createLoadingBoundary, sharedConfig, materializeContainerTrace } from 'solid-js/internal';
5
5
 
6
6
  const ELEMENT_NODE = 1;
7
7
  const TEXT_NODE = 3;
@@ -16,74 +16,6 @@ function claimNode(handlers, el) {
16
16
  for (let i = 0; i < handlers.length; i++) handlers[i](el);
17
17
  }
18
18
  const claimedAttr = name => name === "href" || name === "action";
19
- const BOUND_SEAM = Symbol.for("solid.bnd");
20
- const boundSeam = globalThis[BOUND_SEAM] || (globalThis[BOUND_SEAM] = {});
21
- const BND_ATTR = "_bnd";
22
- const BND_SELECTOR = "[_bnd]";
23
- function bndMap(el) {
24
- const s = el.getAttribute(BND_ATTR);
25
- if (!s) return undefined;
26
- const map = {};
27
- for (const entry of s.split(",")) {
28
- const eq = entry.indexOf("=");
29
- if (eq < 1) continue;
30
- const pos = entry.slice(0, eq);
31
- const prop = decodeURIComponent(entry.slice(eq + 1));
32
- const prev = map[pos];
33
- if (prev === undefined) map[pos] = prop;else if (Array.isArray(prev)) prev.push(prop);else map[pos] = [prev, prop];
34
- }
35
- return map;
36
- }
37
- boundSeam.resolve = (el, type) => {
38
- const frame = el._$bndFrame;
39
- if (!frame) return undefined;
40
- const map = bndMap(el);
41
- const prop = map && map[type];
42
- if (typeof prop !== "string") return undefined;
43
- return claimFn(frame, type, prop);
44
- };
45
- function claimFn(frame, pos, prop) {
46
- const fn = frame.clientProp(prop);
47
- if (typeof fn === "function") return fn;
48
- if (fn !== undefined) {
49
- console.warn(`A server element claims \`${pos}\` from client prop \`${prop}\`, but the mounted ` + `frame's prop is not a function.`);
50
- }
51
- return undefined;
52
- }
53
- function sweepBound(root, frame, delegate, scope) {
54
- const isElement = root.nodeType === ELEMENT_NODE;
55
- if (!isElement && root.nodeType !== 11 ) return;
56
- let els;
57
- if (isElement && root.hasAttribute(BND_ATTR)) (els = []).push(root);
58
- const found = root.querySelectorAll(BND_SELECTOR);
59
- if (found.length) {
60
- els || (els = []);
61
- for (let i = 0; i < found.length; i++) els.push(found[i]);
62
- }
63
- if (!els) return;
64
- const run = () => {
65
- let types;
66
- for (const el of els) {
67
- el._$bndFrame = frame;
68
- const map = bndMap(el);
69
- if (!map) continue;
70
- for (const pos in map) {
71
- if (pos === "ref") fireRefs(frame, el, map.ref);else (types || (types = [])).push(pos);
72
- }
73
- }
74
- if (types && delegate) delegate(types);
75
- };
76
- scope ? scope(run) : run();
77
- }
78
- function fireRefs(frame, el, prop) {
79
- const fired = el._$bndFired || (el._$bndFired = new Set());
80
- for (const p of Array.isArray(prop) ? prop : [prop]) {
81
- if (fired.has(p)) continue;
82
- fired.add(p);
83
- const fn = claimFn(frame, "ref", p);
84
- if (fn) fn(el);
85
- }
86
- }
87
19
  function claimTree(handlers, root) {
88
20
  const isElement = root.nodeType === ELEMENT_NODE;
89
21
  if (!isElement && root.nodeType !== 11 ) return;
@@ -95,6 +27,45 @@ const placeholderId = name => `pl-${name}`;
95
27
  const SLOT_START = /^slot:(.+):start$/;
96
28
  const SLOT_END = /^slot:(.+):end$/;
97
29
  const slotEnd = id => `slot:${id}:end`;
30
+ const SLOT_MARKER = "_s:";
31
+ function slotPositions(el) {
32
+ const attrs = el.attributes;
33
+ let out = null;
34
+ for (let i = 0; i < attrs.length; i++) {
35
+ const attr = attrs[i];
36
+ if (!attr.name.startsWith(SLOT_MARKER)) continue;
37
+ const pos = attr.name.slice(SLOT_MARKER.length);
38
+ for (const entry of attr.value.split(",")) {
39
+ const colon = entry.indexOf(":");
40
+ if (colon < 1) continue;
41
+ const occurrence = entry.slice(0, colon);
42
+ const eq = entry.indexOf("=", colon);
43
+ const key = decodeURIComponent(eq === -1 ? entry.slice(colon + 1) : entry.slice(colon + 1, eq));
44
+ const name = eq === -1 ? undefined : decodeURIComponent(entry.slice(eq + 1));
45
+ out || (out = Object.create(null));
46
+ (out[occurrence] || (out[occurrence] = [])).push({
47
+ pos,
48
+ key,
49
+ name
50
+ });
51
+ }
52
+ }
53
+ return out;
54
+ }
55
+ function consumersEqual(a, b) {
56
+ if (a.length !== b.length) return false;
57
+ for (let i = 0; i < a.length; i++) {
58
+ const x = a[i];
59
+ const y = b[i];
60
+ if (x.element !== y.element || x.positions.length !== y.positions.length) return false;
61
+ for (let j = 0; j < x.positions.length; j++) {
62
+ const p = x.positions[j];
63
+ const q = y.positions[j];
64
+ if (p.pos !== q.pos || p.key !== q.key || p.name !== q.name) return false;
65
+ }
66
+ }
67
+ return true;
68
+ }
98
69
  function chunkToRecords(chunk) {
99
70
  switch (chunk.type) {
100
71
  case "start":
@@ -201,7 +172,6 @@ function createFrameHost(options = {}) {
201
172
  return true;
202
173
  };
203
174
  return {
204
- delegate: options.delegate,
205
175
  register(id, frame) {
206
176
  let set = frames.get(id);
207
177
  if (!set) frames.set(id, set = new Set());
@@ -290,6 +260,8 @@ class FrameImpl {
290
260
  #slotRegions = new Map();
291
261
  #slotResolvedRefs = new Map();
292
262
  #slotNodes = new Map();
263
+ #slotConsumers = new Map();
264
+ #slotRebinders = new Map();
293
265
  #processedAssets = new WeakSet();
294
266
  #recordRefresh = null;
295
267
  #disposed = false;
@@ -297,18 +269,10 @@ class FrameImpl {
297
269
  if (!this.#disposed) this.#flush();
298
270
  };
299
271
  #claimTree = (node, direct) => {
300
- if (!direct && node.nodeType !== TEXT_NODE && node.nodeType !== COMMENT_NODE) {
301
- const o = this.#options;
302
- sweepBound(node, this, o.delegate || o.host && o.host.delegate, o.ownerScope);
303
- }
304
272
  const handlers = claimHandlers();
305
273
  if (!handlers) return;
306
274
  this.#scoped(() => direct ? claimNode(handlers, node) : claimTree(handlers, node));
307
275
  };
308
- clientProp(name) {
309
- const props = this.#options.props;
310
- return props ? props[name] : undefined;
311
- }
312
276
  #scoped(fn) {
313
277
  const scope = this.#options.ownerScope;
314
278
  return scope ? scope(fn) : fn();
@@ -489,15 +453,19 @@ class FrameImpl {
489
453
  #syncSlots(root) {
490
454
  if (!this.#slots && !this.#options.resolveSlot) return;
491
455
  const found = new Map();
492
- if (root) collectSlots(root.firstChild, null, found);else this.#collectSlots(found);
456
+ if (root) collectSlots(root.firstChild, null, found, found);else this.#collectSlots(found, found);
493
457
  for (const [occurrence, start] of found) {
494
458
  const callback = this.#resolveSlot(propOf(occurrence));
495
- if (!callback) continue;
459
+ const consumers = Array.isArray(start) ? start : null;
460
+ if (!callback) {
461
+ if (consumers) devSlotOrphan(this, occurrence, consumers, "fill");
462
+ continue;
463
+ }
496
464
  const record = this.#resolveSlotRecord(occurrence);
497
465
  if (record && record.kind === "slot" && this.#refsUnresolved(record.args)) continue;
498
466
  const prev = this.#slotNodes.get(occurrence);
499
467
  const prevFirst = Array.isArray(prev) ? prev[0] : prev;
500
- const zombie = this.#mountedSlots.has(occurrence) && prevFirst && !prevFirst.parentNode;
468
+ const zombie = !consumers && this.#mountedSlots.has(occurrence) && prevFirst && !prevFirst.parentNode;
501
469
  if (zombie) {
502
470
  this.#mountedSlots.delete(occurrence);
503
471
  this.#runSlotCleanups(occurrence);
@@ -512,14 +480,28 @@ class FrameImpl {
512
480
  });
513
481
  continue;
514
482
  }
483
+ if (consumers && record === undefined && occurrence.indexOf("#") !== -1) devSlotOrphan(this, occurrence, consumers, "record");
515
484
  if (this.#options.adopt) this.#discoverRegions(occurrence, start);
516
485
  const nodes = this.#invokeSlot(occurrence, callback, record, start, this.#options.adopt);
517
- if (nodes) this.#replaceRange(occurrence, start, nodes);
518
- this.#slotNodes.set(occurrence, nodes);
486
+ if (consumers) {
487
+ this.#slotNodes.set(occurrence, consumers.map(c => c.element));
488
+ this.#slotConsumers.set(occurrence, consumers);
489
+ } else {
490
+ if (nodes) this.#replaceRange(occurrence, start, nodes);
491
+ this.#slotNodes.set(occurrence, nodes);
492
+ }
519
493
  this.#mountedSlots.add(occurrence);
520
494
  if (!this.#options.adopt || nodes) this.#discoverRegions(occurrence, start);
521
495
  this.#bindRegions(occurrence);
522
- } else if (record !== this.#slotArgs.get(occurrence)) {
496
+ continue;
497
+ }
498
+ if (consumers && !consumersEqual(this.#slotConsumers.get(occurrence), consumers)) {
499
+ this.#slotConsumers.set(occurrence, consumers);
500
+ this.#slotNodes.set(occurrence, consumers.map(c => c.element));
501
+ const rebind = this.#slotRebinders.get(occurrence);
502
+ if (rebind) rebind(consumers);
503
+ }
504
+ if (record !== this.#slotArgs.get(occurrence)) {
523
505
  if (this.#refArgsUnchanged(occurrence, record)) {
524
506
  this.#slotArgs.set(occurrence, record);
525
507
  this.#reconcileRegions(occurrence, record);
@@ -534,8 +516,10 @@ class FrameImpl {
534
516
  continue;
535
517
  }
536
518
  const nodes = this.#invokeSlot(occurrence, callback, record, start);
537
- if (nodes) this.#replaceRange(occurrence, start, nodes);
538
- this.#slotNodes.set(occurrence, nodes);
519
+ if (consumers) this.#slotNodes.set(occurrence, consumers.map(c => c.element));else {
520
+ if (nodes) this.#replaceRange(occurrence, start, nodes);
521
+ this.#slotNodes.set(occurrence, nodes);
522
+ }
539
523
  this.#bindRegions(occurrence);
540
524
  }
541
525
  }
@@ -547,10 +531,12 @@ class FrameImpl {
547
531
  }
548
532
  #invokeSlot(occurrence, callback, record, start, adopted) {
549
533
  this.#slotUpdaters.delete(occurrence);
534
+ this.#slotRebinders.delete(occurrence);
550
535
  const cleanups = this.#slotCleanups.get(occurrence) ?? [];
551
536
  let existing = [];
552
537
  let end = null;
553
- if (start) end = eachInRange(start, occurrence, n => existing.push(n));
538
+ const positions = Array.isArray(start) ? start : undefined;
539
+ if (start && !positions) end = eachInRange(start, occurrence, n => existing.push(n));
554
540
  const ctx = {
555
541
  frame: this.#options.claimScope ?? this.#options.id,
556
542
  key: occurrence,
@@ -562,7 +548,9 @@ class FrameImpl {
562
548
  range: end ? {
563
549
  start,
564
550
  end
565
- } : undefined
551
+ } : undefined,
552
+ positions,
553
+ onRebind: positions ? fn => this.#slotRebinders.set(occurrence, fn) : undefined
566
554
  };
567
555
  const props = record && record.kind === "slot" ? this.#resolveArgs(occurrence, record.args) : {};
568
556
  const content = this.#scoped(() => callback(props, ctx));
@@ -579,8 +567,10 @@ class FrameImpl {
579
567
  #unmountSlot(key) {
580
568
  this.#mountedSlots.delete(key);
581
569
  this.#slotNodes.delete(key);
570
+ this.#slotConsumers.delete(key);
582
571
  this.#slotArgs.delete(key);
583
572
  this.#slotUpdaters.delete(key);
573
+ this.#slotRebinders.delete(key);
584
574
  this.#slotResolvedRefs.delete(key);
585
575
  this.#removeSlotRecord(key);
586
576
  this.#runSlotCleanups(key);
@@ -644,7 +634,7 @@ class FrameImpl {
644
634
  return props;
645
635
  }
646
636
  #discoverRegions(slotKey, start) {
647
- if (!start) return;
637
+ if (!start || Array.isArray(start)) return;
648
638
  const regions = this.#regionsFor(slotKey);
649
639
  eachInRange(start, slotKey, n => collectRegionElements(n, regions));
650
640
  }
@@ -711,8 +701,8 @@ class FrameImpl {
711
701
  }
712
702
  }
713
703
  }
714
- #collectSlots(found) {
715
- collectSlots(this.#firstContent(), this.#end, found);
704
+ #collectSlots(found, elements) {
705
+ collectSlots(this.#firstContent(), this.#end, found, elements);
716
706
  }
717
707
  #findPlaceholder(name) {
718
708
  return findPlaceholder(this.#firstContent(), this.#end, placeholderId(name));
@@ -806,11 +796,15 @@ class FrameImpl {
806
796
  if (!el) return false;
807
797
  const parsed = parseFragment(`<i${text}></i>`).firstChild;
808
798
  const keepOpen = preservesOpen(el);
799
+ const owned = parsed ? ownedPositions(parsed) : null;
809
800
  const current = el.attributes;
810
801
  for (let i = current.length - 1; i >= 0; i--) {
811
802
  const name = current[i].name;
812
803
  if (name === "data-lha" || keepOpen && name === "open") continue;
813
- if (!parsed || !parsed.hasAttribute(name)) el.removeAttribute(name);
804
+ if (!parsed || !parsed.hasAttribute(name)) {
805
+ if (applyOwned(el, name, "", owned) !== undefined) continue;
806
+ el.removeAttribute(name);
807
+ }
814
808
  }
815
809
  if (parsed) {
816
810
  for (let i = 0; i < parsed.attributes.length; i++) {
@@ -819,10 +813,15 @@ class FrameImpl {
819
813
  value
820
814
  } = parsed.attributes[i];
821
815
  if (keepOpen && name === "open") continue;
816
+ if (applyOwned(el, name, value, owned) !== undefined) continue;
822
817
  if (el.getAttribute(name) !== value) el.setAttribute(name, value);
823
818
  }
824
819
  }
825
- if (removed) for (const name of removed) if (!(keepOpen && name === "open")) el.removeAttribute(name);
820
+ if (removed) for (const name of removed) {
821
+ if (keepOpen && name === "open") continue;
822
+ if (applyOwned(el, name, "", owned) !== undefined) continue;
823
+ el.removeAttribute(name);
824
+ }
826
825
  return true;
827
826
  }
828
827
  #clearContent() {
@@ -1070,7 +1069,7 @@ function findPlaceholder(n, end, id) {
1070
1069
  }
1071
1070
  return null;
1072
1071
  }
1073
- function collectSlots(n, end, out) {
1072
+ function collectSlots(n, end, out, elements) {
1074
1073
  while (n && n !== end) {
1075
1074
  const id = slotStartId(n);
1076
1075
  if (id !== null) {
@@ -1079,7 +1078,22 @@ function collectSlots(n, end, out) {
1079
1078
  n = afterRange(n, id);
1080
1079
  continue;
1081
1080
  }
1082
- if (n.nodeType === ELEMENT_NODE && !isFrameElement(n)) collectSlots(n.firstChild, null, out);
1081
+ if (n.nodeType === ELEMENT_NODE && !isFrameElement(n)) {
1082
+ if (elements !== undefined && n.hasAttributes()) {
1083
+ const byOccurrence = slotPositions(n);
1084
+ if (byOccurrence !== null) {
1085
+ for (const occurrence in byOccurrence) {
1086
+ let consumers = elements.get(occurrence);
1087
+ if (consumers === undefined) elements.set(occurrence, consumers = []);else if (!Array.isArray(consumers)) continue;
1088
+ consumers.push({
1089
+ element: n,
1090
+ positions: byOccurrence[occurrence]
1091
+ });
1092
+ }
1093
+ }
1094
+ }
1095
+ collectSlots(n.firstChild, null, out, elements);
1096
+ }
1083
1097
  n = n.nextSibling;
1084
1098
  }
1085
1099
  }
@@ -1157,15 +1171,77 @@ function preservesOpen(el) {
1157
1171
  const t = el.tagName;
1158
1172
  return t === "DETAILS" || t === "DIALOG";
1159
1173
  }
1174
+ function ownedPositions(el) {
1175
+ const attrs = el.attributes;
1176
+ let out = null;
1177
+ for (let i = 0; i < attrs.length; i++) {
1178
+ const name = attrs[i].name;
1179
+ if (!name.startsWith(SLOT_MARKER)) continue;
1180
+ const pos = name.slice(SLOT_MARKER.length);
1181
+ if (pos === "ref" || pos.startsWith("on:")) continue;
1182
+ out || (out = {
1183
+ attrs: new Set(),
1184
+ class: null,
1185
+ style: null
1186
+ });
1187
+ if (pos !== "class" && pos !== "style") {
1188
+ out.attrs.add(pos);
1189
+ continue;
1190
+ }
1191
+ for (const entry of attrs[i].value.split(",")) {
1192
+ const eq = entry.indexOf("=");
1193
+ if (eq === -1) {
1194
+ out.attrs.add(pos);
1195
+ continue;
1196
+ }
1197
+ (out[pos] || (out[pos] = [])).push(decodeURIComponent(entry.slice(eq + 1)));
1198
+ }
1199
+ }
1200
+ return out;
1201
+ }
1202
+ function morphOwnedClass(oldEl, value, names) {
1203
+ const list = oldEl.classList;
1204
+ const set = new Set(value ? value.split(/\s+/) : []);
1205
+ set.delete("");
1206
+ for (const name of names) list.contains(name) ? set.add(name) : set.delete(name);
1207
+ const next = [...set].join(" ");
1208
+ if (next === (oldEl.getAttribute("class") || "")) return false;
1209
+ next ? oldEl.setAttribute("class", next) : oldEl.removeAttribute("class");
1210
+ return true;
1211
+ }
1212
+ function morphOwnedStyle(oldEl, value, names) {
1213
+ const style = oldEl.style;
1214
+ const saved = names.map(name => [name, style.getPropertyValue(name), style.getPropertyPriority(name)]);
1215
+ const before = oldEl.getAttribute("style");
1216
+ value ? oldEl.setAttribute("style", value) : oldEl.removeAttribute("style");
1217
+ for (const [name, v, priority] of saved) {
1218
+ v ? style.setProperty(name, v, priority) : style.removeProperty(name);
1219
+ }
1220
+ return oldEl.getAttribute("style") !== before;
1221
+ }
1222
+ function applyOwned(oldEl, name, value, owned) {
1223
+ if (owned === null) return undefined;
1224
+ if (owned.attrs.has(name)) return false;
1225
+ if ((name === "class" || name === "style") && owned[name] !== null) {
1226
+ return name === "class" ? morphOwnedClass(oldEl, value, owned.class) : morphOwnedStyle(oldEl, value, owned.style);
1227
+ }
1228
+ return undefined;
1229
+ }
1160
1230
  function morphAttributes(oldEl, newEl, claim) {
1161
1231
  let reclaim = false;
1162
1232
  let changed = false;
1163
1233
  const keepOpen = preservesOpen(oldEl);
1234
+ const owned = ownedPositions(newEl);
1164
1235
  const oldAttrs = oldEl.attributes;
1165
1236
  for (let i = oldAttrs.length - 1; i >= 0; i--) {
1166
1237
  const name = oldAttrs[i].name;
1167
1238
  if (keepOpen && name === "open") continue;
1168
1239
  if (!newEl.hasAttribute(name)) {
1240
+ const handled = applyOwned(oldEl, name, "", owned);
1241
+ if (handled !== undefined) {
1242
+ changed = handled || changed;
1243
+ continue;
1244
+ }
1169
1245
  oldEl.removeAttribute(name);
1170
1246
  changed = true;
1171
1247
  reclaim ||= claimedAttr(name);
@@ -1174,11 +1250,17 @@ function morphAttributes(oldEl, newEl, claim) {
1174
1250
  const newAttrs = newEl.attributes;
1175
1251
  for (let i = 0; i < newAttrs.length; i++) {
1176
1252
  const attr = newAttrs[i];
1177
- if (keepOpen && attr.name === "open") continue;
1178
- if (oldEl.getAttribute(attr.name) !== attr.value) {
1179
- oldEl.setAttribute(attr.name, attr.value);
1253
+ const name = attr.name;
1254
+ if (keepOpen && name === "open") continue;
1255
+ const handled = applyOwned(oldEl, name, attr.value, owned);
1256
+ if (handled !== undefined) {
1257
+ changed = handled || changed;
1258
+ continue;
1259
+ }
1260
+ if (oldEl.getAttribute(name) !== attr.value) {
1261
+ oldEl.setAttribute(name, attr.value);
1180
1262
  changed = true;
1181
- reclaim ||= claimedAttr(attr.name);
1263
+ reclaim ||= claimedAttr(name);
1182
1264
  }
1183
1265
  }
1184
1266
  if (claim && (reclaim || changed && oldEl.matches(CLAIMED_ELEMENTS))) claim(oldEl, true);
@@ -1201,6 +1283,29 @@ function afterRange(start, id) {
1201
1283
  }
1202
1284
  return null;
1203
1285
  }
1286
+ let slotOrphans;
1287
+ function devSlotOrphan(frame, occurrence, consumers, why) {
1288
+ let seen = (slotOrphans ??= new WeakMap()).get(frame);
1289
+ if (!seen) slotOrphans.set(frame, seen = new Set());
1290
+ if (seen.has(occurrence)) return;
1291
+ seen.add(occurrence);
1292
+ const prop = propOf(occurrence);
1293
+ const positions = new Set();
1294
+ for (const c of consumers) for (const p of c.positions) positions.add(p.pos);
1295
+ const where = `${consumers.length} element${consumers.length === 1 ? "" : "s"} (positions: ${[...positions].join(", ")})`;
1296
+ DEV.report(OBSERVE.diagnostics.emit({
1297
+ code: "ATTRIBUTE_SLOT_POSITION",
1298
+ kind: "render",
1299
+ severity: "warn",
1300
+ message: why === "fill" ? `[ATTRIBUTE_SLOT_POSITION] Server markup binds \`${occurrence}\` at ${where}, but no client fill ` + `resolves for slot \`${prop}\` — those positions never bind and the elements are inert. ` + `Pass \`${prop}\` to the server component on the client (a function returning the object the ` + `markup reads), or check that the prop name matches on both sides.` : `[ATTRIBUTE_SLOT_POSITION] Server markup binds \`${occurrence}\` at ${where}, but no args record ` + `for it arrived and none can — the fill mounts with empty args. A called slot always emits its ` + `record ahead of the markup that reads it, so this is the frame protocol out of step, not the fill: ` + `a client and server from different builds (a stale dev prebundle, a cached asset), or a runtime ` + `bug minting the marker and the record under different ids.`,
1301
+ data: {
1302
+ reason: "orphan",
1303
+ why,
1304
+ occurrence,
1305
+ elements: consumers.map(c => c.element)
1306
+ }
1307
+ }, null));
1308
+ }
1204
1309
  function devCheckRange(start, id) {
1205
1310
  const end = slotEnd(id);
1206
1311
  let n = start.nextSibling;
@@ -1692,7 +1797,7 @@ function createServerComponentHandler({
1692
1797
  }
1693
1798
  const version = bump(address);
1694
1799
  if (onStream) onStream(address, version, response);
1695
- applyFrameResponse(response, host, {
1800
+ const applied = applyFrameResponse(response, host, {
1696
1801
  as: address,
1697
1802
  version
1698
1803
  }).catch(err => host.apply({
@@ -1703,7 +1808,7 @@ function createServerComponentHandler({
1703
1808
  message: String(err && err.message)
1704
1809
  }
1705
1810
  }));
1706
- return binding;
1811
+ return host.get(address) ? applied.then(() => binding) : binding;
1707
1812
  },
1708
1813
  showing(address, functionId) {
1709
1814
  bindingFor(address, functionId);
@@ -1819,8 +1924,7 @@ function getFrameHost() {
1819
1924
  applyData: c => tableFor(c.id)?.apply(c),
1820
1925
  resolve: (ref, id) => tableFor(id)?.resolve(ref),
1821
1926
  revive: reviveContainerTraces,
1822
- isContainer: isMaterializedContainer,
1823
- delegate: delegateEvents
1927
+ isContainer: isMaterializedContainer
1824
1928
  });
1825
1929
  }
1826
1930
  return sharedHost;
@@ -1919,6 +2023,139 @@ function slotArgsProxy(args) {
1919
2023
  } : undefined
1920
2024
  });
1921
2025
  }
2026
+ function bindDataOccurrence(fill, args, ctx) {
2027
+ const [consumers, setConsumers] = createSignal(ctx.positions);
2028
+ ctx.onRebind(setConsumers);
2029
+ const output = createMemo(() => {
2030
+ const out = fill(args);
2031
+ const node = typeof Node === "function" && out instanceof Node;
2032
+ if ((out == null || typeof out !== "object" || Array.isArray(out) || node)) {
2033
+ const shape = out === null ? "null" : node ? "a DOM node" : Array.isArray(out) ? "an array" : typeof out;
2034
+ slotShapeFinding(ctx.key, shape, `[ATTRIBUTE_SLOT_POSITION] The fill for \`${ctx.key}\` returned ${shape}; server markup reads ` + `its properties at bound positions, so it must return an object (\`{ done, toggle, … }\`). ` + `Nothing binds until it does.`);
2035
+ }
2036
+ return out == null || typeof out !== "object" || node ? {} : out;
2037
+ });
2038
+ const state = new WeakMap();
2039
+ let bound = new Set();
2040
+ createRenderEffect(() => {
2041
+ const out = output();
2042
+ return consumers().map(({
2043
+ element,
2044
+ positions
2045
+ }) => ({
2046
+ element,
2047
+ ...propsFor(element, positions, out)
2048
+ }));
2049
+ }, writes => {
2050
+ const next = new Set();
2051
+ for (const {
2052
+ element,
2053
+ props,
2054
+ handlers
2055
+ } of writes) {
2056
+ next.add(element);
2057
+ write(element, props, handlers);
2058
+ }
2059
+ for (const element of bound) if (!next.has(element)) write(element, {}, {});
2060
+ bound = next;
2061
+ });
2062
+ onCleanup(() => {
2063
+ for (const element of bound) write(element, {}, {});
2064
+ });
2065
+ function write(element, props, handlers) {
2066
+ const st = state.get(element);
2067
+ for (const k in st.prev) if (!(k in props) && k !== "ref") delete st.prev[k];
2068
+ assign(element, props, true, st.prev);
2069
+ st.keys = handlers;
2070
+ for (const name of st.on) {
2071
+ if (!(name in handlers)) {
2072
+ element.removeEventListener(name, st.listener);
2073
+ st.on.delete(name);
2074
+ }
2075
+ }
2076
+ for (const name in handlers) {
2077
+ if (!st.on.has(name)) {
2078
+ element.addEventListener(name, st.listener);
2079
+ st.on.add(name);
2080
+ }
2081
+ }
2082
+ }
2083
+ function propsFor(element, positions, out) {
2084
+ let st = state.get(element);
2085
+ if (!st) {
2086
+ const s = {
2087
+ prev: {},
2088
+ ref: undefined,
2089
+ refId: "",
2090
+ on: new Set(),
2091
+ keys: {},
2092
+ listener(e) {
2093
+ const o = output();
2094
+ const keys = s.keys[e.type];
2095
+ if (keys === undefined) return;
2096
+ for (const k of keys) {
2097
+ const h = o[k];
2098
+ if (Array.isArray(h)) h[0].call(this, h[1], e);else if (typeof h === "function") h.call(this, e);
2099
+ }
2100
+ }
2101
+ };
2102
+ state.set(element, st = s);
2103
+ }
2104
+ const props = {};
2105
+ const handlers = {};
2106
+ let classNames = null;
2107
+ let styleProps = null;
2108
+ let refKeys = null;
2109
+ for (const {
2110
+ pos,
2111
+ key,
2112
+ name
2113
+ } of positions) {
2114
+ if (pos === "class" || pos === "style") {
2115
+ if (name === undefined) props[pos] = out[key];else if (pos === "class") (classNames || (classNames = {}))[name] = !!out[key];else (styleProps || (styleProps = {}))[name] = out[key];
2116
+ } else if (pos === "ref") {
2117
+ (refKeys || (refKeys = [])).push(key);
2118
+ } else if (pos.startsWith("on:")) {
2119
+ const event = pos.slice(3);
2120
+ (handlers[event] || (handlers[event] = [])).push(key);
2121
+ } else props[pos] = out[key];
2122
+ }
2123
+ if (classNames !== null && !("class" in props)) props.class = classNames;
2124
+ if (styleProps !== null && !("style" in props)) props.style = styleProps;
2125
+ if (refKeys !== null) {
2126
+ const id = refKeys.join(",");
2127
+ if (st.refId !== id) {
2128
+ const keys = refKeys;
2129
+ st.refId = id;
2130
+ st.ref = el => {
2131
+ const o = output();
2132
+ for (const k of keys) {
2133
+ const r = o[k];
2134
+ typeof r === "function" && r(el);
2135
+ }
2136
+ };
2137
+ }
2138
+ props.ref = st.ref;
2139
+ }
2140
+ return {
2141
+ props,
2142
+ handlers
2143
+ };
2144
+ }
2145
+ }
2146
+ function slotShapeFinding(occurrence, shape, message) {
2147
+ DEV.report(OBSERVE.diagnostics.emit({
2148
+ code: "ATTRIBUTE_SLOT_POSITION",
2149
+ kind: "render",
2150
+ severity: "warn",
2151
+ message,
2152
+ data: {
2153
+ reason: "fill-shape",
2154
+ occurrence,
2155
+ shape
2156
+ }
2157
+ }, null));
2158
+ }
1922
2159
  function isReactiveContent(value) {
1923
2160
  if (typeof value === "function") return true;
1924
2161
  if (Array.isArray(value)) {
@@ -1944,6 +2181,26 @@ function slotsFor(props) {
1944
2181
  fillScopes.delete(key);
1945
2182
  prevFill.dispose();
1946
2183
  }
2184
+ if (ctx && ctx.positions) {
2185
+ const fill = props[prop];
2186
+ if (typeof fill !== "function") {
2187
+ {
2188
+ slotShapeFinding(key, typeof fill, `[ATTRIBUTE_SLOT_POSITION] Server markup reads slot \`${prop}\` as data (\`${key}\`), ` + `but the client prop is ${typeof fill === "object" ? "an object" : `a ${typeof fill}`}, ` + `not a function. The fill is a function of the occurrence's args returning the object ` + `the markup reads: \`${prop}={args => ({ … })}\`. Nothing binds until it is.`);
2189
+ }
2190
+ return undefined;
2191
+ }
2192
+ const owner = createOwner();
2193
+ fillScopes.set(key, owner);
2194
+ ctx.onCleanup(() => {
2195
+ if (fillScopes.get(key) === owner) fillScopes.delete(key);
2196
+ owner.dispose();
2197
+ });
2198
+ runWithOwner(owner, () => {
2199
+ const args = ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotArgsProxy(() => slotProps);
2200
+ bindDataOccurrence(fill, args, ctx);
2201
+ });
2202
+ return undefined;
2203
+ }
1947
2204
  const fillOwner = streamInvoke ? createOwner() : null;
1948
2205
  if (fillOwner && key !== undefined && ctx) {
1949
2206
  fillScopes.set(key, fillOwner);
@@ -2024,7 +2281,6 @@ function boundaryComponent(host, fnId) {
2024
2281
  host,
2025
2282
  id,
2026
2283
  slots: slotsFor(props),
2027
- props,
2028
2284
  ownerScope: boundaryScope(owner),
2029
2285
  reveal: revealSeam(owner),
2030
2286
  onApply: () => {
@@ -2228,7 +2484,6 @@ function adoptBoundary(host, id, el, props, binding) {
2228
2484
  host,
2229
2485
  id: address,
2230
2486
  slots: slotsFor(props),
2231
- props,
2232
2487
  ownerScope: boundaryScope(owner),
2233
2488
  reveal: revealSeam(owner),
2234
2489
  onApply: () => {