@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 { OBSERVE, DEV, getOwner, NoHydration, 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, SLOT_VALUE } from '@solidjs/web';
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';
@@ -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
  }
@@ -209,14 +209,14 @@ setContainerTraceStreamMint(iterable => {
209
209
  })();
210
210
  return stream;
211
211
  });
212
- const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
212
+ const DEFAULT_WEB_PLUGINS = /* @__PURE__ */Object.freeze([AbortSignalPlugin,
213
213
  CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
214
214
  FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin,
215
215
  ContainerTracePlugin]);
216
216
  function resolveSerializerPlugins(customPlugins) {
217
217
  return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
218
218
  }
219
- const JSON_CODEC_DISABLED_FEATURES = Feature.RegExp;
219
+ const jsonCodecDisabledFeatures = () => Feature.RegExp;
220
220
  const JSON_CODEC_DEPTH_LIMIT = 64;
221
221
  function resolveCodecOptions({
222
222
  plugins,
@@ -226,13 +226,12 @@ function resolveCodecOptions({
226
226
  } = {}) {
227
227
  return {
228
228
  plugins: resolveSerializerPlugins(plugins),
229
- disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
229
+ disabledFeatures: disabledFeatures === undefined ? jsonCodecDisabledFeatures() : disabledFeatures,
230
230
  depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit,
231
231
  serializeErrorStacks
232
232
  };
233
233
  }
234
234
 
235
- Feature.AggregateError | Feature.BigIntTypedArray;
236
235
  const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : Feature.ErrorPrototypeStack;
237
236
  function createJSONSerializer({
238
237
  onData,
@@ -359,6 +358,7 @@ function observeFrame(frame) {
359
358
  }
360
359
 
361
360
  const FRAME_STREAM_HEADER = "X-Frame-Stream";
361
+ const FRAME_TIERS_HEADER = "X-Frame-Tiers";
362
362
  const FRAME_HAVE_HEADER = "X-Frame-Have";
363
363
  const FRAME_HAVE_BUDGET = 4096;
364
364
  function decodeHaveList(text) {
@@ -489,11 +489,27 @@ function withHoles(chunk, holes) {
489
489
  }
490
490
  return chunk;
491
491
  }
492
- function createFrameSink(emit, frame, have) {
492
+ function createFrameSink(write, frame, have, hooks) {
493
493
  const {
494
494
  id,
495
495
  version
496
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
+ };
497
513
  let conditional = false;
498
514
  const skipped = new Set();
499
515
  const attrText = new Map();
@@ -533,15 +549,38 @@ function createFrameSink(emit, frame, have) {
533
549
  let sweepScheduled = false;
534
550
  let closed = false;
535
551
  let epoch = 0;
552
+ let swept = null;
536
553
  const sweep = () => {
537
554
  epoch++;
538
- for (const b of [...bindings.values()]) {
539
- try {
540
- b.sweep();
541
- } 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
+ }
542
565
  }
566
+ emitOps(pass.ops);
567
+ if (pass.emitted && hooks && hooks.onYield) hooks.onYield();
568
+ } finally {
569
+ swept = null;
543
570
  }
544
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
+ };
545
584
  const scheduleSweep = () => {
546
585
  if (closed || sweepScheduled || !bindings.size) return;
547
586
  sweepScheduled = true;
@@ -585,6 +624,7 @@ function createFrameSink(emit, frame, have) {
585
624
  chunk.preloads.push(wirePreload(entry));
586
625
  }
587
626
  }
627
+ needs("assets");
588
628
  emit(chunk);
589
629
  }
590
630
  emit(withHoles({
@@ -660,6 +700,7 @@ function createFrameSink(emit, frame, have) {
660
700
  attrs: e.attrs
661
701
  }));
662
702
  }
703
+ needs("assets");
663
704
  emit(chunk);
664
705
  }
665
706
  emit(withHoles({
@@ -717,6 +758,7 @@ function createFrameSink(emit, frame, have) {
717
758
  },
718
759
  asset(type, value) {
719
760
  if (type === "module") {
761
+ needs("assets");
720
762
  emit({
721
763
  type: "assets",
722
764
  id,
@@ -725,6 +767,7 @@ function createFrameSink(emit, frame, have) {
725
767
  modules: [value]
726
768
  });
727
769
  } else if (type === "preload") {
770
+ needs("assets");
728
771
  emit({
729
772
  type: "assets",
730
773
  id,
@@ -734,14 +777,17 @@ function createFrameSink(emit, frame, have) {
734
777
  });
735
778
  }
736
779
  },
737
- end() {
738
- if (bindings.size) sweep();
780
+ end(bound) {
781
+ if (closed) return;
782
+ if (bindings.size && !swept) sweep();
739
783
  closed = true;
740
- emit({
784
+ const chunk = {
741
785
  type: "complete",
742
786
  id,
743
787
  version
744
- });
788
+ };
789
+ if (bound) chunk.bound = bound;
790
+ emit(chunk);
745
791
  },
746
792
  error(errorId, error) {
747
793
  emit({
@@ -762,6 +808,7 @@ function createFrameSink(emit, frame, have) {
762
808
  });
763
809
  },
764
810
  region(childId, html) {
811
+ needs("regions");
765
812
  emit({
766
813
  type: "html",
767
814
  id: childId,
@@ -770,26 +817,23 @@ function createFrameSink(emit, frame, have) {
770
817
  });
771
818
  },
772
819
  hole(key, html) {
773
- emit({
820
+ const op = {
774
821
  type: "hole",
775
- id,
776
- version,
777
822
  key,
778
823
  html,
779
824
  digest: textDigest(html)
780
- });
825
+ };
826
+ swept ? swept.ops.push(op) : emitOps([op]);
781
827
  },
782
828
  attr(key, attrs, removed) {
783
- const chunk = {
829
+ const op = {
784
830
  type: "attr",
785
- id,
786
- version,
787
831
  key,
788
832
  attrs,
789
833
  digest: textDigest(attrs)
790
834
  };
791
- if (removed && removed.length) chunk.removed = removed;
792
- emit(chunk);
835
+ if (removed && removed.length) op.removed = removed;
836
+ swept ? swept.ops.push(op) : emitOps([op]);
793
837
  },
794
838
  attrBaseline(key, text) {
795
839
  attrText.set(key, text);
@@ -811,6 +855,11 @@ function createFrameSink(emit, frame, have) {
811
855
  commit: scheduleSweep,
812
856
  get epoch() {
813
857
  return epoch;
858
+ },
859
+ needs,
860
+ announce() {
861
+ staged = [];
862
+ return [...tiers];
814
863
  }
815
864
  };
816
865
  }
@@ -832,6 +881,10 @@ function renderServerComponent(component, options = {}) {
832
881
  };
833
882
  }, options);
834
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");
835
888
  function frameStream(makeCode, options) {
836
889
  const {
837
890
  id = "",
@@ -841,30 +894,77 @@ function frameStream(makeCode, options) {
841
894
  id,
842
895
  version
843
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;
844
900
  function stream(w) {
845
901
  const observation = observeFrame(frame);
846
- const emit = observation ? chunk => {
847
- 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);
848
933
  w.write(chunk);
849
- } : chunk => w.write(chunk);
850
- 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");
851
945
  w.write({
852
946
  type: "start",
853
947
  id,
854
948
  version
855
949
  });
950
+ if (upstream && upstream.aborted) return finish();
951
+ if (upstream) upstream.addEventListener("abort", onSignal, {
952
+ once: true
953
+ });
856
954
  const code = makeCode(sink, frame);
857
955
  try {
858
956
  renderToStream(() => serverOwned(code), {
859
957
  serializer: createJSONSerializer,
860
958
  ...options,
959
+ signal: render.signal,
861
960
  sink
862
961
  }).pipe({
863
962
  write() {},
864
963
  end() {
964
+ if (ended) return;
865
965
  sink.end();
866
966
  observation && observation.settle("complete");
867
- w.end && w.end();
967
+ finish();
868
968
  }
869
969
  });
870
970
  } catch (err) {
@@ -872,8 +972,9 @@ function frameStream(makeCode, options) {
872
972
  sink.error("", wire instanceof Error ? wire.message : String(wire));
873
973
  sink.end();
874
974
  observation && observation.settle("error", err);
875
- w.end && w.end();
975
+ finish();
876
976
  }
977
+ if (w[ANNOUNCE]) w[ANNOUNCE](sink.announce());
877
978
  }
878
979
  return {
879
980
  pipe: stream,
@@ -905,21 +1006,25 @@ function isRangeKey(key) {
905
1006
  const c = key.charCodeAt(0);
906
1007
  return c === 36 || c >= 48 && c <= 57 || RANGE_KEYS.has(key);
907
1008
  }
908
- function slotProxy(range, occurrence, face, content, onData) {
1009
+ function slotProxy(range, occurrence, face, content, onData, needs) {
909
1010
  return new Proxy(range, {
910
1011
  get(target, key, receiver) {
911
1012
  if (typeof key !== "string" || isRangeKey(key)) return Reflect.get(target, key, receiver);
912
1013
  if (onData) onData = void onData();
1014
+ if (face !== SLOT_FACE_MARKUP) needs("bind");
913
1015
  return slotValue(occurrence, key, content ? content[key] : undefined, face);
914
1016
  }
915
1017
  });
916
1018
  }
917
- function argBorderForm(value, key, occurrence) {
918
- return toBorderForm(withoutStandIns(value, key, occurrence));
1019
+ function argBorderForm(value, key, occurrence, needs) {
1020
+ return toBorderForm(withoutStandIns(value, key, occurrence, needs));
919
1021
  }
920
- function withoutStandIns(value, key, occurrence) {
1022
+ function withoutStandIns(value, key, occurrence, needs) {
921
1023
  return rewriteTree(value, (v, path) => {
922
- if (isContainerTraced(v)) return v;
1024
+ if (isContainerTraced(v)) {
1025
+ needs("trace");
1026
+ return v;
1027
+ }
923
1028
  if (Object.getPrototypeOf(v) === Object.prototype && isSlotValue(v)) {
924
1029
  standInArgFinding(v, key, occurrence, path);
925
1030
  return undefined;
@@ -938,10 +1043,10 @@ function standInArgFinding(sv, key, occurrence, path) {
938
1043
  }
939
1044
  const where = path === "" ? `Arg \`${key}\`` : `Arg \`${key}${path}\``;
940
1045
  devCheck({
941
- code: "ATTRIBUTE_SLOT_POSITION",
1046
+ code: "BINDING_SLOT_POSITION",
942
1047
  kind: "ssr",
943
1048
  severity: "warn",
944
- message: `[ATTRIBUTE_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.`,
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.`,
945
1050
  data: {
946
1051
  reason: "arg",
947
1052
  occurrence,
@@ -970,10 +1075,10 @@ function slotFace(range, content) {
970
1075
  for (const key of Object.keys(content)) {
971
1076
  if (isRangeKey(key)) {
972
1077
  devCheck({
973
- code: "ATTRIBUTE_SLOT_POSITION",
1078
+ code: "BINDING_SLOT_POSITION",
974
1079
  kind: "ssr",
975
1080
  severity: "warn",
976
- message: `[ATTRIBUTE_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.`,
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.`,
977
1082
  data: {
978
1083
  reason: "reserved-key",
979
1084
  occurrence: range.$occurrence,
@@ -1084,7 +1189,7 @@ function createDocumentSlotProps(clientProps, frameId) {
1084
1189
  r.$occurrence = occurrence;
1085
1190
  const face = slotFace(r, content);
1086
1191
  r.$face = face;
1087
- return slotProxy(r, occurrence, face, face === SLOT_FACE_DATA ? content : undefined);
1192
+ return slotProxy(r, occurrence, face, face === SLOT_FACE_DATA ? content : undefined, undefined, documentNeeds);
1088
1193
  };
1089
1194
  const zoneOwner = getOwner ? getOwner() : null;
1090
1195
  const scoped = (occurrence, render) => {
@@ -1125,136 +1230,151 @@ function createDocumentSlotProps(clientProps, frameId) {
1125
1230
  const occurrence = occurrenceId(prop, raw, counts);
1126
1231
  const slot = clientProps[prop];
1127
1232
  if (typeof slot !== "function") return range(occurrence, undefined);
1128
- const resolved = {};
1129
- const liveArgs = sharedConfig.context && sharedConfig.context.live && sharedConfig.context.live.args;
1130
- const vals = {};
1131
- const evals = {};
1132
- const states = {};
1133
- const minted = {};
1134
- for (const key of Object.keys(raw)) {
1135
- if (key === "$key") continue;
1136
- const desc = Object.getOwnPropertyDescriptor(raw, key);
1137
- let evaluate = null;
1138
- let value;
1139
- if (desc.get) {
1140
- const get = desc.get;
1141
- evaluate = () => unwrapThunks(get.call(raw));
1142
- } else {
1143
- value = desc.value;
1144
- if (typeof value === "function") {
1145
- const fn = value;
1146
- 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
+ }
1147
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;
1284
+ }
1285
+ vals[key] = value;
1148
1286
  }
1149
- if (evaluate) {
1150
- evals[key] = evaluate;
1151
- const stampBefore = scopeStamp();
1152
- try {
1153
- value = evaluate();
1154
- states[key] = {
1155
- settled: true,
1156
- 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
1157
1301
  };
1158
- } catch (err) {
1159
- const blocked = ssrHandleError && ssrHandleError(err);
1160
- if (!blocked) throw err;
1161
- const state = states[key] = {
1162
- settled: false,
1163
- 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
+ }];
1164
1312
  };
1165
- value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
1166
- state.settled = true;
1167
- state.last = v;
1168
- 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
1169
1328
  });
1329
+ } else {
1330
+ resolved[key] = vals[key] = withoutStandIns(value, key, occurrence, documentNeeds);
1170
1331
  }
1171
- if (scopeStamp() !== stampBefore) minted[key] = true;
1172
1332
  }
1173
- vals[key] = value;
1174
- }
1175
- const regions = [];
1176
- for (const key of Object.keys(vals)) {
1177
- const value = vals[key];
1178
- if (isContainerTraced(value)) {
1179
- resolved[key] = value;
1180
- } else if (isServerContent(value)) {
1181
- const childId = `${frameId}.${occurrence}.${key}`;
1182
- const region = {
1183
- key,
1184
- childId,
1185
- value,
1186
- used: false,
1187
- locked: false
1188
- };
1189
- regions.push(region);
1190
- resolved[key] = () => {
1191
- if (region.locked) return [];
1192
- region.used = true;
1193
- return [{
1194
- t: frameElementOpen(childId)
1195
- }, value, {
1196
- t: FRAME_ELEMENT_CLOSE
1197
- }];
1198
- };
1199
- } else if (ssrAsyncValue && isAsyncValue(value)) {
1200
- let readable = value;
1201
- if (typeof value.then !== "function") {
1202
- const {
1203
- first,
1204
- rest
1205
- } = tapFirstYield(value);
1206
- readable = first;
1207
- 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);
1208
1348
  }
1209
- const read = ssrAsyncValue(readable);
1210
- Object.defineProperty(resolved, key, {
1211
- get: read,
1212
- enumerable: true,
1213
- configurable: true
1349
+ settleRecord ? settleRecord({
1350
+ ...args
1351
+ }) : context.serialize(recordKey, {
1352
+ ...args
1214
1353
  });
1215
- } else {
1216
- resolved[key] = vals[key] = withoutStandIns(value, key, occurrence);
1217
- }
1218
- }
1219
- const out = suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved))));
1220
- const unused = regions.filter(r => !r.used);
1221
- if (sharedConfig.context) {
1222
- const args = {};
1223
- for (const key of Object.keys(vals)) {
1224
- const value = vals[key];
1225
- const region = regions.find(r => r.key === key);
1226
- if (region) {
1227
- args[key] = {
1228
- $frame: region.childId
1229
- };
1230
- continue;
1354
+ for (const region of unused) {
1355
+ region.locked = true;
1356
+ context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(context, region.value));
1231
1357
  }
1232
- if (!isContainerTraced(value) && isServerContent(value)) continue;
1233
- args[key] = argBorderForm(value, key, occurrence);
1234
- }
1235
- sharedConfig.context.serialize(`sc:slot:${frameId}:${occurrence}`, {
1236
- ...args
1237
- });
1238
- for (const region of unused) {
1239
- region.locked = true;
1240
- sharedConfig.context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(sharedConfig.context, region.value));
1241
- }
1242
- if (liveArgs) {
1243
- for (const key of Object.keys(evals)) {
1244
- if (regions.some(r => r.key === key)) continue;
1245
- if (minted[key]) continue;
1246
- const ledgerKey = `${frameId}:${occurrence}:${key}`;
1247
- openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
1248
- args[key] = argBorderForm(value, key, occurrence);
1249
- liveArgs.slot(frameId, occurrence, {
1250
- ...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
+ });
1251
1368
  });
1252
- });
1369
+ }
1253
1370
  }
1254
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;
1255
1377
  }
1256
- if (rk !== undefined && (rk === occurrence || out.$face === SLOT_FACE_DATA)) repeats.has(rk) || repeats.set(rk, out);
1257
- return out;
1258
1378
  };
1259
1379
  fn.$lhSkip = true;
1260
1380
  getters.set(prop, fn);
@@ -1270,6 +1390,17 @@ function frameElementOpen(id) {
1270
1390
  return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}" style="display:contents">`;
1271
1391
  }
1272
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
+ }
1273
1404
  function armDocumentLiveHoles(ctx) {
1274
1405
  if (!ctx || ctx.liveHoles !== undefined) return;
1275
1406
  const live = ctx.live;
@@ -1290,14 +1421,27 @@ function armDocumentLiveHoles(ctx) {
1290
1421
  let epoch = 0;
1291
1422
  let sweepScheduled = false;
1292
1423
  let closed = false;
1424
+ let swept = null;
1293
1425
  const sweep = () => {
1294
1426
  epoch++;
1295
- for (const b of [...bindings.values()]) {
1296
- try {
1297
- b.sweep();
1298
- } catch (_) {
1427
+ const ops = swept = [];
1428
+ try {
1429
+ for (const b of [...bindings.values()]) {
1430
+ try {
1431
+ b.sweep();
1432
+ } catch (_) {
1433
+ }
1299
1434
  }
1435
+ } finally {
1436
+ swept = null;
1300
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
+ });
1301
1445
  };
1302
1446
  const scheduleSweep = () => {
1303
1447
  if (closed || sweepScheduled || !bindings.size) return;
@@ -1324,12 +1468,13 @@ function armDocumentLiveHoles(ctx) {
1324
1468
  bindings.delete(key);
1325
1469
  },
1326
1470
  hole(key, html) {
1327
- push({
1471
+ const op = {
1328
1472
  type: "hole",
1329
1473
  key,
1330
1474
  html,
1331
1475
  digest: textDigest(html)
1332
- });
1476
+ };
1477
+ swept ? swept.push(op) : pushOps([op]);
1333
1478
  },
1334
1479
  attr(key, attrs, removed) {
1335
1480
  const op = {
@@ -1339,7 +1484,7 @@ function armDocumentLiveHoles(ctx) {
1339
1484
  digest: textDigest(attrs)
1340
1485
  };
1341
1486
  if (removed && removed.length) op.removed = removed;
1342
- push(op);
1487
+ swept ? swept.push(op) : pushOps([op]);
1343
1488
  },
1344
1489
  error(key, error) {
1345
1490
  push({
@@ -1372,6 +1517,13 @@ function armDocumentLiveHoles(ctx) {
1372
1517
  },
1373
1518
  commit: scheduleSweep
1374
1519
  };
1520
+ live.error = (fid, error) => {
1521
+ push({
1522
+ type: "error",
1523
+ fid,
1524
+ error
1525
+ });
1526
+ };
1375
1527
  live.end = () => {
1376
1528
  if (closed) return;
1377
1529
  if (bindings.size) sweep();
@@ -1381,7 +1533,8 @@ function armDocumentLiveHoles(ctx) {
1381
1533
  }
1382
1534
  function frameTransformDirectResult(value, {
1383
1535
  id,
1384
- args
1536
+ args,
1537
+ tierUrls
1385
1538
  }) {
1386
1539
  if (typeof value !== "function") return value;
1387
1540
  const component = value;
@@ -1391,12 +1544,16 @@ function frameTransformDirectResult(value, {
1391
1544
  serverOwned(() => {
1392
1545
  const page = sharedConfig.context;
1393
1546
  armDocumentLiveHoles(page);
1547
+ if (tierUrls && page && page.live && !page.live.tierUrls) page.live.tierUrls = tierUrls;
1394
1548
  const ctx = Object.create(page);
1395
1549
  ctx.claims = CLAIMS_DOCUMENT;
1550
+ ctx.frameId = id;
1396
1551
  sharedConfig.context = ctx;
1397
1552
  try {
1398
1553
  const slotProps = createDocumentSlotProps(props, id);
1399
- return serverComponentScope(() => component(slotProps), !!wrapped[LIVE_SOURCE]);
1554
+ const live = !!wrapped[LIVE_SOURCE];
1555
+ if (live) documentNeeds("wire");
1556
+ return serverComponentScope(() => component(slotProps), live);
1400
1557
  } finally {
1401
1558
  sharedConfig.context = page;
1402
1559
  }
@@ -1508,6 +1665,7 @@ function createSlotProps(sink, frame) {
1508
1665
  const counts = Object.create(null);
1509
1666
  const getters = new Map();
1510
1667
  const repeats = new Map();
1668
+ const needs = sink.needs || (() => {});
1511
1669
  return new Proxy(Object.create(null), {
1512
1670
  has() {
1513
1671
  return true;
@@ -1519,7 +1677,7 @@ function createSlotProps(sink, frame) {
1519
1677
  if (!fn) {
1520
1678
  fn = (...callArgs) => {
1521
1679
  if (callArgs.length === 0 || callArgs[0] === undefined) {
1522
- return slotProxy(slotRange(prop), prop, SLOT_FACE_STREAM, undefined);
1680
+ return slotProxy(slotRange(prop), prop, SLOT_FACE_STREAM, undefined, undefined, needs);
1523
1681
  }
1524
1682
  const rk = repeatKey(prop, callArgs[0]);
1525
1683
  const repeat = rk !== undefined && repeats.get(rk);
@@ -1600,7 +1758,7 @@ function createSlotProps(sink, frame) {
1600
1758
  };
1601
1759
  } else {
1602
1760
  const ref = `arg:${occurrence}:${key}`;
1603
- ctx.serialize(ref, argBorderForm(value, key, occurrence));
1761
+ ctx.serialize(ref, argBorderForm(value, key, occurrence, needs));
1604
1762
  args[key] = {
1605
1763
  $ref: ref
1606
1764
  };
@@ -1632,7 +1790,7 @@ function createSlotProps(sink, frame) {
1632
1790
  } else {
1633
1791
  const ref = `arg:${occurrence}:${key}@${sink.nextArgRef(ledgerKey)}`;
1634
1792
  sink.mintRef(ref);
1635
- ctx.serialize(ref, argBorderForm(value, key, occurrence));
1793
+ ctx.serialize(ref, argBorderForm(value, key, occurrence, needs));
1636
1794
  args[key] = {
1637
1795
  $ref: ref
1638
1796
  };
@@ -1643,7 +1801,7 @@ function createSlotProps(sink, frame) {
1643
1801
  });
1644
1802
  }
1645
1803
  const keyed = rk === occurrence;
1646
- const out = slotProxy(slotRange(occurrence), occurrence, SLOT_FACE_STREAM, undefined, rk === undefined || keyed ? undefined : () => repeats.has(rk) || repeats.set(rk, out));
1804
+ const out = slotProxy(slotRange(occurrence), occurrence, SLOT_FACE_STREAM, undefined, rk === undefined || keyed ? undefined : () => repeats.has(rk) || repeats.set(rk, out), needs);
1647
1805
  if (keyed) repeats.set(rk, out);
1648
1806
  return out;
1649
1807
  };
@@ -1702,9 +1860,6 @@ function serverComponentResponse(component, options = {}, init = {}) {
1702
1860
  } catch (_) {}
1703
1861
  };
1704
1862
  if (teardown.signal.aborted) return end();
1705
- teardown.signal.addEventListener("abort", end, {
1706
- once: true
1707
- });
1708
1863
  if (live) stopLive = armLiveBody(controller, () => {
1709
1864
  closed = true;
1710
1865
  disarm();
@@ -1719,14 +1874,19 @@ function serverComponentResponse(component, options = {}, init = {}) {
1719
1874
  closed = true;
1720
1875
  }
1721
1876
  },
1722
- end
1877
+ end,
1878
+ [ANNOUNCE](tiers) {
1879
+ if (tiers.length) headers.set(FRAME_TIERS_HEADER, tiers.join(","));
1880
+ }
1723
1881
  });
1724
1882
  },
1725
1883
  cancel() {
1726
1884
  closed = true;
1727
1885
  disarm();
1728
1886
  if (stopLive) stopLive();
1729
- teardown.abort();
1887
+ teardown.abort({
1888
+ [DISCONNECTED]: true
1889
+ });
1730
1890
  }
1731
1891
  });
1732
1892
  return new Response(body, {
@@ -1928,7 +2088,9 @@ function frameFlightResponse({
1928
2088
  cancel() {
1929
2089
  closed = true;
1930
2090
  disarm();
1931
- teardown.abort();
2091
+ teardown.abort({
2092
+ [DISCONNECTED]: true
2093
+ });
1932
2094
  }
1933
2095
  });
1934
2096
  return new Response(body, {
@@ -1943,4 +2105,4 @@ function asyncArg(value) {
1943
2105
  return value;
1944
2106
  }
1945
2107
 
1946
- 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 };