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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/server.dev.js +705 -151
  2. package/dist/server.js +604 -123
  3. package/dist/server.observe.js +617 -124
  4. package/dist/web.dev.js +102 -41
  5. package/dist/web.js +75 -37
  6. package/dist/web.observe.js +75 -39
  7. package/frames/dist/assets.js +92 -0
  8. package/frames/dist/bind.dev.js +326 -0
  9. package/frames/dist/bind.js +295 -0
  10. package/frames/dist/client.dev.js +693 -919
  11. package/frames/dist/client.js +636 -917
  12. package/frames/dist/client.observe.js +637 -917
  13. package/frames/dist/regions.js +130 -0
  14. package/frames/dist/server.dev.js +607 -212
  15. package/frames/dist/server.js +554 -212
  16. package/frames/dist/server.observe.js +554 -212
  17. package/frames/dist/trace.js +42 -0
  18. package/frames/dist/wire.js +133 -0
  19. package/package.json +30 -3
  20. package/performance-tracks/dist/performance-tracks.dev.js +2 -1
  21. package/performance-tracks/dist/performance-tracks.observe.js +2 -1
  22. package/performance-tracks/types/index.d.ts +8 -6
  23. package/serialization/dist/decode.js +37 -8
  24. package/serialization/dist/serialization.js +39 -10
  25. package/serialization/types/serializer-decode.d.ts +24 -2
  26. package/server-functions/dist/client.dev.js +178 -72
  27. package/server-functions/dist/client.js +99 -61
  28. package/server-functions/dist/client.observe.js +178 -72
  29. package/server-functions/dist/server.dev.js +117 -56
  30. package/server-functions/dist/server.js +117 -56
  31. package/server-functions/dist/server.observe.js +117 -56
  32. package/skills/server-components/SKILL.md +228 -0
  33. package/types/client.d.ts +37 -2
  34. package/types/constants.d.ts +2 -1
  35. package/types/diagnostics.d.ts +8 -0
  36. package/types/frames/assets-tier.d.ts +78 -0
  37. package/types/frames/bind-tier.d.ts +60 -0
  38. package/types/frames/client.d.ts +37 -3
  39. package/types/frames/frame-client.d.ts +249 -96
  40. package/types/frames/frame-container-plugin.d.ts +2 -10
  41. package/types/frames/frame-sink.d.ts +33 -0
  42. package/types/frames/frame-transport.d.ts +66 -18
  43. package/types/frames/regions-tier.d.ts +45 -0
  44. package/types/frames/serializer-decode.d.ts +24 -2
  45. package/types/frames/server.d.ts +53 -1
  46. package/types/frames/trace-tier.d.ts +2 -0
  47. package/types/frames/tree-rewrite.d.ts +39 -0
  48. package/types/frames/wire-tier.d.ts +116 -0
  49. package/types/index.d.ts +38 -0
  50. package/types/index.server.d.ts +10 -1
  51. package/types/jsx.d.ts +11 -1
  52. package/types/observe.d.ts +182 -12
  53. package/types/request-error-hook.d.ts +5 -0
  54. package/types/serializer-decode.d.ts +24 -2
  55. package/types/server-functions/client.d.ts +26 -0
  56. package/types/server-functions/registry.d.ts +4 -1
  57. package/types/server-functions/shared.d.ts +12 -8
  58. package/types/server-mock.d.ts +13 -1
  59. package/types/server-observe.d.ts +8 -0
  60. package/types/server.d.ts +125 -12
@@ -1,10 +1,100 @@
1
- import { ssrSanitizeError, creationStamp, ssrHandleError, runInServerComponentScope, shareAsyncIterable, getProjectionTrace } from 'solid-js/internal';
2
- import { sharedConfig, NoHydration, getOwner, runWithOwner, createMemo, Hydration, createOwner } from 'solid-js';
3
- import { isResponseEnvelope, renderToStream, createLiveHoles, CLAIMS_STREAM, CLAIMS_DOCUMENT, CLAIM_PROP } from '@solidjs/web';
1
+ import { sharedConfig, ssrSanitizeError, creationStamp, ssrHandleError, runInServerComponentScope, shareAsyncIterable, getProjectionTrace } from 'solid-js/internal';
2
+ import { OBSERVE, DEV, getOwner, NoHydration, runWithOwner, createMemo, Hydration, createOwner } from 'solid-js';
3
+ import { isResponseEnvelope, renderToStream, createLiveHoles, CLAIMS_STREAM, CLAIMS_DOCUMENT, SLOT_FACE_DATA, SLOT_FACE_MARKUP, slotValue, SLOT_FACE_STREAM, isSlotValue, SLOT_VALUE } from '@solidjs/web';
4
4
  import { Feature, createStream, toCrossJSONStream } from 'seroval';
5
5
  import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
6
6
  import { textDigest, frameAddress, getEventServerFunctionInvocation, armLiveBody, createEventChunk, createChunk, ChunkReader, serializeStream, guardFailures } from '@solidjs/web/server-functions/server';
7
7
 
8
+ const DESCEND = Symbol("descend");
9
+ const CYCLE = {};
10
+ const TRACK = 16;
11
+ function rewriteTree(value, visit, withPath) {
12
+ if (value === null || typeof value !== "object") return value;
13
+ const path = withPath ? "" : undefined;
14
+ const state = {
15
+ memo: undefined,
16
+ ancestors: undefined
17
+ };
18
+ try {
19
+ return cow(value, visit, path, 0, state);
20
+ } catch (err) {
21
+ if (err !== CYCLE) throw err;
22
+ }
23
+ return clone(value, visit, path, state.memo || (state.memo = new Map()));
24
+ }
25
+ function shape(value) {
26
+ return Array.isArray(value) ? 1 : Object.getPrototypeOf(value) === Object.prototype ? 2 : 0;
27
+ }
28
+ function cow(value, visit, path, depth, state) {
29
+ const memo = state.memo;
30
+ if (memo !== undefined && memo.has(value)) return memo.get(value);
31
+ const r = visit(value, path);
32
+ if (r !== DESCEND) {
33
+ if (r !== value) (memo || (state.memo = new Map())).set(value, r);
34
+ return r;
35
+ }
36
+ const s = shape(value);
37
+ if (s === 0) return value;
38
+ let ancestors;
39
+ if (depth >= TRACK) {
40
+ ancestors = state.ancestors || (state.ancestors = new Set());
41
+ if (ancestors.has(value)) throw CYCLE;
42
+ ancestors.add(value);
43
+ }
44
+ let out = value;
45
+ if (s === 1) {
46
+ for (let i = 0; i < value.length; i++) {
47
+ const c = value[i];
48
+ if (c === null || typeof c !== "object") continue;
49
+ const next = cow(c, visit, path === undefined ? undefined : `${path}[${i}]`, depth + 1, state);
50
+ if (next !== c) {
51
+ if (out === value) out = value.slice();
52
+ out[i] = next;
53
+ }
54
+ }
55
+ } else {
56
+ for (const k of Object.keys(value)) {
57
+ const c = value[k];
58
+ if (c === null || typeof c !== "object") continue;
59
+ const next = cow(c, visit, path === undefined ? undefined : `${path}.${k}`, depth + 1, state);
60
+ if (next !== c) {
61
+ if (out === value) out = {
62
+ ...value
63
+ };
64
+ out[k] = next;
65
+ }
66
+ }
67
+ }
68
+ if (ancestors !== undefined) ancestors.delete(value);
69
+ return out;
70
+ }
71
+ function clone(value, visit, path, memo) {
72
+ if (memo.has(value)) return memo.get(value);
73
+ const r = visit(value, path);
74
+ if (r !== DESCEND) {
75
+ memo.set(value, r);
76
+ return r;
77
+ }
78
+ const s = shape(value);
79
+ if (s === 0) return value;
80
+ const out = s === 1 ? value.slice() : {
81
+ ...value
82
+ };
83
+ memo.set(value, out);
84
+ if (s === 1) {
85
+ for (let i = 0; i < value.length; i++) {
86
+ const c = value[i];
87
+ if (c !== null && typeof c === "object") out[i] = clone(c, visit, path === undefined ? undefined : `${path}[${i}]`, memo);
88
+ }
89
+ } else {
90
+ for (const k of Object.keys(value)) {
91
+ const c = value[k];
92
+ if (c !== null && typeof c === "object") out[k] = clone(c, visit, path === undefined ? undefined : `${path}.${k}`, memo);
93
+ }
94
+ }
95
+ return out;
96
+ }
97
+
8
98
  const STATE = Symbol.for("solid.container-trace-state");
