@solidjs/web 2.0.0-rc.13 → 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 (57) hide show
  1. package/dist/server.dev.js +200 -73
  2. package/dist/server.js +182 -59
  3. package/dist/server.observe.js +183 -60
  4. package/dist/web.dev.js +70 -35
  5. package/dist/web.js +43 -31
  6. package/dist/web.observe.js +43 -33
  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 +605 -1086
  11. package/frames/dist/client.js +572 -1066
  12. package/frames/dist/client.observe.js +571 -1066
  13. package/frames/dist/regions.js +130 -0
  14. package/frames/dist/server.dev.js +339 -177
  15. package/frames/dist/server.js +335 -173
  16. package/frames/dist/server.observe.js +335 -173
  17. package/frames/dist/trace.js +42 -0
  18. package/frames/dist/wire.js +133 -0
  19. package/package.json +28 -2
  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 +99 -61
  27. package/server-functions/dist/client.js +99 -61
  28. package/server-functions/dist/client.observe.js +99 -61
  29. package/server-functions/dist/server.dev.js +87 -50
  30. package/server-functions/dist/server.js +87 -50
  31. package/server-functions/dist/server.observe.js +87 -50
  32. package/skills/server-components/SKILL.md +65 -43
  33. package/types/client.d.ts +20 -0
  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 -78
  40. package/types/frames/frame-container-plugin.d.ts +2 -2
  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 +32 -8
  46. package/types/frames/trace-tier.d.ts +2 -0
  47. package/types/frames/wire-tier.d.ts +116 -0
  48. package/types/index.d.ts +38 -0
  49. package/types/index.server.d.ts +9 -0
  50. package/types/jsx.d.ts +1 -1
  51. package/types/observe.d.ts +4 -2
  52. package/types/serializer-decode.d.ts +24 -2
  53. package/types/server-functions/client.d.ts +26 -0
  54. package/types/server-functions/registry.d.ts +4 -1
  55. package/types/server-functions/shared.d.ts +12 -8
  56. package/types/server-mock.d.ts +13 -1
  57. package/types/server.d.ts +34 -8
@@ -1,6 +1,6 @@
1
1
  import { sharedConfig, ssrSanitizeError, creationStamp, ssrHandleError, runInServerComponentScope, shareAsyncIterable, getProjectionTrace } from 'solid-js/internal';
2
2
  import { NoHydration, getOwner, runWithOwner, createMemo, Hydration, createOwner } from 'solid-js';
3
- import { isResponseEnvelope, renderToStream, createLiveHoles, CLAIMS_STREAM, CLAIMS_DOCUMENT, SLOT_FACE_DATA, slotValue, SLOT_FACE_STREAM, SLOT_FACE_MARKUP, isSlotValue } from '@solidjs/web';
3
+ import { isResponseEnvelope, renderToStream, createLiveHoles, CLAIMS_STREAM, CLAIMS_DOCUMENT, SLOT_FACE_DATA, SLOT_FACE_MARKUP, slotValue, SLOT_FACE_STREAM, isSlotValue } 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';
@@ -139,10 +139,10 @@ function isShareableIterable(value) {
139
139
  return false;
140
140
  }
141
141
  }
142
- function materialize(marker) {
142
+ function materialize(marker, claiming) {
143
143
  let value = state.materialized.get(marker.$tr);
144
144
  if (value === undefined) {
145
- value = state.materializeTrace(marker);
145
+ value = state.materializeTrace(marker, claiming);
146
146
  state.materialized.set(marker.$tr, value);
147
147
  if (value !== null && typeof value === "object") state.materializedValues.add(value);
148
148
  }
@@ -200,14 +200,14 @@ setContainerTraceStreamMint(iterable => {
200
200
  })();
201
201
  return stream;
202
202
  });
203
- const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
203
+ const DEFAULT_WEB_PLUGINS = /* @__PURE__ */Object.freeze([AbortSignalPlugin,
204
204
  CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
205
205
  FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin,
206
206
  ContainerTracePlugin]);
207
207
  function resolveSerializerPlugins(customPlugins) {
208
208
  return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
209
209
  }
210
- const JSON_CODEC_DISABLED_FEATURES = Feature.RegExp;
210
+ const jsonCodecDisabledFeatures = () => Feature.RegExp;
211
211
  const JSON_CODEC_DEPTH_LIMIT = 64;
