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