9
99
  const state = globalThis[STATE] || (globalThis[STATE] = {
10
100
  materialized: new WeakMap(),
@@ -29,38 +119,16 @@ function toBorderForm(value, envelopeContainers) {
29
119
  const resolve = state.resolveTrace ;
30
120
  const share = state.shareIterable;
31
121
  if (!resolve && !share) return value;
32
- if (resolve) {
33
- const trace = resolve(value);
34
- if (trace) return {
35
- [TRACE]: trace
36
- };
37
- }
38
- if (share && isShareableIterable(value)) return share(value);
39
- if (Array.isArray(value)) {
40
- let out = value;
41
- for (let i = 0; i < value.length; i++) {
42
- const next = toBorderForm(value[i]);
43
- if (next !== value[i]) {
44
- if (out === value) out = value.slice();
45
- out[i] = next;
46
- }
47
- }
48
- return out;
49
- }
50
- if (Object.getPrototypeOf(value) === Object.prototype) {
51
- let out = value;
52
- for (const key of Object.keys(value)) {
53
- const next = toBorderForm(value[key]);
54
- if (next !== value[key]) {
55
- if (out === value) out = {
56
- ...value
57
- };
58
- out[key] = next;
59
- }
122
+ return rewriteTree(value, v => {
123
+ if (resolve) {
124
+ const trace = resolve(v);
125
+ if (trace) return {
126
+ [TRACE]: trace
127
+ };
60
128
  }
61
- return out;
62
- }
63
- return value;
129
+ if (share && isShareableIterable(v)) return share(v);
130
+ return DESCEND;
131
+ }, false);
64
132
  }
65
133
  function isShareableIterable(value) {
66
134
  try {
@@ -71,10 +139,10 @@ function isShareableIterable(value) {
71
139
  return false;
72
140
  }
73
141
  }
74
- function materialize(marker) {
142
+ function materialize(marker, claiming) {
75
143
  let value = state.materialized.get(marker.$tr);
76
144
  if (value === undefined) {
77
- value = state.materializeTrace(marker);
145
+ value = state.materializeTrace(marker, claiming);
78
146
  state.materialized.set(marker.$tr, value);
79
147
  if (value !== null && typeof value === "object") state.materializedValues.add(value);
80
148
  }
@@ -120,6 +188,15 @@ const ContainerTracePlugin = {
120
188
  }
121
189
  };
122
190
 
191
+ function emitFinding(finding, subject = getOwner()) {
192
+ if (OBSERVE === undefined) return;
193
+ const entry = OBSERVE.diagnostics.emit(finding, subject);
194
+ if (DEV !== undefined) DEV.report(entry);
195
+ }
196
+ function devCheck(finding, subject) {
197
+ emitFinding(finding, subject);
198
+ }
199
+
123
200
  setContainerTraceStreamMint(iterable => {
124
201
  const stream = createStream();
125
202
  (async () => {
@@ -132,14 +209,14 @@ setContainerTraceStreamMint(iterable => {
132
209
  })();
133
210
  return stream;
134
211
  });
135
- const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
212
+ const DEFAULT_WEB_PLUGINS = /* @__PURE__ */Object.freeze([AbortSignalPlugin,
136
213
  CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
137
214
  FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin,
138
215
  ContainerTracePlugin]);
139
216
  function resolveSerializerPlugins(customPlugins) {
140
217
  return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
141
218
  }
142
- const JSON_CODEC_DISABLED_FEATURES = Feature.RegExp;
219
+ const jsonCodecDisabledFeatures = () => Feature.RegExp;
143
220
  const JSON_CODEC_DEPTH_LIMIT = 64;
144
221
  function resolveCodecOptions({
145
222
  plugins,
@@ -149,13 +226,12 @@ function resolveCodecOptions({
149
226
  } = {}) {
150
227
  return {
151
228
  plugins: resolveSerializerPlugins(plugins),
152
- disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
229
+ disabledFeatures: disabledFeatures === undefined ? jsonCodecDisabledFeatures() : disabledFeatures,
153
230
  depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit,
154
231
  serializeErrorStacks
155
232
  };
156
233
  }
157
234
 
158
- Feature.AggregateError | Feature.BigIntTypedArray;
159
235
  const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : Feature.ErrorPrototypeStack;
160
236
  function createJSONSerializer({
161
237
  onData,
@@ -282,6 +358,7 @@ function observeFrame(frame) {
282
358
  }
283
359
 
284
360
  const FRAME_STREAM_HEADER = "X-Frame-Stream";
361
+ const FRAME_TIERS_HEADER = "X-Frame-Tiers";
285
362
  const FRAME_HAVE_HEADER = "X-Frame-Have";
286
363
  const FRAME_HAVE_BUDGET = 4096;
287
364
  function decodeHaveList(text) {
@@ -412,11 +489,27 @@ function withHoles(chunk, holes) {
412
489
  }
413
490
  return chunk;
414
491
  }
415
- function createFrameSink(emit, frame, have) {
492
+ function createFrameSink(write, frame, have, hooks) {
416
493
  const {
417
494
  id,
418
495
  version
419
496
  } = frame;
497
+ const tiers = new Set();
498
+ let staged = [];
499
+ const emit = chunk => {
500
+ if (swept) swept.emitted = true;
501
+ if (staged.length) {
502
+ chunk.tiers = staged;
503
+ staged = [];
504
+ }
505
+ write(chunk);
506
+ };
507
+ const needs = name => {
508
+ if (!tiers.has(name)) {
509
+ tiers.add(name);
510
+ staged.push(name);
511
+ }
512
+ };
420
513
  let conditional = false;
421
514
  const skipped = new Set();
422
515
  const attrText = new Map();
@@ -456,15 +549,38 @@ function createFrameSink(emit, frame, have) {
456
549
  let sweepScheduled = false;
457
550
  let closed = false;
458
551
  let epoch = 0;
552
+ let swept = null;
459
553
  const sweep = () => {
460
554
  epoch++;
461
- for (const b of [...bindings.values()]) {
462
- try {
463
- b.sweep();
464
- } catch (_) {
555
+ const pass = swept = {
556
+ ops: [],
557
+ emitted: false
558
+ };
559
+ try {
560
+ for (const b of [...bindings.values()]) {
561
+ try {
562
+ b.sweep();
563
+ } catch (_) {
564
+ }
465
565
  }
566
+ emitOps(pass.ops);
567
+ if (pass.emitted && hooks && hooks.onYield) hooks.onYield();
568
+ } finally {
569
+ swept = null;
466
570
  }
467
571
  };
572
+ const emitOps = ops => {
573
+ if (ops.length === 1) emit(Object.assign({
574
+ type: ops[0].type,
575
+ id,
576
+ version
577
+ }, ops[0]));else if (ops.length) emit({
578
+ type: "ops",
579
+ id,
580
+ version,
581
+ ops
582
+ });
583
+ };
468
584
  const scheduleSweep = () => {
469
585
  if (closed || sweepScheduled || !bindings.size) return;
470
586
  sweepScheduled = true;
@@ -508,6 +624,7 @@ function createFrameSink(emit, frame, have) {
508
624
  chunk.preloads.push(wirePreload(entry));
509
625
  }
510
626
  }
627
+ needs("assets");
511
628
  emit(chunk);
512
629
  }
513
630
  emit(withHoles({
@@ -583,6 +700,7 @@ function createFrameSink(emit, frame, have) {
583
700
  attrs: e.attrs
584
701
  }));
585
702
  }
703
+ needs("assets");
586
704
  emit(chunk);
587
705
  }
588
706
  emit(withHoles({
@@ -640,6 +758,7 @@ function createFrameSink(emit, frame, have) {
640
758
  },
641
759
  asset(type, value) {
642
760
  if (type === "module") {
761
+ needs("assets");
643
762
  emit({
644
763
  type: "assets",
645
764
  id,
@@ -648,6 +767,7 @@ function createFrameSink(emit, frame, have) {
648
767
  modules: [value]
649
768
  });
650
769
  } else if (type === "preload") {
770
+ needs("assets");
651
771
  emit({
652
772
  type: "assets",
653
773
  id,
@@ -657,14 +777,17 @@ function createFrameSink(emit, frame, have) {
657
777
  });
658
778
  }
659
779
  },
660
- end() {
661
- if (bindings.size) sweep();
780
+ end(bound) {
781
+ if (closed) return;
782
+ if (bindings.size && !swept) sweep();
662
783
  closed = true;
663
- emit({
784
+ const chunk = {
664
785
  type: "complete",
665
786
  id,
666
787
  version
667
- });
788
+ };
789
+ if (bound) chunk.bound = bound;
790
+ emit(chunk);
668
791
  },
669
792
  error(errorId, error) {
670
793
  emit({
@@ -685,6 +808,7 @@ function createFrameSink(emit, frame, have) {
685
808
  });
686
809
  },
687
810
  region(childId, html) {
811
+ needs("regions");
688
812
  emit({
689
813
  type: "html",
690
814
  id: childId,
@@ -693,26 +817,23 @@ function createFrameSink(emit, frame, have) {
693
817
  });
694
818
  },
695
819
  hole(key, html) {
696
- emit({
820
+ const op = {
697
821
  type: "hole",
698
- id,
699
- version,
700
822
  key,
701
823
  html,
702
824
  digest: textDigest(html)
703
- });
825
+ };
826
+ swept ? swept.ops.push(op) : emitOps([op]);
704
827
  },
705
828
  attr(key, attrs, removed) {
706
- const chunk = {
829
+ const op = {
707
830
  type: "attr",
708
- id,
709
- version,
710
831
  key,
711
832
  attrs,
712
833
  digest: textDigest(attrs)
713
834
  };
714
- if (removed && removed.length) chunk.removed = removed;
715
- emit(chunk);
835
+ if (removed && removed.length) op.removed = removed;
836
+ swept ? swept.ops.push(op) : emitOps([op]);
716
837
  },
717
838
  attrBaseline(key, text) {
718
839
  attrText.set(key, text);
@@ -734,6 +855,11 @@ function createFrameSink(emit, frame, have) {
734
855
  commit: scheduleSweep,
735
856
  get epoch() {
736
857
  return epoch;
858
+ },
859
+ needs,
860
+ announce() {
861
+ staged = [];
862
+ return [...tiers];
737
863
  }
738
864
  };
739
865
  }
@@ -755,6 +881,10 @@ function renderServerComponent(component, options = {}) {
755
881
  };
756
882
  }, options);
757
883
  }
884
+ const DEFAULT_MAX_YIELDS = 64;
885
+ const DEFAULT_MAX_DURATION_MS = 30_000;
886
+ const DISCONNECTED = Symbol("solid.frames.disconnected");
887
+ const ANNOUNCE = Symbol("solid.frames.announce");
758
888
  function frameStream(makeCode, options) {
759
889
  const {
760
890
  id = "",
@@ -764,30 +894,77 @@ function frameStream(makeCode, options) {
764
894
  id,
765
895
  version
766
896
  };
897
+ const bounded = !options.live;
898
+ const maxYields = bounded ? options.maxYields ?? DEFAULT_MAX_YIELDS : 0;
899
+ const maxDurationMs = bounded ? options.maxDurationMs ?? DEFAULT_MAX_DURATION_MS : 0;
767
900
  function stream(w) {
768
901
  const observation = observeFrame(frame);
769
- const emit = observation ? chunk => {
770
- observation.chunk(chunk);
902
+ const render = new AbortController();
903
+ const upstream = options.signal;
904
+ let ended = false;
905
+ let flushed = false;
906
+ let yields = 0;
907
+ let timer;
908
+ function finish() {
909
+ if (ended) return;
910
+ ended = true;
911
+ if (timer) clearTimeout(timer);
912
+ if (upstream) upstream.removeEventListener("abort", onSignal);
913
+ w.end && w.end();
914
+ }
915
+ function cut(bound) {
916
+ if (ended) return;
917
+ sink.end(bound);
918
+ observation && observation.settle("complete");
919
+ finish();
920
+ render.abort({
921
+ quiet: true,
922
+ bound
923
+ });
924
+ }
925
+ function onSignal() {
926
+ const gone = upstream.reason && upstream.reason[DISCONNECTED];
927
+ if (bounded && flushed && !gone) return cut("time");
928
+ finish();
929
+ render.abort(upstream.reason);
930
+ }
931
+ const emit = chunk => {
932
+ if (observation) observation.chunk(chunk);
771
933
  w.write(chunk);
772
- } : chunk => w.write(chunk);
773
- const sink = createFrameSink(emit, frame, options.resume && options.resume.have);
934
+ if (bounded && !flushed && chunk.type === "html" && chunk.id === id) {
935
+ flushed = true;
936
+ if (maxDurationMs > 0 && maxDurationMs !== Infinity) timer = setTimeout(() => cut("time"), maxDurationMs);
937
+ }
938
+ };
939
+ const sink = createFrameSink(emit, frame, options.resume && options.resume.have, bounded ? {
940
+ onYield() {
941
+ if (flushed && maxYields > 0 && ++yields >= maxYields) cut("yields");
942
+ }
943
+ } : undefined);
944
+ if (options.live) sink.needs("wire");
774
945
  w.write({
775
946
  type: "start",
776
947
  id,
777
948
  version
778
949
  });
950
+ if (upstream && upstream.aborted) return finish();
951
+ if (upstream) upstream.addEventListener("abort", onSignal, {
952
+ once: true
953
+ });
779
954
  const code = makeCode(sink, frame);
780
955
  try {
781
956
  renderToStream(() => serverOwned(code), {
782
957
  serializer: createJSONSerializer,
783
958
  ...options,
959
+ signal: render.signal,
784
960
  sink
785
961
  }).pipe({
786
962
  write() {},
787
963
  end() {
964
+ if (ended) return;
788
965
  sink.end();
789
966
  observation && observation.settle("complete");
790
- w.end && w.end();
967
+ finish();
791
968
  }
792
969
  });
793
970
  } catch (err) {
@@ -795,8 +972,9 @@ function frameStream(makeCode, options) {
795
972
  sink.error("", wire instanceof Error ? wire.message : String(wire));
796
973
  sink.end();
797
974
  observation && observation.settle("error", err);
798
- w.end && w.end();
975
+ finish();
799
976
  }
977
+ if (w[ANNOUNCE]) w[ANNOUNCE](sink.announce());
800
978
  }
801
979
  return {
802
980
  pipe: stream,
@@ -818,9 +996,100 @@ function frameStream(makeCode, options) {
818
996
  function slotRange(occurrence) {
819
997
  return {
820
998
  t: `<!--slot:${occurrence}:start--><!--slot:${occurrence}:end-->`,
821
- $slot: true
999
+ $slot: true,
1000
+ $occurrence: occurrence
822
1001
  };
823
1002
  }
1003
+ const RANGE_KEYS = new Set(["t", "h", "p", "then", "length", "slice", "constructor", "toString", "valueOf", "toJSON"]);
1004
+ const NODE_KEYS = new Set(["t", "h", "p"]);
1005
+ function isRangeKey(key) {
1006
+ const c = key.charCodeAt(0);
1007
+ return c === 36 || c >= 48 && c <= 57 || RANGE_KEYS.has(key);
1008
+ }
1009
+ function slotProxy(range, occurrence, face, content, onData, needs) {
1010
+ return new Proxy(range, {
1011
+ get(target, key, receiver) {
1012
+ if (typeof key !== "string" || isRangeKey(key)) return Reflect.get(target, key, receiver);
1013
+ if (onData) onData = void onData();
1014
+ if (face !== SLOT_FACE_MARKUP) needs("bind");
1015
+ return slotValue(occurrence, key, content ? content[key] : undefined, face);
1016
+ }
1017
+ });
1018
+ }
1019
+ function argBorderForm(value, key, occurrence, needs) {
1020
+ return toBorderForm(withoutStandIns(value, key, occurrence, needs));
1021
+ }
1022
+ function withoutStandIns(value, key, occurrence, needs) {
1023
+ return rewriteTree(value, (v, path) => {
1024
+ if (isContainerTraced(v)) {
1025
+ needs("trace");
1026
+ return v;
1027
+ }
1028
+ if (Object.getPrototypeOf(v) === Object.prototype && isSlotValue(v)) {
1029
+ standInArgFinding(v, key, occurrence, path);
1030
+ return undefined;
1031
+ }
1032
+ return DESCEND;
1033
+ }, true);
1034
+ }
1035
+ function standInArgFinding(sv, key, occurrence, path) {
1036
+ {
1037
+ const ctx = sharedConfig.context;
1038
+ if (ctx) {
1039
+ const id = `${occurrence}\u0000${key}${path}\u0000arg`;
1040
+ const seen = ctx.slotFindings || (ctx.slotFindings = new Set());
1041
+ if (seen.has(id)) return;
1042
+ seen.add(id);
1043
+ }
1044
+ const where = path === "" ? `Arg \`${key}\`` : `Arg \`${key}${path}\``;
1045
+ devCheck({
1046
+ code: "BINDING_SLOT_POSITION",
1047
+ kind: "ssr",
1048
+ severity: "warn",
1049
+ message: `[BINDING_SLOT_POSITION] ${where} of \`${occurrence}\` is another slot's value ` + `(\`${sv.k}\` of \`${sv[SLOT_VALUE]}\`). The server does not have it — the client owns ` + `it — so it cannot be passed as data; the arg carries \`undefined\` there on both faces. ` + `Pass the server's own value, or have the client fill read it from its own state.`,
1050
+ data: {
1051
+ reason: "arg",
1052
+ occurrence,
1053
+ key,
1054
+ path: path === "" ? undefined : path,
1055
+ from: sv[SLOT_VALUE],
1056
+ fromKey: sv.k
1057
+ }
1058
+ });
1059
+ }
1060
+ }
1061
+ function slotFace(range, content) {
1062
+ if (content == null) return SLOT_FACE_DATA;
1063
+ if (typeof content !== "object" || Array.isArray(content)) return SLOT_FACE_MARKUP;
1064
+ if (isServerContent(content)) {
1065
+ let data = false;
1066
+ for (const key in content) {
1067
+ if (!NODE_KEYS.has(key)) {
1068
+ data = true;
1069
+ break;
1070
+ }
1071
+ }
1072
+ if (!data) return SLOT_FACE_MARKUP;
1073
+ }
1074
+ {
1075
+ for (const key of Object.keys(content)) {
1076
+ if (isRangeKey(key)) {
1077
+ devCheck({
1078
+ code: "BINDING_SLOT_POSITION",
1079
+ kind: "ssr",
1080
+ severity: "warn",
1081
+ message: `[BINDING_SLOT_POSITION] The fill for \`${range.$occurrence}\` returned a key named \`${key}\`, ` + `which is reserved (keys beginning with \`$\` or a digit, \`length\`, \`slice\`, the node keys \`t\`/\`h\`/\`p\`, ` + `\`then\`, \`constructor\`, \`toString\`, \`valueOf\`, \`toJSON\`): the server reads it as the ` + `slot's range, not as a value. Rename it.`,
1082
+ data: {
1083
+ reason: "reserved-key",
1084
+ occurrence: range.$occurrence,
1085
+ key
1086
+ }
1087
+ });
1088
+ }
1089
+ }
1090
+ }
1091
+ return SLOT_FACE_DATA;
1092
+ }
824
1093
  const OCCURRENCE_UNSAFE = /[^A-Za-z0-9_.-]/g;
825
1094
  function encodeOccurrenceKey(key) {
826
1095
  return String(key).replace(OCCURRENCE_UNSAFE, c => {
@@ -829,14 +1098,58 @@ function encodeOccurrenceKey(key) {
829
1098
  });
830
1099
  }
831
1100
  function occurrenceId(prop, raw, counts) {
832
- const k = raw.$key;
833
- if (typeof k === "string" || typeof k === "number") {
834
- return `${prop}#${encodeOccurrenceKey(k)}`;
835
- }
1101
+ const keyed = keyedId(prop, raw);
1102
+ if (keyed !== undefined) return keyed;
836
1103
  const n = counts[prop] || 0;
837
1104
  counts[prop] = n + 1;
838
1105
  return `${prop}#${n}`;
839
1106
  }
1107
+ function keyedId(prop, raw) {
1108
+ const k = raw.$key;
1109
+ return typeof k === "string" || typeof k === "number" ? `${prop}#${encodeOccurrenceKey(k)}` : undefined;
1110
+ }
1111
+ function structuralArgsKey(raw) {
1112
+ let out = "";
1113
+ let ancestors;
1114
+ const walk = (v, top) => {
1115
+ if (v === null) out += "N";else if (typeof v === "string") out += "s" + v.length + ":" + v;else if (typeof v === "boolean") out += v ? "T" : "F";else if (typeof v === "undefined") out += "U";else if (typeof v === "number") out += "n" + v + ";";else if (typeof v === "bigint") out += "b" + v + ";";else if (typeof v !== "object") return false;else {
1116
+ const isArray = Array.isArray(v);
1117
+ if (!isArray) {
1118
+ const proto = Object.getPrototypeOf(v);
1119
+ if (proto !== Object.prototype && proto !== null) return false;
1120
+ }
1121
+ if (ancestors === undefined) ancestors = new Set();else if (ancestors.has(v)) return false;
1122
+ ancestors.add(v);
1123
+ try {
1124
+ if (isArray) {
1125
+ out += "[";
1126
+ for (const item of v) if (!walk(item)) return false;
1127
+ out += "]";
1128
+ } else {
1129
+ out += "{";
1130
+ for (const k of Object.keys(v).sort()) {
1131
+ if (top && k === "$key") continue;
1132
+ const desc = Object.getOwnPropertyDescriptor(v, k);
1133
+ if (desc.get || desc.set) return false;
1134
+ out += "k" + k.length + ":" + k;
1135
+ if (!walk(desc.value)) return false;
1136
+ }
1137
+ out += "}";
1138
+ }
1139
+ } finally {
1140
+ ancestors.delete(v);
1141
+ }
1142
+ }
1143
+ return true;
1144
+ };
1145
+ return walk(raw, true) ? out : undefined;
1146
+ }
1147
+ function repeatKey(prop, raw) {
1148
+ const keyed = keyedId(prop, raw);
1149
+ if (keyed !== undefined) return keyed;
1150
+ const structural = structuralArgsKey(raw);
1151
+ return structural === undefined ? undefined : prop + "\0" + structural;
1152
+ }
840
1153
  function isAsyncValue(v) {
841
1154
  return !!v && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
842
1155
  }
@@ -865,6 +1178,7 @@ function suppressedFill(render) {
865
1178
  function createDocumentSlotProps(clientProps, frameId) {
866
1179
  const counts = Object.create(null);
867
1180
  const getters = new Map();
1181
+ const repeats = new Map();
868
1182
  const range = (occurrence, content) => {
869
1183
  const r = [{
870
1184
  t: `<!--slot:${occurrence}:start-->`
@@ -872,7 +1186,10 @@ function createDocumentSlotProps(clientProps, frameId) {
872
1186
  t: `<!--slot:${occurrence}:end-->`
873
1187
  }];
874
1188
  r.$slot = true;
875
- return r;
1189
+ r.$occurrence = occurrence;
1190
+ const face = slotFace(r, content);
1191
+ r.$face = face;
1192
+ return slotProxy(r, occurrence, face, face === SLOT_FACE_DATA ? content : undefined, undefined, documentNeeds);
876
1193
  };
877
1194
  const zoneOwner = getOwner ? getOwner() : null;
878
1195
  const scoped = (occurrence, render) => {
@@ -896,147 +1213,170 @@ function createDocumentSlotProps(clientProps, frameId) {
896
1213
  if (!fn) {
897
1214
  fn = (...callArgs) => {
898
1215
  if (callArgs.length === 0 || callArgs[0] === undefined) {
899
- return suppressedFill(() => scoped(prop, () => {
1216
+ const rk = prop + "\0";
1217
+ const repeat = repeats.get(rk);
1218
+ if (repeat) return repeat;
1219
+ const out = suppressedFill(() => scoped(prop, () => {
900
1220
  const value = clientProps[prop];
901
1221
  return range(prop, typeof value === "function" ? value() : value);
902
1222
  }));
1223
+ if (out.$face === SLOT_FACE_DATA) repeats.set(rk, out);
1224
+ return out;
903
1225
  }
904
1226
  const raw = callArgs[0];
1227
+ const rk = repeatKey(prop, raw);
1228
+ const repeat = rk !== undefined && repeats.get(rk);
1229
+ if (repeat) return repeat;
905
1230
  const occurrence = occurrenceId(prop, raw, counts);
906
1231
  const slot = clientProps[prop];
907
1232
  if (typeof slot !== "function") return range(occurrence, undefined);
908
- const resolved = {};
909
- const liveArgs = sharedConfig.context && sharedConfig.context.live && sharedConfig.context.live.args;
910
- const vals = {};
911
- const evals = {};
912
- const states = {};
913
- const minted = {};
914
- for (const key of Object.keys(raw)) {
915
- if (key === "$key") continue;
916
- const desc = Object.getOwnPropertyDescriptor(raw, key);
917
- let evaluate = null;
918
- let value;
919
- if (desc.get) {
920
- const get = desc.get;
921
- evaluate = () => unwrapThunks(get.call(raw));
922
- } else {
923
- value = desc.value;
924
- if (typeof value === "function") {
925
- const fn = value;
926
- evaluate = () => unwrapThunks(fn);
1233
+ const context = sharedConfig.context;
1234
+ const recordKey = `sc:slot:${frameId}:${occurrence}`;
1235
+ let settleRecord;
1236
+ if (context && context.async) {
1237
+ context.serialize(recordKey, new Promise(resolve => settleRecord = resolve));
1238
+ }
1239
+ try {
1240
+ const resolved = {};
1241
+ const liveArgs = sharedConfig.context && sharedConfig.context.live && sharedConfig.context.live.args;
1242
+ const vals = {};
1243
+ const evals = {};
1244
+ const states = {};
1245
+ const minted = {};
1246
+ for (const key of Object.keys(raw)) {
1247
+ if (key === "$key") continue;
1248
+ const desc = Object.getOwnPropertyDescriptor(raw, key);
1249
+ let evaluate = null;
1250
+ let value;
1251
+ if (desc.get) {
1252
+ const get = desc.get;
1253
+ evaluate = () => unwrapThunks(get.call(raw));
1254
+ } else {
1255
+ value = desc.value;
1256
+ if (typeof value === "function") {
1257
+ const fn = value;
1258
+ evaluate = () => unwrapThunks(fn);
1259
+ }
1260
+ }
1261
+ if (evaluate) {
1262
+ evals[key] = evaluate;
1263
+ const stampBefore = scopeStamp();
1264
+ try {
1265
+ value = evaluate();
1266
+ states[key] = {
1267
+ settled: true,
1268
+ last: value
1269
+ };
1270
+ } catch (err) {
1271
+ const blocked = ssrHandleError && ssrHandleError(err);
1272
+ if (!blocked) throw err;
1273
+ const state = states[key] = {
1274
+ settled: false,
1275
+ last: undefined
1276
+ };
1277
+ value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
1278
+ state.settled = true;
1279
+ state.last = v;
1280
+ if (liveArgs) liveArgs.commit();
1281
+ });
1282
+ }
1283
+ if (scopeStamp() !== stampBefore) minted[key] = true;
927
1284
  }
1285
+ vals[key] = value;
928
1286
  }
929
- if (evaluate) {
930
- evals[key] = evaluate;
931
- const stampBefore = scopeStamp();
932
- try {
933
- value = evaluate();
934
- states[key] = {
935
- settled: true,
936
- last: value
1287
+ const regions = [];
1288
+ for (const key of Object.keys(vals)) {
1289
+ const value = vals[key];
1290
+ if (isContainerTraced(value)) {
1291
+ documentNeeds("trace");
1292
+ resolved[key] = value;
1293
+ } else if (isServerContent(value)) {
1294
+ const childId = `${frameId}.${occurrence}.${key}`;
1295
+ const region = {
1296
+ key,
1297
+ childId,
1298
+ value,
1299
+ used: false,
1300
+ locked: false
937
1301
  };
938
- } catch (err) {
939
- const blocked = ssrHandleError && ssrHandleError(err);
940
- if (!blocked) throw err;
941
- const state = states[key] = {
942
- settled: false,
943
- last: undefined
1302
+ regions.push(region);
1303
+ documentNeeds("regions");
1304
+ resolved[key] = () => {
1305
+ if (region.locked) return [];
1306
+ region.used = true;
1307
+ return [{
1308
+ t: frameElementOpen(childId)
1309
+ }, value, {
1310
+ t: FRAME_ELEMENT_CLOSE
1311
+ }];
944
1312
  };
945
- value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
946
- state.settled = true;
947
- state.last = v;
948
- if (liveArgs) liveArgs.commit();
1313
+ } else if (ssrAsyncValue && isAsyncValue(value)) {
1314
+ let readable = value;
1315
+ if (typeof value.then !== "function") {
1316
+ const {
1317
+ first,
1318
+ rest
1319
+ } = tapFirstYield(value);
1320
+ readable = first;
1321
+ vals[key] = rest;
1322
+ }
1323
+ const read = ssrAsyncValue(readable);
1324
+ Object.defineProperty(resolved, key, {
1325
+ get: read,
1326
+ enumerable: true,
1327
+ configurable: true
949
1328
  });
1329
+ } else {
1330
+ resolved[key] = vals[key] = withoutStandIns(value, key, occurrence, documentNeeds);
950
1331
  }
951
- if (scopeStamp() !== stampBefore) minted[key] = true;
952
1332
  }
953
- vals[key] = value;
954
- }
955
- const regions = [];
956
- for (const key of Object.keys(vals)) {
957
- const value = vals[key];
958
- if (isContainerTraced(value)) {
959
- resolved[key] = value;
960
- } else if (isServerContent(value)) {
961
- const childId = `${frameId}.${occurrence}.${key}`;
962
- const region = {
963
- key,
964
- childId,
965
- value,
966
- used: false,
967
- locked: false
968
- };
969
- regions.push(region);
970
- resolved[key] = () => {
971
- if (region.locked) return [];
972
- region.used = true;
973
- return [{
974
- t: frameElementOpen(childId)
975
- }, value, {
976
- t: FRAME_ELEMENT_CLOSE
977
- }];
978
- };
979
- } else if (ssrAsyncValue && isAsyncValue(value)) {
980
- let readable = value;
981
- if (typeof value.then !== "function") {
982
- const {
983
- first,
984
- rest
985
- } = tapFirstYield(value);
986
- readable = first;
987
- vals[key] = rest;
1333
+ const out = suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved))));
1334
+ const unused = regions.filter(r => !r.used);
1335
+ if (context) {
1336
+ const args = {};
1337
+ for (const key of Object.keys(vals)) {
1338
+ const value = vals[key];
1339
+ const region = regions.find(r => r.key === key);
1340
+ if (region) {
1341
+ args[key] = {
1342
+ $frame: region.childId
1343
+ };
1344
+ continue;
1345
+ }
1346
+ if (!isContainerTraced(value) && isServerContent(value)) continue;
1347
+ args[key] = argBorderForm(value, key, occurrence, documentNeeds);
988
1348
  }
989
- const read = ssrAsyncValue(readable);
990
- Object.defineProperty(resolved, key, {
991
- get: read,
992
- enumerable: true,
993
- configurable: true
1349
+ settleRecord ? settleRecord({
1350
+ ...args
1351
+ }) : context.serialize(recordKey, {
1352
+ ...args
994
1353
  });
995
- } else {
996
- resolved[key] = value;
997
- }
998
- }
999
- const out = suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved))));
1000
- const unused = regions.filter(r => !r.used);
1001
- if (sharedConfig.context) {
1002
- const args = {};
1003
- for (const key of Object.keys(vals)) {
1004
- const value = vals[key];
1005
- const region = regions.find(r => r.key === key);
1006
- if (region) {
1007
- args[key] = {
1008
- $frame: region.childId
1009
- };
1010
- continue;
1354
+ for (const region of unused) {
1355
+ region.locked = true;
1356
+ context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(context, region.value));
1011
1357
  }
1012
- if (!isContainerTraced(value) && isServerContent(value)) continue;
1013
- args[key] = toBorderForm(value);
1014
- }
1015
- sharedConfig.context.serialize(`sc:slot:${frameId}:${occurrence}`, {
1016
- ...args
1017
- });
1018
- for (const region of unused) {
1019
- region.locked = true;
1020
- sharedConfig.context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(sharedConfig.context, region.value));
1021
- }
1022
- if (liveArgs) {
1023
- for (const key of Object.keys(evals)) {
1024
- if (regions.some(r => r.key === key)) continue;
1025
- if (minted[key]) continue;
1026
- const ledgerKey = `${frameId}:${occurrence}:${key}`;
1027
- openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
1028
- args[key] = toBorderForm(value);
1029
- liveArgs.slot(frameId, occurrence, {
1030
- ...args
1358
+ if (liveArgs) {
1359
+ for (const key of Object.keys(evals)) {
1360
+ if (regions.some(r => r.key === key)) continue;
1361
+ if (minted[key]) continue;
1362
+ const ledgerKey = `${frameId}:${occurrence}:${key}`;
1363
+ openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
1364
+ args[key] = argBorderForm(value, key, occurrence, documentNeeds);
1365
+ liveArgs.slot(frameId, occurrence, {
1366
+ ...args
1367
+ });
1031
1368
  });
1032
- });
1369
+ }
1033
1370
  }
1034
1371
  }
1372
+ if (rk !== undefined && (rk === occurrence || out.$face === SLOT_FACE_DATA)) repeats.has(rk) || repeats.set(rk, out);
1373
+ return out;
1374
+ } catch (error) {
1375
+ settleRecord && settleRecord(undefined);
1376
+ throw error;
1035
1377
  }
1036
- return out;
1037
1378
  };
1038
1379
  fn.$lhSkip = true;
1039
- fn[CLAIM_PROP] = prop;
1040
1380
  getters.set(prop, fn);
1041
1381
  }
1042
1382
  return fn;
@@ -1050,6 +1390,17 @@ function frameElementOpen(id) {
1050
1390
  return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}" style="display:contents">`;
1051
1391
  }
1052
1392
  const FRAME_ELEMENT_CLOSE = `</${FRAME_TAG}>`;
1393
+ function documentNeeds(name) {
1394
+ const ctx = sharedConfig.context;
1395
+ const live = ctx && ctx.live;
1396
+ if (!live || !ctx.serialize) return;
1397
+ const tiers = live.tiers || (live.tiers = []);
1398
+ if (tiers.includes(name)) return;
1399
+ tiers.push(name);
1400
+ ctx.serialize("sc:tiers", tiers.slice());
1401
+ const url = live.tierUrls && live.tierUrls[name];
1402
+ if (url && ctx.registerAsset) ctx.registerAsset("module", url);
1403
+ }
1053
1404
  function armDocumentLiveHoles(ctx) {
1054
1405
  if (!ctx || ctx.liveHoles !== undefined) return;
1055
1406
  const live = ctx.live;
@@ -1061,7 +1412,7 @@ function armDocumentLiveHoles(ctx) {
1061
1412
  }
1062
1413
  return;
1063
1414
  }
1064
- if (!live || !ctx.async || ctx.noHydrate || !ctx.serialize || typeof ReadableStream !== "function") {
1415
+ if (!live || !ctx.async || !ctx.serialize || typeof ReadableStream !== "function") {
1065
1416
  ctx.liveHoles = null;
1066
1417
  if (live) live.holes = null;
1067
1418
  return;
@@ -1070,14 +1421,27 @@ function armDocumentLiveHoles(ctx) {
1070
1421
  let epoch = 0;
1071
1422
  let sweepScheduled = false;
1072
1423
  let closed = false;
1424
+ let swept = null;
1073
1425
  const sweep = () => {
1074
1426
  epoch++;
1075
- for (const b of [...bindings.values()]) {
1076
- try {
1077
- b.sweep();
1078
- } catch (_) {
1427
+ const ops = swept = [];
1428
+ try {
1429
+ for (const b of [...bindings.values()]) {
1430
+ try {
1431
+ b.sweep();
1432
+ } catch (_) {
1433
+ }
1079
1434
  }
1435
+ } finally {
1436
+ swept = null;
1080
1437
  }
1438
+ pushOps(ops);
1439
+ };
1440
+ const pushOps = ops => {
1441
+ if (ops.length === 1) push(ops[0]);else if (ops.length) push({
1442
+ type: "ops",
1443
+ ops
1444
+ });
1081
1445
  };
1082
1446
  const scheduleSweep = () => {
1083
1447
  if (closed || sweepScheduled || !bindings.size) return;
@@ -1104,12 +1468,13 @@ function armDocumentLiveHoles(ctx) {
1104
1468
  bindings.delete(key);
1105
1469
  },
1106
1470
  hole(key, html) {
1107
- push({
1471
+ const op = {
1108
1472
  type: "hole",
1109
1473
  key,
1110
1474
  html,
1111
1475
  digest: textDigest(html)
1112
- });
1476
+ };
1477
+ swept ? swept.push(op) : pushOps([op]);
1113
1478
  },
1114
1479
  attr(key, attrs, removed) {
1115
1480
  const op = {
@@ -1119,7 +1484,7 @@ function armDocumentLiveHoles(ctx) {
1119
1484
  digest: textDigest(attrs)
1120
1485
  };
1121
1486
  if (removed && removed.length) op.removed = removed;
1122
- push(op);
1487
+ swept ? swept.push(op) : pushOps([op]);
1123
1488
  },
1124
1489
  error(key, error) {
1125
1490
  push({
@@ -1152,6 +1517,13 @@ function armDocumentLiveHoles(ctx) {
1152
1517
  },
1153
1518
  commit: scheduleSweep
1154
1519
  };
1520
+ live.error = (fid, error) => {
1521
+ push({
1522
+ type: "error",
1523
+ fid,
1524
+ error
1525
+ });
1526
+ };
1155
1527
  live.end = () => {
1156
1528
  if (closed) return;
1157
1529
  if (bindings.size) sweep();
@@ -1161,7 +1533,8 @@ function armDocumentLiveHoles(ctx) {
1161
1533
  }
1162
1534
  function frameTransformDirectResult(value, {
1163
1535
  id,
1164
- args
1536
+ args,
1537
+ tierUrls
1165
1538
  }) {
1166
1539
  if (typeof value !== "function") return value;
1167
1540
  const component = value;
@@ -1169,10 +1542,21 @@ function frameTransformDirectResult(value, {
1169
1542
  t: frameElementOpen(id)
1170
1543
  },
1171
1544
  serverOwned(() => {
1172
- armDocumentLiveHoles(sharedConfig.context);
1173
- sharedConfig.context.claims = CLAIMS_DOCUMENT;
1174
- const slotProps = createDocumentSlotProps(props, id);
1175
- return serverComponentScope(() => component(slotProps), !!wrapped[LIVE_SOURCE]);
1545
+ const page = sharedConfig.context;
1546
+ armDocumentLiveHoles(page);
1547
+ if (tierUrls && page && page.live && !page.live.tierUrls) page.live.tierUrls = tierUrls;
1548
+ const ctx = Object.create(page);
1549
+ ctx.claims = CLAIMS_DOCUMENT;
1550
+ ctx.frameId = id;
1551
+ sharedConfig.context = ctx;
1552
+ try {
1553
+ const slotProps = createDocumentSlotProps(props, id);
1554
+ const live = !!wrapped[LIVE_SOURCE];
1555
+ if (live) documentNeeds("wire");
1556
+ return serverComponentScope(() => component(slotProps), live);
1557
+ } finally {
1558
+ sharedConfig.context = page;
1559
+ }
1176
1560
  }), {
1177
1561
  t: FRAME_ELEMENT_CLOSE
1178
1562
  }];
@@ -1280,6 +1664,8 @@ function openArgBinding(sink, ledgerKey, occurrence, key, evaluate, state, emit)
1280
1664
  function createSlotProps(sink, frame) {
1281
1665
  const counts = Object.create(null);
1282
1666
  const getters = new Map();
1667
+ const repeats = new Map();
1668
+ const needs = sink.needs || (() => {});
1283
1669
  return new Proxy(Object.create(null), {
1284
1670
  has() {
1285
1671
  return true;
@@ -1291,8 +1677,11 @@ function createSlotProps(sink, frame) {
1291
1677
  if (!fn) {
1292
1678
  fn = (...callArgs) => {
1293
1679
  if (callArgs.length === 0 || callArgs[0] === undefined) {
1294
- return slotRange(prop);
1680
+ return slotProxy(slotRange(prop), prop, SLOT_FACE_STREAM, undefined, undefined, needs);
1295
1681
  }
1682
+ const rk = repeatKey(prop, callArgs[0]);
1683
+ const repeat = rk !== undefined && repeats.get(rk);
1684
+ if (repeat) return repeat;
1296
1685
  const live = sharedConfig.context && sharedConfig.context.liveHoles;
1297
1686
  if (live) {
1298
1687
  if (live.sweeping) {
@@ -1369,7 +1758,7 @@ function createSlotProps(sink, frame) {
1369
1758
  };
1370
1759
  } else {
1371
1760
  const ref = `arg:${occurrence}:${key}`;
1372
- ctx.serialize(ref, toBorderForm(value, true));
1761
+ ctx.serialize(ref, argBorderForm(value, key, occurrence, needs));
1373
1762
  args[key] = {
1374
1763
  $ref: ref
1375
1764
  };
@@ -1401,7 +1790,7 @@ function createSlotProps(sink, frame) {
1401
1790
  } else {
1402
1791
  const ref = `arg:${occurrence}:${key}@${sink.nextArgRef(ledgerKey)}`;
1403
1792
  sink.mintRef(ref);
1404
- ctx.serialize(ref, toBorderForm(value));
1793
+ ctx.serialize(ref, argBorderForm(value, key, occurrence, needs));
1405
1794
  args[key] = {
1406
1795
  $ref: ref
1407
1796
  };
@@ -1411,10 +1800,12 @@ function createSlotProps(sink, frame) {
1411
1800
  });
1412
1801
  });
1413
1802
  }
1414
- return slotRange(occurrence);
1803
+ const keyed = rk === occurrence;
1804
+ const out = slotProxy(slotRange(occurrence), occurrence, SLOT_FACE_STREAM, undefined, rk === undefined || keyed ? undefined : () => repeats.has(rk) || repeats.set(rk, out), needs);
1805
+ if (keyed) repeats.set(rk, out);
1806
+ return out;
1415
1807
  };
1416
1808
  fn.$lhSkip = true;
1417
- fn[CLAIM_PROP] = prop;
1418
1809
  getters.set(prop, fn);
1419
1810
  }
1420
1811
  return fn;
@@ -1469,9 +1860,6 @@ function serverComponentResponse(component, options = {}, init = {}) {
1469
1860
  } catch (_) {}
1470
1861
  };
1471
1862
  if (teardown.signal.aborted) return end();
1472
- teardown.signal.addEventListener("abort", end, {
1473
- once: true
1474
- });
1475
1863
  if (live) stopLive = armLiveBody(controller, () => {
1476
1864
  closed = true;
1477
1865
  disarm();
@@ -1486,14 +1874,19 @@ function serverComponentResponse(component, options = {}, init = {}) {
1486
1874
  closed = true;
1487
1875
  }
1488
1876
  },
1489
- end
1877
+ end,
1878
+ [ANNOUNCE](tiers) {
1879
+ if (tiers.length) headers.set(FRAME_TIERS_HEADER, tiers.join(","));
1880
+ }
1490
1881
  });
1491
1882
  },
1492
1883
  cancel() {
1493
1884
  closed = true;
1494
1885
  disarm();
1495
1886
  if (stopLive) stopLive();
1496
- teardown.abort();
1887
+ teardown.abort({
1888
+ [DISCONNECTED]: true
1889
+ });
1497
1890
  }
1498
1891
  });
1499
1892
  return new Response(body, {
@@ -1695,7 +2088,9 @@ function frameFlightResponse({
1695
2088
  cancel() {
1696
2089
  closed = true;
1697
2090
  disarm();
1698
- teardown.abort();
2091
+ teardown.abort({
2092
+ [DISCONNECTED]: true
2093
+ });
1699
2094
  }
1700
2095
  });
1701
2096
  return new Response(body, {
@@ -1710,4 +2105,4 @@ function asyncArg(value) {
1710
2105
  return value;
1711
2106
  }
1712
2107
 
1713
- export { FRAME_HAVE_BUDGET, FRAME_HAVE_HEADER, FRAME_STREAM_HEADER, SERVER_COMPONENT_BOOTSTRAP, ServerComponentPlugin, asyncArg, createFrameSink, frameTransformDirectResult, frameTransformFlightResult, frameTransformResult, isFrameStreamResponse, renderServerComponent, renderToFrameStream, serverComponentResponse };
2108
+ export { FRAME_HAVE_BUDGET, FRAME_HAVE_HEADER, FRAME_STREAM_HEADER, FRAME_TIERS_HEADER, SERVER_COMPONENT_BOOTSTRAP, ServerComponentPlugin, asyncArg, createFrameSink, frameTransformDirectResult, frameTransformFlightResult, frameTransformResult, isFrameStreamResponse, renderServerComponent, renderToFrameStream, serverComponentResponse };