212
212
  function resolveCodecOptions({
213
213
  plugins,
@@ -217,13 +217,12 @@ function resolveCodecOptions({
217
217
  } = {}) {
218
218
  return {
219
219
  plugins: resolveSerializerPlugins(plugins),
220
- disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
220
+ disabledFeatures: disabledFeatures === undefined ? jsonCodecDisabledFeatures() : disabledFeatures,
221
221
  depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit,
222
222
  serializeErrorStacks
223
223
  };
224
224
  }
225
225
 
226
- Feature.AggregateError | Feature.BigIntTypedArray;
227
226
  const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : Feature.ErrorPrototypeStack;
228
227
  function createJSONSerializer({
229
228
  onData,
@@ -349,6 +348,7 @@ function observeFrame(frame) {
349
348
  }
350
349
 
351
350
  const FRAME_STREAM_HEADER = "X-Frame-Stream";
351
+ const FRAME_TIERS_HEADER = "X-Frame-Tiers";
352
352
  const FRAME_HAVE_HEADER = "X-Frame-Have";
353
353
  const FRAME_HAVE_BUDGET = 4096;
354
354
  function decodeHaveList(text) {
@@ -479,11 +479,27 @@ function withHoles(chunk, holes) {
479
479
  }
480
480
  return chunk;
481
481
  }
482
- function createFrameSink(emit, frame, have) {
482
+ function createFrameSink(write, frame, have, hooks) {
483
483
  const {
484
484
  id,
485
485
  version
486
486
  } = frame;
487
+ const tiers = new Set();
488
+ let staged = [];
489
+ const emit = chunk => {
490
+ if (swept) swept.emitted = true;
491
+ if (staged.length) {
492
+ chunk.tiers = staged;
493
+ staged = [];
494
+ }
495
+ write(chunk);
496
+ };
497
+ const needs = name => {
498
+ if (!tiers.has(name)) {
499
+ tiers.add(name);
500
+ staged.push(name);
501
+ }
502
+ };
487
503
  let conditional = false;
488
504
  const skipped = new Set();
489
505
  const attrText = new Map();
@@ -523,15 +539,38 @@ function createFrameSink(emit, frame, have) {
523
539
  let sweepScheduled = false;
524
540
  let closed = false;
525
541
  let epoch = 0;
542
+ let swept = null;
526
543
  const sweep = () => {
527
544
  epoch++;
528
- for (const b of [...bindings.values()]) {
529
- try {
530
- b.sweep();
531
- } catch (_) {
545
+ const pass = swept = {
546
+ ops: [],
547
+ emitted: false
548
+ };
549
+ try {
550
+ for (const b of [...bindings.values()]) {
551
+ try {
552
+ b.sweep();
553
+ } catch (_) {
554
+ }
532
555
  }
556
+ emitOps(pass.ops);
557
+ if (pass.emitted && hooks && hooks.onYield) hooks.onYield();
558
+ } finally {
559
+ swept = null;
533
560
  }
534
561
  };
562
+ const emitOps = ops => {
563
+ if (ops.length === 1) emit(Object.assign({
564
+ type: ops[0].type,
565
+ id,
566
+ version
567
+ }, ops[0]));else if (ops.length) emit({
568
+ type: "ops",
569
+ id,
570
+ version,
571
+ ops
572
+ });
573
+ };
535
574
  const scheduleSweep = () => {
536
575
  if (closed || sweepScheduled || !bindings.size) return;
537
576
  sweepScheduled = true;
@@ -575,6 +614,7 @@ function createFrameSink(emit, frame, have) {
575
614
  chunk.preloads.push(wirePreload(entry));
576
615
  }
577
616
  }
617
+ needs("assets");
578
618
  emit(chunk);
579
619
  }
580
620
  emit(withHoles({
@@ -650,6 +690,7 @@ function createFrameSink(emit, frame, have) {
650
690
  attrs: e.attrs
651
691
  }));
652
692
  }
693
+ needs("assets");
653
694
  emit(chunk);
654
695
  }
655
696
  emit(withHoles({
@@ -707,6 +748,7 @@ function createFrameSink(emit, frame, have) {
707
748
  },
708
749
  asset(type, value) {
709
750
  if (type === "module") {
751
+ needs("assets");
710
752
  emit({
711
753
  type: "assets",
712
754
  id,
@@ -715,6 +757,7 @@ function createFrameSink(emit, frame, have) {
715
757
  modules: [value]
716
758
  });
717
759
  } else if (type === "preload") {
760
+ needs("assets");
718
761
  emit({
719
762
  type: "assets",
720
763
  id,
@@ -724,14 +767,17 @@ function createFrameSink(emit, frame, have) {
724
767
  });
725
768
  }
726
769
  },
727
- end() {
728
- if (bindings.size) sweep();
770
+ end(bound) {
771
+ if (closed) return;
772
+ if (bindings.size && !swept) sweep();
729
773
  closed = true;
730
- emit({
774
+ const chunk = {
731
775
  type: "complete",
732
776
  id,
733
777
  version
734
- });
778
+ };
779
+ if (bound) chunk.bound = bound;
780
+ emit(chunk);
735
781
  },
736
782
  error(errorId, error) {
737
783
  emit({
@@ -752,6 +798,7 @@ function createFrameSink(emit, frame, have) {
752
798
  });
753
799
  },
754
800
  region(childId, html) {
801
+ needs("regions");
755
802
  emit({
756
803
  type: "html",
757
804
  id: childId,
@@ -760,26 +807,23 @@ function createFrameSink(emit, frame, have) {
760
807
  });
761
808
  },
762
809
  hole(key, html) {
763
- emit({
810
+ const op = {
764
811
  type: "hole",
765
- id,
766
- version,
767
812
  key,
768
813
  html,
769
814
  digest: textDigest(html)
770
- });
815
+ };
816
+ swept ? swept.ops.push(op) : emitOps([op]);
771
817
  },
772
818
  attr(key, attrs, removed) {
773
- const chunk = {
819
+ const op = {
774
820
  type: "attr",
775
- id,
776
- version,
777
821
  key,
778
822
  attrs,
779
823
  digest: textDigest(attrs)
780
824
  };
781
- if (removed && removed.length) chunk.removed = removed;
782
- emit(chunk);
825
+ if (removed && removed.length) op.removed = removed;
826
+ swept ? swept.ops.push(op) : emitOps([op]);
783
827
  },
784
828
  attrBaseline(key, text) {
785
829
  attrText.set(key, text);
@@ -801,6 +845,11 @@ function createFrameSink(emit, frame, have) {
801
845
  commit: scheduleSweep,
802
846
  get epoch() {
803
847
  return epoch;
848
+ },
849
+ needs,
850
+ announce() {
851
+ staged = [];
852
+ return [...tiers];
804
853
  }
805
854
  };
806
855
  }
@@ -822,6 +871,10 @@ function renderServerComponent(component, options = {}) {
822
871
  };
823
872
  }, options);
824
873
  }
874
+ const DEFAULT_MAX_YIELDS = 64;
875
+ const DEFAULT_MAX_DURATION_MS = 30_000;
876
+ const DISCONNECTED = Symbol("solid.frames.disconnected");
877
+ const ANNOUNCE = Symbol("solid.frames.announce");
825
878
  function frameStream(makeCode, options) {
826
879
  const {
827
880
  id = "",
@@ -831,30 +884,77 @@ function frameStream(makeCode, options) {
831
884
  id,
832
885
  version
833
886
  };
887
+ const bounded = !options.live;
888
+ const maxYields = bounded ? options.maxYields ?? DEFAULT_MAX_YIELDS : 0;
889
+ const maxDurationMs = bounded ? options.maxDurationMs ?? DEFAULT_MAX_DURATION_MS : 0;
834
890
  function stream(w) {
835
891
  const observation = observeFrame(frame);
836
- const emit = observation ? chunk => {
837
- observation.chunk(chunk);
892
+ const render = new AbortController();
893
+ const upstream = options.signal;
894
+ let ended = false;
895
+ let flushed = false;
896
+ let yields = 0;
897
+ let timer;
898
+ function finish() {
899
+ if (ended) return;
900
+ ended = true;
901
+ if (timer) clearTimeout(timer);
902
+ if (upstream) upstream.removeEventListener("abort", onSignal);
903
+ w.end && w.end();
904
+ }
905
+ function cut(bound) {
906
+ if (ended) return;
907
+ sink.end(bound);
908
+ observation && observation.settle("complete");
909
+ finish();
910
+ render.abort({
911
+ quiet: true,
912
+ bound
913
+ });
914
+ }
915
+ function onSignal() {
916
+ const gone = upstream.reason && upstream.reason[DISCONNECTED];
917
+ if (bounded && flushed && !gone) return cut("time");
918
+ finish();
919
+ render.abort(upstream.reason);
920
+ }
921
+ const emit = chunk => {
922
+ if (observation) observation.chunk(chunk);
838
923
  w.write(chunk);
839
- } : chunk => w.write(chunk);
840
- const sink = createFrameSink(emit, frame, options.resume && options.resume.have);
924
+ if (bounded && !flushed && chunk.type === "html" && chunk.id === id) {
925
+ flushed = true;
926
+ if (maxDurationMs > 0 && maxDurationMs !== Infinity) timer = setTimeout(() => cut("time"), maxDurationMs);
927
+ }
928
+ };
929
+ const sink = createFrameSink(emit, frame, options.resume && options.resume.have, bounded ? {
930
+ onYield() {
931
+ if (flushed && maxYields > 0 && ++yields >= maxYields) cut("yields");
932
+ }
933
+ } : undefined);
934
+ if (options.live) sink.needs("wire");
841
935
  w.write({
842
936
  type: "start",
843
937
  id,
844
938
  version
845
939
  });
940
+ if (upstream && upstream.aborted) return finish();
941
+ if (upstream) upstream.addEventListener("abort", onSignal, {
942
+ once: true
943
+ });
846
944
  const code = makeCode(sink, frame);
847
945
  try {
848
946
  renderToStream(() => serverOwned(code), {
849
947
  serializer: createJSONSerializer,
850
948
  ...options,
949
+ signal: render.signal,
851
950
  sink
852
951
  }).pipe({
853
952
  write() {},
854
953
  end() {
954
+ if (ended) return;
855
955
  sink.end();
856
956
  observation && observation.settle("complete");
857
- w.end && w.end();
957
+ finish();
858
958
  }
859
959
  });
860
960
  } catch (err) {
@@ -862,8 +962,9 @@ function frameStream(makeCode, options) {
862
962
  sink.error("", wire instanceof Error ? wire.message : String(wire));
863
963
  sink.end();
864
964
  observation && observation.settle("error", err);
865
- w.end && w.end();
965
+ finish();
866
966
  }
967
+ if (w[ANNOUNCE]) w[ANNOUNCE](sink.announce());
867
968
  }
868
969
  return {
869
970
  pipe: stream,
@@ -895,21 +996,25 @@ function isRangeKey(key) {
895
996
  const c = key.charCodeAt(0);
896
997
  return c === 36 || c >= 48 && c <= 57 || RANGE_KEYS.has(key);
897
998
  }
898
- function slotProxy(range, occurrence, face, content, onData) {
999
+ function slotProxy(range, occurrence, face, content, onData, needs) {
899
1000
  return new Proxy(range, {
900
1001
  get(target, key, receiver) {
901
1002
  if (typeof key !== "string" || isRangeKey(key)) return Reflect.get(target, key, receiver);
902
1003
  if (onData) onData = void onData();
1004
+ if (face !== SLOT_FACE_MARKUP) needs("bind");
903
1005
  return slotValue(occurrence, key, content ? content[key] : undefined, face);
904
1006
  }
905
1007
  });
906
1008
  }
907
- function argBorderForm(value, key, occurrence) {
908
- return toBorderForm(withoutStandIns(value));
1009
+ function argBorderForm(value, key, occurrence, needs) {
1010
+ return toBorderForm(withoutStandIns(value, key, occurrence, needs));
909
1011
  }
910
- function withoutStandIns(value, key, occurrence) {
1012
+ function withoutStandIns(value, key, occurrence, needs) {
911
1013
  return rewriteTree(value, (v, path) => {
912
- if (isContainerTraced(v)) return v;
1014
+ if (isContainerTraced(v)) {
1015
+ needs("trace");
1016
+ return v;
1017
+ }
913
1018
  if (Object.getPrototypeOf(v) === Object.prototype && isSlotValue(v)) {
914
1019
  return undefined;
915
1020
  }
@@ -1030,7 +1135,7 @@ function createDocumentSlotProps(clientProps, frameId) {
1030
1135
  r.$occurrence = occurrence;
1031
1136
  const face = slotFace(r, content);
1032
1137
  r.$face = face;
1033
- return slotProxy(r, occurrence, face, face === SLOT_FACE_DATA ? content : undefined);
1138
+ return slotProxy(r, occurrence, face, face === SLOT_FACE_DATA ? content : undefined, undefined, documentNeeds);
1034
1139
  };
1035
1140
  const zoneOwner = getOwner ? getOwner() : null;
1036
1141
  const scoped = (occurrence, render) => {
@@ -1071,136 +1176,151 @@ function createDocumentSlotProps(clientProps, frameId) {
1071
1176
  const occurrence = occurrenceId(prop, raw, counts);
1072
1177
  const slot = clientProps[prop];
1073
1178
  if (typeof slot !== "function") return range(occurrence, undefined);
1074
- const resolved = {};
1075
- const liveArgs = sharedConfig.context && sharedConfig.context.live && sharedConfig.context.live.args;
1076
- const vals = {};
1077
- const evals = {};
1078
- const states = {};
1079
- const minted = {};
1080
- for (const key of Object.keys(raw)) {
1081
- if (key === "$key") continue;
1082
- const desc = Object.getOwnPropertyDescriptor(raw, key);
1083
- let evaluate = null;
1084
- let value;
1085
- if (desc.get) {
1086
- const get = desc.get;
1087
- evaluate = () => unwrapThunks(get.call(raw));
1088
- } else {
1089
- value = desc.value;
1090
- if (typeof value === "function") {
1091
- const fn = value;
1092
- evaluate = () => unwrapThunks(fn);
1179
+ const context = sharedConfig.context;
1180
+ const recordKey = `sc:slot:${frameId}:${occurrence}`;
1181
+ let settleRecord;
1182
+ if (context && context.async) {
1183
+ context.serialize(recordKey, new Promise(resolve => settleRecord = resolve));
1184
+ }
1185
+ try {
1186
+ const resolved = {};
1187
+ const liveArgs = sharedConfig.context && sharedConfig.context.live && sharedConfig.context.live.args;
1188
+ const vals = {};
1189
+ const evals = {};
1190
+ const states = {};
1191
+ const minted = {};
1192
+ for (const key of Object.keys(raw)) {
1193
+ if (key === "$key") continue;
1194
+ const desc = Object.getOwnPropertyDescriptor(raw, key);
1195
+ let evaluate = null;
1196
+ let value;
1197
+ if (desc.get) {
1198
+ const get = desc.get;
1199
+ evaluate = () => unwrapThunks(get.call(raw));
1200
+ } else {
1201
+ value = desc.value;
1202
+ if (typeof value === "function") {
1203
+ const fn = value;
1204
+ evaluate = () => unwrapThunks(fn);
1205
+ }
1093
1206
  }
1207
+ if (evaluate) {
1208
+ evals[key] = evaluate;
1209
+ const stampBefore = scopeStamp();
1210
+ try {
1211
+ value = evaluate();
1212
+ states[key] = {
1213
+ settled: true,
1214
+ last: value
1215
+ };
1216
+ } catch (err) {
1217
+ const blocked = ssrHandleError && ssrHandleError(err);
1218
+ if (!blocked) throw err;
1219
+ const state = states[key] = {
1220
+ settled: false,
1221
+ last: undefined
1222
+ };
1223
+ value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
1224
+ state.settled = true;
1225
+ state.last = v;
1226
+ if (liveArgs) liveArgs.commit();
1227
+ });
1228
+ }
1229
+ if (scopeStamp() !== stampBefore) minted[key] = true;
1230
+ }
1231
+ vals[key] = value;
1094
1232
  }
1095
- if (evaluate) {
1096
- evals[key] = evaluate;
1097
- const stampBefore = scopeStamp();
1098
- try {
1099
- value = evaluate();
1100
- states[key] = {
1101
- settled: true,
1102
- last: value
1233
+ const regions = [];
1234
+ for (const key of Object.keys(vals)) {
1235
+ const value = vals[key];
1236
+ if (isContainerTraced(value)) {
1237
+ documentNeeds("trace");
1238
+ resolved[key] = value;
1239
+ } else if (isServerContent(value)) {
1240
+ const childId = `${frameId}.${occurrence}.${key}`;
1241
+ const region = {
1242
+ key,
1243
+ childId,
1244
+ value,
1245
+ used: false,
1246
+ locked: false
1103
1247
  };
1104
- } catch (err) {
1105
- const blocked = ssrHandleError && ssrHandleError(err);
1106
- if (!blocked) throw err;
1107
- const state = states[key] = {
1108
- settled: false,
1109
- last: undefined
1248
+ regions.push(region);
1249
+ documentNeeds("regions");
1250
+ resolved[key] = () => {
1251
+ if (region.locked) return [];
1252
+ region.used = true;
1253
+ return [{
1254
+ t: frameElementOpen(childId)
1255
+ }, value, {
1256
+ t: FRAME_ELEMENT_CLOSE
1257
+ }];
1110
1258
  };
1111
- value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
1112
- state.settled = true;
1113
- state.last = v;
1114
- if (liveArgs) liveArgs.commit();
1259
+ } else if (ssrAsyncValue && isAsyncValue(value)) {
1260
+ let readable = value;
1261
+ if (typeof value.then !== "function") {
1262
+ const {
1263
+ first,
1264
+ rest
1265
+ } = tapFirstYield(value);
1266
+ readable = first;
1267
+ vals[key] = rest;
1268
+ }
1269
+ const read = ssrAsyncValue(readable);
1270
+ Object.defineProperty(resolved, key, {
1271
+ get: read,
1272
+ enumerable: true,
1273
+ configurable: true
1115
1274
  });
1275
+ } else {
1276
+ resolved[key] = vals[key] = withoutStandIns(value, key, occurrence, documentNeeds);
1116
1277
  }
1117
- if (scopeStamp() !== stampBefore) minted[key] = true;
1118
1278
  }
1119
- vals[key] = value;
1120
- }
1121
- const regions = [];
1122
- for (const key of Object.keys(vals)) {
1123
- const value = vals[key];
1124
- if (isContainerTraced(value)) {
1125
- resolved[key] = value;
1126
- } else if (isServerContent(value)) {
1127
- const childId = `${frameId}.${occurrence}.${key}`;
1128
- const region = {
1129
- key,
1130
- childId,
1131
- value,
1132
- used: false,
1133
- locked: false
1134
- };
1135
- regions.push(region);
1136
- resolved[key] = () => {
1137
- if (region.locked) return [];
1138
- region.used = true;
1139
- return [{
1140
- t: frameElementOpen(childId)
1141
- }, value, {
1142
- t: FRAME_ELEMENT_CLOSE
1143
- }];
1144
- };
1145
- } else if (ssrAsyncValue && isAsyncValue(value)) {
1146
- let readable = value;
1147
- if (typeof value.then !== "function") {
1148
- const {
1149
- first,
1150
- rest
1151
- } = tapFirstYield(value);
1152
- readable = first;
1153
- vals[key] = rest;
1279
+ const out = suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved))));
1280
+ const unused = regions.filter(r => !r.used);
1281
+ if (context) {
1282
+ const args = {};
1283
+ for (const key of Object.keys(vals)) {
1284
+ const value = vals[key];
1285
+ const region = regions.find(r => r.key === key);
1286
+ if (region) {
1287
+ args[key] = {
1288
+ $frame: region.childId
1289
+ };
1290
+ continue;
1291
+ }
1292
+ if (!isContainerTraced(value) && isServerContent(value)) continue;
1293
+ args[key] = argBorderForm(value, key, occurrence, documentNeeds);
1154
1294
  }
1155
- const read = ssrAsyncValue(readable);
1156
- Object.defineProperty(resolved, key, {
1157
- get: read,
1158
- enumerable: true,
1159
- configurable: true
1295
+ settleRecord ? settleRecord({
1296
+ ...args
1297
+ }) : context.serialize(recordKey, {
1298
+ ...args
1160
1299
  });
1161
- } else {
1162
- resolved[key] = vals[key] = withoutStandIns(value);
1163
- }
1164
- }
1165
- const out = suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved))));
1166
- const unused = regions.filter(r => !r.used);
1167
- if (sharedConfig.context) {
1168
- const args = {};
1169
- for (const key of Object.keys(vals)) {
1170
- const value = vals[key];
1171
- const region = regions.find(r => r.key === key);
1172
- if (region) {
1173
- args[key] = {
1174
- $frame: region.childId
1175
- };
1176
- continue;
1300
+ for (const region of unused) {
1301
+ region.locked = true;
1302
+ context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(context, region.value));
1177
1303
  }
1178
- if (!isContainerTraced(value) && isServerContent(value)) continue;
1179
- args[key] = argBorderForm(value);
1180
- }
1181
- sharedConfig.context.serialize(`sc:slot:${frameId}:${occurrence}`, {
1182
- ...args
1183
- });
1184
- for (const region of unused) {
1185
- region.locked = true;
1186
- sharedConfig.context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(sharedConfig.context, region.value));
1187
- }
1188
- if (liveArgs) {
1189
- for (const key of Object.keys(evals)) {
1190
- if (regions.some(r => r.key === key)) continue;
1191
- if (minted[key]) continue;
1192
- const ledgerKey = `${frameId}:${occurrence}:${key}`;
1193
- openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
1194
- args[key] = argBorderForm(value);
1195
- liveArgs.slot(frameId, occurrence, {
1196
- ...args
1304
+ if (liveArgs) {
1305
+ for (const key of Object.keys(evals)) {
1306
+ if (regions.some(r => r.key === key)) continue;
1307
+ if (minted[key]) continue;
1308
+ const ledgerKey = `${frameId}:${occurrence}:${key}`;
1309
+ openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
1310
+ args[key] = argBorderForm(value, key, occurrence, documentNeeds);
1311
+ liveArgs.slot(frameId, occurrence, {
1312
+ ...args
1313
+ });
1197
1314
  });
1198
- });
1315
+ }
1199
1316
  }
1200
1317
  }
1318
+ if (rk !== undefined && (rk === occurrence || out.$face === SLOT_FACE_DATA)) repeats.has(rk) || repeats.set(rk, out);
1319
+ return out;
1320
+ } catch (error) {
1321
+ settleRecord && settleRecord(undefined);
1322
+ throw error;
1201
1323
  }
1202
- if (rk !== undefined && (rk === occurrence || out.$face === SLOT_FACE_DATA)) repeats.has(rk) || repeats.set(rk, out);
1203
- return out;
1204
1324
  };
1205
1325
  fn.$lhSkip = true;
1206
1326
  getters.set(prop, fn);
@@ -1216,6 +1336,17 @@ function frameElementOpen(id) {
1216
1336
  return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}" style="display:contents">`;
1217
1337
  }
1218
1338
  const FRAME_ELEMENT_CLOSE = `</${FRAME_TAG}>`;
1339
+ function documentNeeds(name) {
1340
+ const ctx = sharedConfig.context;
1341
+ const live = ctx && ctx.live;
1342
+ if (!live || !ctx.serialize) return;
1343
+ const tiers = live.tiers || (live.tiers = []);
1344
+ if (tiers.includes(name)) return;
1345
+ tiers.push(name);
1346
+ ctx.serialize("sc:tiers", tiers.slice());
1347
+ const url = live.tierUrls && live.tierUrls[name];
1348
+ if (url && ctx.registerAsset) ctx.registerAsset("module", url);
1349
+ }
1219
1350
  function armDocumentLiveHoles(ctx) {
1220
1351
  if (!ctx || ctx.liveHoles !== undefined) return;
1221
1352
  const live = ctx.live;
@@ -1236,14 +1367,27 @@ function armDocumentLiveHoles(ctx) {
1236
1367
  let epoch = 0;
1237
1368
  let sweepScheduled = false;
1238
1369
  let closed = false;
1370
+ let swept = null;
1239
1371
  const sweep = () => {
1240
1372
  epoch++;
1241
- for (const b of [...bindings.values()]) {
1242
- try {
1243
- b.sweep();
1244
- } catch (_) {
1373
+ const ops = swept = [];
1374
+ try {
1375
+ for (const b of [...bindings.values()]) {
1376
+ try {
1377
+ b.sweep();
1378
+ } catch (_) {
1379
+ }
1245
1380
  }
1381
+ } finally {
1382
+ swept = null;
1246
1383
  }
1384
+ pushOps(ops);
1385
+ };
1386
+ const pushOps = ops => {
1387
+ if (ops.length === 1) push(ops[0]);else if (ops.length) push({
1388
+ type: "ops",
1389
+ ops
1390
+ });
1247
1391
  };
1248
1392
  const scheduleSweep = () => {
1249
1393
  if (closed || sweepScheduled || !bindings.size) return;
@@ -1270,12 +1414,13 @@ function armDocumentLiveHoles(ctx) {
1270
1414
  bindings.delete(key);
1271
1415
  },
1272
1416
  hole(key, html) {
1273
- push({
1417
+ const op = {
1274
1418
  type: "hole",
1275
1419
  key,
1276
1420
  html,
1277
1421
  digest: textDigest(html)
1278
- });
1422
+ };
1423
+ swept ? swept.push(op) : pushOps([op]);
1279
1424
  },
1280
1425
  attr(key, attrs, removed) {
1281
1426
  const op = {
@@ -1285,7 +1430,7 @@ function armDocumentLiveHoles(ctx) {
1285
1430
  digest: textDigest(attrs)
1286
1431
  };
1287
1432
  if (removed && removed.length) op.removed = removed;
1288
- push(op);
1433
+ swept ? swept.push(op) : pushOps([op]);
1289
1434
  },
1290
1435
  error(key, error) {
1291
1436
  push({
@@ -1318,6 +1463,13 @@ function armDocumentLiveHoles(ctx) {
1318
1463
  },
1319
1464
  commit: scheduleSweep
1320
1465
  };
1466
+ live.error = (fid, error) => {
1467
+ push({
1468
+ type: "error",
1469
+ fid,
1470
+ error
1471
+ });
1472
+ };
1321
1473
  live.end = () => {
1322
1474
  if (closed) return;
1323
1475
  if (bindings.size) sweep();
@@ -1327,7 +1479,8 @@ function armDocumentLiveHoles(ctx) {
1327
1479
  }
1328
1480
  function frameTransformDirectResult(value, {
1329
1481
  id,
1330
- args
1482
+ args,
1483
+ tierUrls
1331
1484
  }) {
1332
1485
  if (typeof value !== "function") return value;
1333
1486
  const component = value;
@@ -1337,12 +1490,16 @@ function frameTransformDirectResult(value, {
1337
1490
  serverOwned(() => {
1338
1491
  const page = sharedConfig.context;
1339
1492
  armDocumentLiveHoles(page);
1493
+ if (tierUrls && page && page.live && !page.live.tierUrls) page.live.tierUrls = tierUrls;
1340
1494
  const ctx = Object.create(page);
1341
1495
  ctx.claims = CLAIMS_DOCUMENT;
1496
+ ctx.frameId = id;
1342
1497
  sharedConfig.context = ctx;
1343
1498
  try {
1344
1499
  const slotProps = createDocumentSlotProps(props, id);
1345
- return serverComponentScope(() => component(slotProps), !!wrapped[LIVE_SOURCE]);
1500
+ const live = !!wrapped[LIVE_SOURCE];
1501
+ if (live) documentNeeds("wire");
1502
+ return serverComponentScope(() => component(slotProps), live);
1346
1503
  } finally {
1347
1504
  sharedConfig.context = page;
1348
1505
  }
@@ -1454,6 +1611,7 @@ function createSlotProps(sink, frame) {
1454
1611
  const counts = Object.create(null);
1455
1612
  const getters = new Map();
1456
1613
  const repeats = new Map();
1614
+ const needs = sink.needs || (() => {});
1457
1615
  return new Proxy(Object.create(null), {
1458
1616
  has() {
1459
1617
  return true;
@@ -1465,7 +1623,7 @@ function createSlotProps(sink, frame) {
1465
1623
  if (!fn) {
1466
1624
  fn = (...callArgs) => {
1467
1625
  if (callArgs.length === 0 || callArgs[0] === undefined) {
1468
- return slotProxy(slotRange(prop), prop, SLOT_FACE_STREAM, undefined);
1626
+ return slotProxy(slotRange(prop), prop, SLOT_FACE_STREAM, undefined, undefined, needs);
1469
1627
  }
1470
1628
  const rk = repeatKey(prop, callArgs[0]);
1471
1629
  const repeat = rk !== undefined && repeats.get(rk);
@@ -1546,7 +1704,7 @@ function createSlotProps(sink, frame) {
1546
1704
  };
1547
1705
  } else {
1548
1706
  const ref = `arg:${occurrence}:${key}`;
1549
- ctx.serialize(ref, argBorderForm(value, key, occurrence));
1707
+ ctx.serialize(ref, argBorderForm(value, key, occurrence, needs));
1550
1708
  args[key] = {
1551
1709
  $ref: ref
1552
1710
  };
@@ -1578,7 +1736,7 @@ function createSlotProps(sink, frame) {
1578
1736
  } else {
1579
1737
  const ref = `arg:${occurrence}:${key}@${sink.nextArgRef(ledgerKey)}`;
1580
1738
  sink.mintRef(ref);
1581
- ctx.serialize(ref, argBorderForm(value));
1739
+ ctx.serialize(ref, argBorderForm(value, key, occurrence, needs));
1582
1740
  args[key] = {
1583
1741
  $ref: ref
1584
1742
  };
@@ -1589,7 +1747,7 @@ function createSlotProps(sink, frame) {
1589
1747
  });
1590
1748
  }
1591
1749
  const keyed = rk === occurrence;
1592
- const out = slotProxy(slotRange(occurrence), occurrence, SLOT_FACE_STREAM, undefined, rk === undefined || keyed ? undefined : () => repeats.has(rk) || repeats.set(rk, out));
1750
+ const out = slotProxy(slotRange(occurrence), occurrence, SLOT_FACE_STREAM, undefined, rk === undefined || keyed ? undefined : () => repeats.has(rk) || repeats.set(rk, out), needs);
1593
1751
  if (keyed) repeats.set(rk, out);
1594
1752
  return out;
1595
1753
  };
@@ -1648,9 +1806,6 @@ function serverComponentResponse(component, options = {}, init = {}) {
1648
1806
  } catch (_) {}
1649
1807
  };
1650
1808
  if (teardown.signal.aborted) return end();
1651
- teardown.signal.addEventListener("abort", end, {
1652
- once: true
1653
- });
1654
1809
  if (live) stopLive = armLiveBody(controller, () => {
1655
1810
  closed = true;
1656
1811
  disarm();
@@ -1665,14 +1820,19 @@ function serverComponentResponse(component, options = {}, init = {}) {
1665
1820
  closed = true;
1666
1821
  }
1667
1822
  },
1668
- end
1823
+ end,
1824
+ [ANNOUNCE](tiers) {
1825
+ if (tiers.length) headers.set(FRAME_TIERS_HEADER, tiers.join(","));
1826
+ }
1669
1827
  });
1670
1828
  },
1671
1829
  cancel() {
1672
1830
  closed = true;
1673
1831
  disarm();
1674
1832
  if (stopLive) stopLive();
1675
- teardown.abort();
1833
+ teardown.abort({
1834
+ [DISCONNECTED]: true
1835
+ });
1676
1836
  }
1677
1837
  });
1678
1838
  return new Response(body, {
@@ -1874,7 +2034,9 @@ function frameFlightResponse({
1874
2034
  cancel() {
1875
2035
  closed = true;
1876
2036
  disarm();
1877
- teardown.abort();
2037
+ teardown.abort({
2038
+ [DISCONNECTED]: true
2039
+ });
1878
2040
  }
1879
2041
  });
1880
2042
  return new Response(body, {
@@ -1889,4 +2051,4 @@ function asyncArg(value) {
1889
2051
  return value;
1890
2052
  }
1891
2053
 
1892
- export { FRAME_HAVE_BUDGET, FRAME_HAVE_HEADER, FRAME_STREAM_HEADER, SERVER_COMPONENT_BOOTSTRAP, ServerComponentPlugin, asyncArg, createFrameSink, frameTransformDirectResult, frameTransformFlightResult, frameTransformResult, isFrameStreamResponse, renderServerComponent, renderToFrameStream, serverComponentResponse };
2054
+ 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 };