@solidjs/web 2.0.0-rc.15 → 2.0.0-rc.16

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 (53) hide show
  1. package/README.md +1 -1
  2. package/dist/server.dev.js +358 -479
  3. package/dist/server.js +343 -387
  4. package/dist/server.observe.js +343 -387
  5. package/dist/web.dev.js +57 -54
  6. package/dist/web.js +47 -49
  7. package/dist/web.observe.js +57 -54
  8. package/frames/dist/client.dev.js +610 -621
  9. package/frames/dist/client.js +540 -566
  10. package/frames/dist/client.observe.js +571 -573
  11. package/frames/dist/regions.js +43 -2
  12. package/frames/dist/server.dev.js +514 -423
  13. package/frames/dist/server.js +514 -370
  14. package/frames/dist/server.observe.js +514 -370
  15. package/frames/dist/wire.js +371 -6
  16. package/package.json +11 -11
  17. package/serialization/dist/decode.js +9 -7
  18. package/serialization/dist/serialization.js +9 -7
  19. package/serialization/types/serializer-decode.d.ts +2 -2
  20. package/server-functions/dist/client.dev.js +3 -1
  21. package/server-functions/dist/client.js +1 -1
  22. package/server-functions/dist/client.observe.js +3 -1
  23. package/server-functions/dist/rich-args.js +33 -1
  24. package/server-functions/dist/server.dev.js +127 -18
  25. package/server-functions/dist/server.js +127 -18
  26. package/server-functions/dist/server.observe.js +127 -18
  27. package/skills/server-components/SKILL.md +74 -185
  28. package/types/client.d.ts +15 -5
  29. package/types/frames/assets-tier.d.ts +2 -2
  30. package/types/frames/client.d.ts +8 -3
  31. package/types/frames/frame-client.d.ts +121 -157
  32. package/types/frames/frame-morph.d.ts +28 -0
  33. package/types/frames/frame-sink.d.ts +13 -9
  34. package/types/frames/frame-transport.d.ts +30 -1
  35. package/types/frames/regions-tier.d.ts +15 -0
  36. package/types/frames/serializer-decode.d.ts +2 -2
  37. package/types/frames/server.d.ts +0 -52
  38. package/types/frames/wire-tier.d.ts +54 -1
  39. package/types/index.d.ts +2 -2
  40. package/types/jsx.d.ts +11 -5
  41. package/types/observe.d.ts +14 -7
  42. package/types/render.d.ts +3 -1
  43. package/types/response.d.ts +5 -4
  44. package/types/serializer-decode.d.ts +2 -2
  45. package/types/server-functions/argument-codec.d.ts +21 -0
  46. package/types/server-functions/client.d.ts +14 -5
  47. package/types/server-functions/server.d.ts +6 -2
  48. package/types/server-functions/shared.d.ts +19 -0
  49. package/types/server-observe.d.ts +3 -2
  50. package/types/server.d.ts +57 -76
  51. package/frames/dist/bind.dev.js +0 -326
  52. package/frames/dist/bind.js +0 -295
  53. package/types/frames/bind-tier.d.ts +0 -60
@@ -1,6 +1,6 @@
1
- import { sharedConfig, ssrSanitizeError, creationStamp, ssrHandleError, runInServerComponentScope, shareAsyncIterable, getProjectionTrace } from 'solid-js/internal';
2
- import { getOwner, NoHydration, runWithOwner, createMemo, Hydration, createOwner } from 'solid-js';
3
- import { isResponseEnvelope, renderToStream, createLiveHoles, CLAIMS_STREAM, CLAIMS_DOCUMENT, SLOT_FACE_DATA, SLOT_FACE_MARKUP, slotValue, SLOT_FACE_STREAM, isSlotValue } from '@solidjs/web';
1
+ import { sharedConfig, ssrSanitizeError, creationStamp, ssrHandleError, runInServerComponentScope, trackFillReads, shareAsyncIterable, getProjectionTrace } from 'solid-js/internal';
2
+ import { getOwner, NoHydration, runWithOwner, createMemo, createOwner, Hydration } from 'solid-js';
3
+ import { isResponseEnvelope, renderToStream, createLiveHoles } 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 { frameAddress, getEventServerFunctionInvocation, ChunkReader, serializeStream, guardFailures, armLiveBody, createEventChunk, createChunk, textDigest } from '@solidjs/web/server-functions/server';
@@ -207,14 +207,16 @@ function resolveSerializerPlugins(customPlugins) {
207
207
  }
208
208
  const jsonCodecDisabledFeatures = () => Feature.RegExp;
209
209
  const JSON_CODEC_DEPTH_LIMIT = 64;
210
- function resolveCodecOptions({
211
- plugins,
212
- disabledFeatures,
213
- depthLimit,
214
- serializeErrorStacks
215
- } = {}) {
210
+ const RESOLVED_PLUGINS = Symbol.for("solid.codec.resolvedPlugins");
211
+ function resolveCodecOptions(options = {}) {
212
+ const {
213
+ plugins,
214
+ disabledFeatures,
215
+ depthLimit,
216
+ serializeErrorStacks
217
+ } = options;
216
218
  return {
217
- plugins: resolveSerializerPlugins(plugins),
219
+ plugins: options[RESOLVED_PLUGINS] || resolveSerializerPlugins(plugins),
218
220
  disabledFeatures: disabledFeatures === undefined ? jsonCodecDisabledFeatures() : disabledFeatures,
219
221
  depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit,
220
222
  serializeErrorStacks
@@ -293,8 +295,17 @@ function createJSONSerializer({
293
295
  function records() {
294
296
  return undefined;
295
297
  }
296
- function frameCensus(event, type, own) {
297
- event.chunks++;
298
+ function frameRecordCensus(event, message, own) {
299
+ const r = message.r;
300
+ let counted = !r;
301
+ for (const key in r) {
302
+ if (key === ":complete" || key === ":bound") continue;
303
+ counted = true;
304
+ countEvent(event, key === "" ? "html" : key.endsWith(":error") ? "error" : key.startsWith("slot:") ? "slot" : key.startsWith("seg:") && r[key] && r[key].kind === "html" ? "fragment" : key, own);
305
+ }
306
+ if (counted) event.chunks++;
307
+ }
308
+ function countEvent(event, type, own) {
298
309
  switch (type) {
299
310
  case "html":
300
311
  if (!own) event.regions++;else if (event.shellMs === undefined) event.shellMs = performance.now() - event.at;
@@ -329,9 +340,8 @@ function observeFrame(frame) {
329
340
  };
330
341
  let settled = false;
331
342
  return {
332
- chunk(chunk) {
333
- if (chunk.type === "complete") return;
334
- frameCensus(event, chunk.type, chunk.id === frame.id);
343
+ chunk(message) {
344
+ frameRecordCensus(event, message, message.id === frame.id);
335
345
  },
336
346
  settle(outcome, error) {
337
347
  if (settled) return;
@@ -484,14 +494,41 @@ function createFrameSink(write, frame, have, hooks) {
484
494
  } = frame;
485
495
  const tiers = new Set();
486
496
  let staged = [];
487
- const emit = chunk => {
488
- if (swept) swept.emitted = true;
497
+ const send = message => {
489
498
  if (staged.length) {
490
- chunk.tiers = staged;
499
+ message.tiers = staged;
491
500
  staged = [];
492
501
  }
493
- write(chunk);
502
+ write(message);
503
+ };
504
+ let queue = [];
505
+ let open = null;
506
+ let scheduled = false;
507
+ const flush = () => {
508
+ scheduled = false;
509
+ open = null;
510
+ const out = queue;
511
+ queue = [];
512
+ for (const message of out) send(message);
513
+ };
514
+ const put = (fid, r) => {
515
+ if (swept) swept.emitted = true;
516
+ showing(r);
517
+ let merge = open && open.id === fid;
518
+ if (merge) for (const key in r) if (key in open.r) merge = false;
519
+ if (merge) Object.assign(open.r, r);else queue.push(open = {
520
+ id: fid,
521
+ version,
522
+ r
523
+ });
524
+ if (!scheduled) {
525
+ scheduled = true;
526
+ queueMicrotask(flush);
527
+ }
494
528
  };
529
+ const putError = (fid, key, error) => put(fid, {
530
+ [key ? `${/^lha?:/.test(key) ? "hole" : "seg"}:${key}:error` : ":error"]: error
531
+ });
495
532
  const needs = name => {
496
533
  if (!tiers.has(name)) {
497
534
  tiers.add(name);
@@ -501,36 +538,44 @@ function createFrameSink(write, frame, have, hooks) {
501
538
  let conditional = false;
502
539
  const skipped = new Set();
503
540
  const attrText = new Map();
504
- const emitDiffering = html => {
505
- for (const m of html.matchAll(HOLE_RANGE)) {
541
+ const holeDigest = new Map();
542
+ if (have) for (const key in have) key.startsWith("lh:") && holeDigest.set(key, have[key]);
543
+ function showing(r) {
544
+ if ("" in r) holeDigest.clear();
545
+ for (const k in r) {
546
+ const record = r[k];
547
+ if (k.startsWith("hole:lh:") && !k.endsWith(":error")) holeDigest.set(k.slice(5), record.digest);
548
+ if (record) for (const key in record.holes) key.startsWith("lh:") && holeDigest.set(key, record.holes[key]);
549
+ }
550
+ }
551
+ const html = (value, digest, holes) => withHoles({
552
+ kind: "html",
553
+ value,
554
+ digest
555
+ }, holes);
556
+ const emitDiffering = source => {
557
+ for (const m of source.matchAll(HOLE_RANGE)) {
506
558
  const key = "lh:" + m[1];
507
559
  const digest = textDigest(stripHoleMarkers(m[2]));
508
560
  if (have[key] === digest) continue;
509
- emit(withHoles({
510
- type: "hole",
511
- id,
512
- version,
513
- key,
514
- html: m[2],
515
- digest
516
- }, holeDigests(m[2], null)));
561
+ put(id, {
562
+ ["hole:" + key]: html(m[2], digest, holeDigests(m[2], null))
563
+ });
517
564
  }
518
- for (const m of html.matchAll(ATTR_ADDRESS)) {
565
+ for (const m of source.matchAll(ATTR_ADDRESS)) {
519
566
  const text = attrText.get("lha:" + m[1]);
520
567
  if (text === undefined) continue;
521
568
  const digest = textDigest(text);
522
569
  if (have["lha:" + m[1]] === digest) continue;
523
- emit({
524
- type: "attr",
525
- id,
526
- version,
527
- key: m[1],
528
- attrs: text,
529
- digest
570
+ put(id, {
571
+ ["attr:" + m[1]]: {
572
+ kind: "attrs",
573
+ value: text,
574
+ digest
575
+ }
530
576
  });
531
577
  }
532
578
  };
533
- const styledKeys = new Set();
534
579
  const bindings = new Map();
535
580
  const sweepMinted = new Set();
536
581
  const argRefVersions = new Map();
@@ -541,34 +586,27 @@ function createFrameSink(write, frame, have, hooks) {
541
586
  const sweep = () => {
542
587
  epoch++;
543
588
  const pass = swept = {
544
- ops: [],
589
+ r: {},
545
590
  emitted: false
546
591
  };
547
592
  try {
548
- for (const b of [...bindings.values()]) {
593
+ for (const [key, b] of [...bindings]) {
594
+ if (bindings.get(key) !== b) continue;
549
595
  try {
550
596
  b.sweep();
551
597
  } catch (_) {
552
598
  }
553
599
  }
554
- emitOps(pass.ops);
600
+ for (const _ in pass.r) {
601
+ put(id, pass.r);
602
+ break;
603
+ }
604
+ flush();
555
605
  if (pass.emitted && hooks && hooks.onYield) hooks.onYield();
556
606
  } finally {
557
607
  swept = null;
558
608
  }
559
609
  };
560
- const emitOps = ops => {
561
- if (ops.length === 1) emit(Object.assign({
562
- type: ops[0].type,
563
- id,
564
- version
565
- }, ops[0]));else if (ops.length) emit({
566
- type: "ops",
567
- id,
568
- version,
569
- ops
570
- });
571
- };
572
610
  const scheduleSweep = () => {
573
611
  if (closed || sweepScheduled || !bindings.size) return;
574
612
  sweepScheduled = true;
@@ -583,52 +621,47 @@ function createFrameSink(write, frame, have, hooks) {
583
621
  tagRegion(key, childId) {
584
622
  if (!regionKeys.has(key)) regionKeys.set(key, childId);
585
623
  },
586
- shell(html, meta = {}) {
587
- const digest = textDigest(frameSkeleton(html));
624
+ shell(source, meta = {}) {
625
+ const digest = textDigest(frameSkeleton(source));
588
626
  if (have && have[""] === digest) {
589
627
  conditional = true;
590
- emitDiffering(html);
628
+ emitDiffering(source);
591
629
  return;
592
630
  }
593
631
  if (meta.preloads && meta.preloads.size || meta.preloadLinks) {
594
- const chunk = {
595
- type: "assets",
596
- id,
597
- version,
598
- key: ""
599
- };
632
+ const record = {};
600
633
  if (meta.preloads && meta.preloads.size) {
601
634
  const styles = [];
602
635
  const modules = [];
603
636
  for (const url of meta.preloads) {
604
637
  (url.endsWith(".css") ? styles : modules).push(url);
605
638
  }
606
- if (styles.length) chunk.styles = styles;
607
- if (modules.length) chunk.modules = modules;
639
+ if (styles.length) record.styles = styles;
640
+ if (modules.length) record.modules = modules;
608
641
  }
609
642
  if (meta.preloadLinks) {
610
- chunk.preloads = [];
643
+ record.preloads = [];
611
644
  for (const entry of meta.preloadLinks) {
612
- chunk.preloads.push(wirePreload(entry));
645
+ record.preloads.push(wirePreload(entry));
613
646
  }
614
647
  }
615
648
  needs("assets");
616
- emit(chunk);
649
+ put(id, {
650
+ "seg::assets": record
651
+ });
617
652
  }
618
- emit(withHoles({
619
- type: "html",
620
- id,
621
- version,
622
- html,
623
- digest
624
- }, holeDigests(html, attrText)));
653
+ put(id, {
654
+ "": html(source, digest, holeDigests(source, attrText))
655
+ });
625
656
  },
626
657
  data(record) {
627
658
  if (record && typeof record.key === "string" && (record.key.endsWith("_fr") || /^\d+$/.test(record.key))) {
628
659
  return;
629
660
  }
661
+ if (swept) swept.emitted = true;
662
+ flush();
630
663
  if (typeof record === "string") {
631
- emit({
664
+ send({
632
665
  type: "data",
633
666
  id,
634
667
  version,
@@ -636,7 +669,7 @@ function createFrameSink(write, frame, have, hooks) {
636
669
  });
637
670
  scheduleSweep();
638
671
  } else {
639
- emit({
672
+ send({
640
673
  type: "data",
641
674
  id,
642
675
  version,
@@ -653,73 +686,40 @@ function createFrameSink(write, frame, have, hooks) {
653
686
  skipped.add(key);
654
687
  scheduleSweep();
655
688
  if (meta.error) {
656
- emit({
657
- type: "error",
658
- id: fid,
659
- version,
660
- key,
661
- error: {
662
- message: String(meta.error && meta.error.message || meta.error)
663
- }
689
+ putError(fid, key, {
690
+ message: String(meta.error && meta.error.message || meta.error)
664
691
  });
665
692
  } else emitDiffering(value);
666
693
  return;
667
694
  }
668
695
  const links = meta.styles && meta.styles.links || [];
669
696
  const inline = meta.styles && meta.styles.inline || [];
697
+ const r = {};
670
698
  if (links.length || inline.length) {
671
- if (links.length) styledKeys.add(key);
672
- const chunk = {
673
- type: "assets",
674
- id: fid,
675
- version,
676
- key
677
- };
699
+ const record = {};
678
700
  if (links.length) {
679
- chunk.styles = links.map(e => typeof e === "string" ? e : e.attrs ? {
701
+ record.styles = links.map(e => typeof e === "string" ? e : e.attrs ? {
680
702
  href: e.href,
681
703
  attrs: e.attrs
682
704
  } : e.href);
683
705
  }
684
706
  if (inline.length) {
685
- chunk.inlineStyles = inline.map(e => ({
707
+ record.inlineStyles = inline.map(e => ({
686
708
  id: e.id,
687
709
  content: e.content,
688
710
  attrs: e.attrs
689
711
  }));
690
712
  }
691
713
  needs("assets");
692
- emit(chunk);
714
+ r[`seg:${key}:assets`] = record;
693
715
  }
694
- emit(withHoles({
695
- type: "fragment",
696
- id: fid,
697
- version,
698
- key,
699
- html: value,
700
- digest: textDigest(value)
701
- }, holeDigests(value, attrText)));
716
+ r[`seg:${key}`] = html(value, textDigest(value), holeDigests(value, attrText));
702
717
  scheduleSweep();
703
- if (meta.error) {
704
- emit({
705
- type: "error",
706
- id: fid,
707
- version,
708
- key,
709
- error: {
710
- message: String(meta.error && meta.error.message || meta.error)
711
- }
712
- });
713
- }
714
- if (!meta.revealGroup) {
715
- emit({
716
- type: "reveal",
717
- id: fid,
718
- version,
719
- keys: [key],
720
- waitForStyles: !!links.length
721
- });
722
- }
718
+ if (meta.error) r[`seg:${key}:error`] = {
719
+ message: String(meta.error && meta.error.message || meta.error)
720
+ };
721
+ if (!meta.revealGroup) r[`seg:${key}:reveal`] = true;
722
+ put(fid, r);
723
723
  },
724
724
  reveal(keys, meta = {}) {
725
725
  const byFrame = new Map();
@@ -730,38 +730,27 @@ function createFrameSink(write, frame, have, hooks) {
730
730
  if (!group) byFrame.set(fid, group = []);
731
731
  group.push(key);
732
732
  }
733
+ const gate = meta.fallback ? "fallback" : "reveal";
733
734
  for (const [fid, groupKeys] of byFrame) {
734
- let waitForStyles = false;
735
- for (const key of groupKeys) if (styledKeys.has(key)) waitForStyles = true;
736
- const chunk = {
737
- type: "reveal",
738
- id: fid,
739
- version,
740
- keys: groupKeys,
741
- waitForStyles
742
- };
743
- if (meta.fallback) chunk.fallback = true;
744
- emit(chunk);
735
+ const r = {};
736
+ for (const key of groupKeys) r[`seg:${key}:${gate}`] = true;
737
+ put(fid, r);
745
738
  }
746
739
  },
747
740
  asset(type, value) {
748
741
  if (type === "module") {
749
742
  needs("assets");
750
- emit({
751
- type: "assets",
752
- id,
753
- version,
754
- key: "",
755
- modules: [value]
743
+ put(id, {
744
+ "seg::assets": {
745
+ modules: [value]
746
+ }
756
747
  });
757
748
  } else if (type === "preload") {
758
749
  needs("assets");
759
- emit({
760
- type: "assets",
761
- id,
762
- version,
763
- key: "",
764
- preloads: [wirePreload(value)]
750
+ put(id, {
751
+ "seg::assets": {
752
+ preloads: [wirePreload(value)]
753
+ }
765
754
  });
766
755
  }
767
756
  },
@@ -769,64 +758,69 @@ function createFrameSink(write, frame, have, hooks) {
769
758
  if (closed) return;
770
759
  if (bindings.size && !swept) sweep();
771
760
  closed = true;
772
- const chunk = {
773
- type: "complete",
774
- id,
775
- version
776
- };
777
- if (bound) chunk.bound = bound;
778
- emit(chunk);
761
+ put(id, bound ? {
762
+ ":complete": true,
763
+ ":bound": bound
764
+ } : {
765
+ ":complete": true
766
+ });
767
+ flush();
779
768
  },
780
769
  error(errorId, error) {
781
- emit({
782
- type: "error",
783
- id,
784
- version,
785
- key: errorId,
786
- error
787
- });
770
+ putError(id, errorId, error);
788
771
  },
772
+ flush,
789
773
  slot(key, args) {
790
- emit({
791
- type: "slot",
792
- id,
793
- version,
794
- key,
795
- args
774
+ put(id, {
775
+ [`slot:${key}`]: {
776
+ kind: "slot",
777
+ args
778
+ }
796
779
  });
797
780
  },
798
- region(childId, html) {
781
+ region(childId, value) {
799
782
  needs("regions");
800
- emit({
801
- type: "html",
802
- id: childId,
803
- version,
804
- html
783
+ put(childId, {
784
+ "": {
785
+ kind: "html",
786
+ value
787
+ }
805
788
  });
806
789
  },
807
- hole(key, html) {
808
- const op = {
809
- type: "hole",
810
- key,
811
- html,
812
- digest: textDigest(html)
790
+ hole(key, source, rows) {
791
+ const record = {
792
+ kind: "html",
793
+ digest: textDigest(source)
794
+ };
795
+ const base = holeDigest.get(key);
796
+ if (rows && base && hooks && hooks.live) {
797
+ record.rows = rows;
798
+ record.base = base;
799
+ } else record.value = source;
800
+ withHoles(record, holeDigests(record.rows ? rows.r.map(r => r[1]).join("") : source, null));
801
+ const r = {
802
+ ["hole:" + key]: record
813
803
  };
814
- swept ? swept.ops.push(op) : emitOps([op]);
804
+ showing(r);
805
+ swept ? Object.assign(swept.r, r) : put(id, r);
815
806
  },
816
807
  attr(key, attrs, removed) {
817
- const op = {
818
- type: "attr",
819
- key,
820
- attrs,
808
+ const record = {
809
+ kind: "attrs",
810
+ value: attrs,
821
811
  digest: textDigest(attrs)
822
812
  };
823
- if (removed && removed.length) op.removed = removed;
824
- swept ? swept.ops.push(op) : emitOps([op]);
813
+ if (removed && removed.length) record.removed = removed;
814
+ const r = {
815
+ ["attr:" + key]: record
816
+ };
817
+ swept ? Object.assign(swept.r, r) : put(id, r);
825
818
  },
826
819
  attrBaseline(key, text) {
827
820
  attrText.set(key, text);
828
821
  },
829
822
  openBinding(key, b) {
823
+ if (/^lha?:/.test(key)) needs("wire");
830
824
  bindings.set(key, b);
831
825
  },
832
826
  closeBinding(key) {
@@ -859,8 +853,9 @@ function renderServerComponent(component, options = {}) {
859
853
  if (ctx) {
860
854
  ctx.commit = sink.commit;
861
855
  ctx.commitEpoch = () => sink.epoch;
862
- ctx.liveHoles = createLiveHoles(sink);
863
- ctx.claims = CLAIMS_STREAM;
856
+ let unsettled = !!options.live;
857
+ if (!unsettled) ctx.unsettled = () => void (unsettled = true);
858
+ ctx.liveHoles = createLiveHoles(sink, false, () => !unsettled, ctx._errorScope);
864
859
  }
865
860
  return serverComponentScope(() => component(props));
866
861
  };
@@ -893,6 +888,7 @@ function frameStream(makeCode, options) {
893
888
  function finish() {
894
889
  if (ended) return;
895
890
  ended = true;
891
+ sink.flush();
896
892
  if (timer) clearTimeout(timer);
897
893
  if (upstream) upstream.removeEventListener("abort", onSignal);
898
894
  w.end && w.end();
@@ -913,19 +909,20 @@ function frameStream(makeCode, options) {
913
909
  finish();
914
910
  render.abort(upstream.reason);
915
911
  }
916
- const emit = chunk => {
917
- if (observation) observation.chunk(chunk);
918
- w.write(chunk);
919
- if (bounded && !flushed && chunk.type === "html" && chunk.id === id) {
912
+ const emit = message => {
913
+ if (observation) observation.chunk(message);
914
+ w.write(message);
915
+ if (bounded && !flushed && message.id === id && message.r && "" in message.r) {
920
916
  flushed = true;
921
917
  if (maxDurationMs > 0 && maxDurationMs !== Infinity) timer = setTimeout(() => cut("time"), maxDurationMs);
922
918
  }
923
919
  };
924
- const sink = createFrameSink(emit, frame, options.resume && options.resume.have, bounded ? {
925
- onYield() {
920
+ const sink = createFrameSink(emit, frame, options.resume && options.resume.have, {
921
+ live: options.live,
922
+ onYield: bounded ? () => {
926
923
  if (flushed && maxYields > 0 && ++yields >= maxYields) cut("yields");
927
- }
928
- } : undefined);
924
+ } : undefined
925
+ });
929
926
  if (options.live) sink.needs("wire");
930
927
  w.write({
931
928
  type: "start",
@@ -960,6 +957,7 @@ function frameStream(makeCode, options) {
960
957
  finish();
961
958
  }
962
959
  if (w[ANNOUNCE]) w[ANNOUNCE](sink.announce());
960
+ sink.flush();
963
961
  }
964
962
  return {
965
963
  pipe: stream,
@@ -981,56 +979,21 @@ function frameStream(makeCode, options) {
981
979
  function slotRange(occurrence) {
982
980
  return {
983
981
  t: `<!--slot:${occurrence}:start--><!--slot:${occurrence}:end-->`,
984
- $slot: true,
985
- $occurrence: occurrence
982
+ $slot: true
986
983
  };
987
984
  }
988
- const RANGE_KEYS = new Set(["t", "h", "p", "then", "length", "slice", "constructor", "toString", "valueOf", "toJSON"]);
989
- const NODE_KEYS = new Set(["t", "h", "p"]);
990
- function isRangeKey(key) {
991
- const c = key.charCodeAt(0);
992
- return c === 36 || c >= 48 && c <= 57 || RANGE_KEYS.has(key);
993
- }
994
- function slotProxy(range, occurrence, face, content, onData, needs) {
995
- return new Proxy(range, {
996
- get(target, key, receiver) {
997
- if (typeof key !== "string" || isRangeKey(key)) return Reflect.get(target, key, receiver);
998
- if (onData) onData = void onData();
999
- if (face !== SLOT_FACE_MARKUP) needs("bind");
1000
- return slotValue(occurrence, key, content ? content[key] : undefined, face);
1001
- }
1002
- });
985
+ function argBorderForm(value, needs) {
986
+ return toBorderForm(noteTraces(value, needs));
1003
987
  }
1004
- function argBorderForm(value, key, occurrence, needs) {
1005
- return toBorderForm(withoutStandIns(value, key, occurrence, needs));
1006
- }
1007
- function withoutStandIns(value, key, occurrence, needs) {
1008
- return rewriteTree(value, (v, path) => {
988
+ function noteTraces(value, needs) {
989
+ return rewriteTree(value, v => {
1009
990
  if (isContainerTraced(v)) {
1010
991
  needs("trace");
1011
992
  return v;
1012
993
  }
1013
- if (Object.getPrototypeOf(v) === Object.prototype && isSlotValue(v)) {
1014
- return undefined;
1015
- }
1016
994
  return DESCEND;
1017
995
  }, true);
1018
996
  }
1019
- function slotFace(range, content) {
1020
- if (content == null) return SLOT_FACE_DATA;
1021
- if (typeof content !== "object" || Array.isArray(content)) return SLOT_FACE_MARKUP;
1022
- if (isServerContent(content)) {
1023
- let data = false;
1024
- for (const key in content) {
1025
- if (!NODE_KEYS.has(key)) {
1026
- data = true;
1027
- break;
1028
- }
1029
- }
1030
- if (!data) return SLOT_FACE_MARKUP;
1031
- }
1032
- return SLOT_FACE_DATA;
1033
- }
1034
997
  const OCCURRENCE_UNSAFE = /[^A-Za-z0-9_.-]/g;
1035
998
  function encodeOccurrenceKey(key) {
1036
999
  return String(key).replace(OCCURRENCE_UNSAFE, c => {
@@ -1085,12 +1048,19 @@ function structuralArgsKey(raw) {
1085
1048
  };
1086
1049
  return walk(raw, true) ? out : undefined;
1087
1050
  }
1088
- function repeatKey(prop, raw) {
1089
- const keyed = keyedId(prop, raw);
1090
- if (keyed !== undefined) return keyed;
1091
- const structural = structuralArgsKey(raw);
1092
- return structural === undefined ? undefined : prop + "\0" + structural;
1051
+ function argDigest(value) {
1052
+ const t = typeof value;
1053
+ if (value == null || t !== "object" && t !== "function" && value === value) return value;
1054
+ if (isContainerTraced(value)) return value;
1055
+ try {
1056
+ const key = structuralArgsKey([value]);
1057
+ return key === undefined ? value : key;
1058
+ } catch (_) {
1059
+ return value;
1060
+ }
1093
1061
  }
1062
+ const PENDING_ARG = {};
1063
+ const noDigest = () => NaN;
1094
1064
  function isAsyncValue(v) {
1095
1065
  return !!v && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
1096
1066
  }
@@ -1106,6 +1076,37 @@ function tapFirstYield(iterable) {
1106
1076
  rest
1107
1077
  };
1108
1078
  }
1079
+ function packOccurrences(occs) {
1080
+ const out = [];
1081
+ let prop = "",
1082
+ a = -1,
1083
+ b = -1;
1084
+ const flush = () => a >= 0 && out.push(prop + "#" + (a === b ? a : a + "-" + b));
1085
+ for (const o of occs) {
1086
+ const m = /^(.*)#(\d+)$/.exec(o);
1087
+ if (m && m[1] === prop && +m[2] === b + 1 && a >= 0) {
1088
+ b++;
1089
+ continue;
1090
+ }
1091
+ flush();
1092
+ a = b = -1;
1093
+ if (m) {
1094
+ prop = m[1];
1095
+ a = b = +m[2];
1096
+ } else out.push(o);
1097
+ }
1098
+ flush();
1099
+ return out.join(" ");
1100
+ }
1101
+ function hasAsyncHoles(node, depth = 0) {
1102
+ if (!node || typeof node !== "object" || depth > 64) return false;
1103
+ if (Array.isArray(node)) {
1104
+ for (const n of node) if (hasAsyncHoles(n, depth + 1)) return true;
1105
+ return false;
1106
+ }
1107
+ if (node.h && node.h.length) return true;
1108
+ return false;
1109
+ }
1109
1110
  function suppressedFill(render) {
1110
1111
  const live = sharedConfig.context && sharedConfig.context.liveHoles;
1111
1112
  if (!live) return render();
@@ -1116,25 +1117,96 @@ function suppressedFill(render) {
1116
1117
  live.suppressed--;
1117
1118
  }
1118
1119
  }
1120
+ let parked = null;
1121
+ let parkedIds = 0;
1122
+ const PARKED = /<!--sc-n:(\d+)-->/;
1123
+ function park(render) {
1124
+ if (!parked) return render();
1125
+ const id = ++parkedIds;
1126
+ parked.set(id, {
1127
+ render,
1128
+ out: undefined
1129
+ });
1130
+ return {
1131
+ t: `<!--sc-n:${id}-->`
1132
+ };
1133
+ }
1134
+ const runParked = (entry, owner) => entry.out || (entry.out = entry.render(owner));
1135
+ function placeParked(node, nested, owner) {
1136
+ const out = expandParked(node, nested, owner);
1137
+ for (const entry of nested.values()) runParked(entry, owner);
1138
+ return out;
1139
+ }
1140
+ function expandParked(node, nested, owner) {
1141
+ if (Array.isArray(node)) {
1142
+ const out = node.map(n => expandParked(n, nested, owner));
1143
+ out.$slot = node.$slot;
1144
+ return out;
1145
+ }
1146
+ if (!node || node.t === undefined) return node;
1147
+ if (!node.h) return splitParked(node.t, nested, owner) || node;
1148
+ const out = [];
1149
+ node.t.forEach((t, i) => {
1150
+ out.push(splitParked(t, nested, owner) || {
1151
+ t
1152
+ });
1153
+ if (i < node.h.length) out.push({
1154
+ t: ["", ""],
1155
+ h: [node.h[i]],
1156
+ p: [node.p[i]]
1157
+ });
1158
+ });
1159
+ return out;
1160
+ }
1161
+ function splitParked(t, nested, owner) {
1162
+ const parts = typeof t === "string" ? t.split(PARKED) : [t];
1163
+ return parts.length > 1 ? parts.map((part, i) => i & 1 ? runParked(nested.get(+part), owner) : {
1164
+ t: part
1165
+ }) : undefined;
1166
+ }
1119
1167
  function createDocumentSlotProps(clientProps, frameId) {
1120
1168
  const counts = Object.create(null);
1169
+ let depsBatch = null;
1170
+ let depsN = 0;
1171
+ let wideSent = 0;
1172
+ const depsContext = sharedConfig.context;
1173
+ const noteDeps = (occurrence, reads, untracked) => {
1174
+ if (!depsContext || !depsContext.serialize || !depsContext.edges) return;
1175
+ const own = `sc-${frameId}-${occurrence}-`;
1176
+ const batch = () => {
1177
+ if (depsBatch) return depsBatch;
1178
+ queueMicrotask(() => {
1179
+ const b = {};
1180
+ for (const sid in depsBatch) b[sid] = packOccurrences(depsBatch[sid]);
1181
+ depsBatch = null;
1182
+ const wide = depsContext.edgeWide?.s || null;
1183
+ if (wide && wide.size > wideSent) {
1184
+ b["*"] = [...wide].slice(wideSent).join(" ");
1185
+ wideSent = wide.size;
1186
+ }
1187
+ if (depsN === 0 || Object.keys(b).length) depsContext.serialize(`sc:deps:${frameId}:${depsN++}`, b);
1188
+ });
1189
+ return depsBatch = Object.create(null);
1190
+ };
1191
+ const b = batch();
1192
+ if (reads) for (const sid of reads) if (!sid.startsWith(own)) (b[sid] ||= []).push(occurrence);
1193
+ if (untracked) (b["!"] ||= []).push(occurrence);
1194
+ };
1121
1195
  const getters = new Map();
1122
1196
  const repeats = new Map();
1123
- const range = (occurrence, content) => {
1197
+ const range = (occurrence, content, tail) => {
1124
1198
  const r = [{
1125
1199
  t: `<!--slot:${occurrence}:start-->`
1126
- }, content, {
1200
+ }, content, tail, {
1127
1201
  t: `<!--slot:${occurrence}:end-->`
1128
1202
  }];
1129
1203
  r.$slot = true;
1130
- r.$occurrence = occurrence;
1131
- const face = slotFace(r, content);
1132
- r.$face = face;
1133
- return slotProxy(r, occurrence, face, face === SLOT_FACE_DATA ? content : undefined, undefined, documentNeeds);
1204
+ return r;
1134
1205
  };
1135
1206
  const zoneOwner = getOwner ? getOwner() : null;
1136
- const scoped = (occurrence, render) => {
1207
+ const scoped = (occurrence, render, owner) => {
1137
1208
  const id = `sc-${frameId}-${occurrence}-`;
1209
+ if (owner) return runWithOwner(owner, () => runWithHydrationScope(id, render));
1138
1210
  const run = () => Hydration ? Hydration({
1139
1211
  id,
1140
1212
  get children() {
@@ -1154,18 +1226,13 @@ function createDocumentSlotProps(clientProps, frameId) {
1154
1226
  if (!fn) {
1155
1227
  fn = (...callArgs) => {
1156
1228
  if (callArgs.length === 0 || callArgs[0] === undefined) {
1157
- const rk = prop + "\0";
1158
- const repeat = repeats.get(rk);
1159
- if (repeat) return repeat;
1160
- const out = suppressedFill(() => scoped(prop, () => {
1229
+ return park(owner => suppressedFill(() => scoped(prop, () => {
1161
1230
  const value = clientProps[prop];
1162
1231
  return range(prop, typeof value === "function" ? value() : value);
1163
- }));
1164
- if (out.$face === SLOT_FACE_DATA) repeats.set(rk, out);
1165
- return out;
1232
+ }, owner)));
1166
1233
  }
1167
1234
  const raw = callArgs[0];
1168
- const rk = repeatKey(prop, raw);
1235
+ const rk = keyedId(prop, raw);
1169
1236
  const repeat = rk !== undefined && repeats.get(rk);
1170
1237
  if (repeat) return repeat;
1171
1238
  const occurrence = occurrenceId(prop, raw, counts);
@@ -1173,10 +1240,10 @@ function createDocumentSlotProps(clientProps, frameId) {
1173
1240
  if (typeof slot !== "function") return range(occurrence, undefined);
1174
1241
  const context = sharedConfig.context;
1175
1242
  const recordKey = `sc:slot:${frameId}:${occurrence}`;
1243
+ const deferred = !!parked;
1176
1244
  let settleRecord;
1177
- if (context && context.async) {
1178
- context.serialize(recordKey, new Promise(resolve => settleRecord = resolve));
1179
- }
1245
+ const declare = () => context && context.async && context.serialize(recordKey, new Promise(resolve => settleRecord = resolve));
1246
+ deferred || declare();
1180
1247
  try {
1181
1248
  const resolved = {};
1182
1249
  const liveArgs = sharedConfig.context && sharedConfig.context.live && sharedConfig.context.live.args;
@@ -1184,6 +1251,7 @@ function createDocumentSlotProps(clientProps, frameId) {
1184
1251
  const evals = {};
1185
1252
  const states = {};
1186
1253
  const minted = {};
1254
+ const nestedOf = {};
1187
1255
  for (const key of Object.keys(raw)) {
1188
1256
  if (key === "$key") continue;
1189
1257
  const desc = Object.getOwnPropertyDescriptor(raw, key);
@@ -1202,6 +1270,8 @@ function createDocumentSlotProps(clientProps, frameId) {
1202
1270
  if (evaluate) {
1203
1271
  evals[key] = evaluate;
1204
1272
  const stampBefore = scopeStamp();
1273
+ const outer = parked;
1274
+ const nested = nestedOf[key] = parked = new Map();
1205
1275
  try {
1206
1276
  value = evaluate();
1207
1277
  states[key] = {
@@ -1209,6 +1279,9 @@ function createDocumentSlotProps(clientProps, frameId) {
1209
1279
  last: value
1210
1280
  };
1211
1281
  } catch (err) {
1282
+ parked = outer;
1283
+ for (const entry of nested.values()) runParked(entry);
1284
+ nested.clear();
1212
1285
  const blocked = ssrHandleError && ssrHandleError(err);
1213
1286
  if (!blocked) throw err;
1214
1287
  const state = states[key] = {
@@ -1221,6 +1294,7 @@ function createDocumentSlotProps(clientProps, frameId) {
1221
1294
  if (liveArgs) liveArgs.commit();
1222
1295
  });
1223
1296
  }
1297
+ parked = outer;
1224
1298
  if (scopeStamp() !== stampBefore) minted[key] = true;
1225
1299
  }
1226
1300
  vals[key] = value;
@@ -1237,6 +1311,7 @@ function createDocumentSlotProps(clientProps, frameId) {
1237
1311
  key,
1238
1312
  childId,
1239
1313
  value,
1314
+ nested: nestedOf[key],
1240
1315
  used: false,
1241
1316
  locked: false
1242
1317
  };
@@ -1247,7 +1322,7 @@ function createDocumentSlotProps(clientProps, frameId) {
1247
1322
  region.used = true;
1248
1323
  return [{
1249
1324
  t: frameElementOpen(childId)
1250
- }, value, {
1325
+ }, region.nested && region.nested.size ? placeParked(value, region.nested, getOwner()) : value, {
1251
1326
  t: FRAME_ELEMENT_CLOSE
1252
1327
  }];
1253
1328
  };
@@ -1268,49 +1343,67 @@ function createDocumentSlotProps(clientProps, frameId) {
1268
1343
  configurable: true
1269
1344
  });
1270
1345
  } else {
1271
- resolved[key] = vals[key] = withoutStandIns(value, key, occurrence, documentNeeds);
1346
+ resolved[key] = vals[key] = noteTraces(value, documentNeeds);
1272
1347
  }
1273
1348
  }
1274
- const out = suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved))));
1275
- const unused = regions.filter(r => !r.used);
1276
- if (context) {
1277
- const args = {};
1278
- for (const key of Object.keys(vals)) {
1279
- const value = vals[key];
1280
- const region = regions.find(r => r.key === key);
1281
- if (region) {
1282
- args[key] = {
1283
- $frame: region.childId
1284
- };
1285
- continue;
1286
- }
1287
- if (!isContainerTraced(value) && isServerContent(value)) continue;
1288
- args[key] = argBorderForm(value, key, occurrence, documentNeeds);
1289
- }
1290
- settleRecord ? settleRecord({
1291
- ...args
1292
- }) : context.serialize(recordKey, {
1293
- ...args
1294
- });
1295
- for (const region of unused) {
1349
+ for (const key in nestedOf) if (!regions.some(r => r.key === key)) for (const entry of nestedOf[key].values()) runParked(entry);
1350
+ const flip = () => {
1351
+ if (flip.done || !context) return;
1352
+ flip.done = true;
1353
+ for (const region of regions) {
1354
+ if (region.used) continue;
1296
1355
  region.locked = true;
1297
- context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(context, region.value));
1356
+ context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(context, region.nested && region.nested.size ? placeParked(region.value, region.nested) : region.value));
1298
1357
  }
1299
- if (liveArgs) {
1300
- for (const key of Object.keys(evals)) {
1301
- if (regions.some(r => r.key === key)) continue;
1302
- if (minted[key]) continue;
1303
- const ledgerKey = `${frameId}:${occurrence}:${key}`;
1304
- openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
1305
- args[key] = argBorderForm(value, key, occurrence, documentNeeds);
1306
- liveArgs.slot(frameId, occurrence, {
1307
- ...args
1308
- });
1358
+ };
1359
+ flip.$lhSkip = true;
1360
+ const finish = owner => {
1361
+ if (deferred) declare();
1362
+ try {
1363
+ const tracked = trackFillReads(() => suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved), flip), owner)));
1364
+ const out = tracked.result;
1365
+ noteDeps(occurrence, tracked.reads, tracked.untracked || hasAsyncHoles(out));
1366
+ if (context) {
1367
+ const args = {};
1368
+ for (const key of Object.keys(vals)) {
1369
+ const value = vals[key];
1370
+ const region = regions.find(r => r.key === key);
1371
+ if (region) {
1372
+ args[key] = {
1373
+ $frame: region.childId
1374
+ };
1375
+ continue;
1376
+ }
1377
+ if (!isContainerTraced(value) && isServerContent(value)) continue;
1378
+ args[key] = argBorderForm(value, documentNeeds);
1379
+ }
1380
+ settleRecord ? settleRecord({
1381
+ ...args
1382
+ }) : context.serialize(recordKey, {
1383
+ ...args
1309
1384
  });
1385
+ if (liveArgs) {
1386
+ for (const key of Object.keys(evals)) {
1387
+ if (regions.some(r => r.key === key)) continue;
1388
+ if (minted[key]) continue;
1389
+ const ledgerKey = `${frameId}:${occurrence}:${key}`;
1390
+ openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
1391
+ args[key] = argBorderForm(value, documentNeeds);
1392
+ liveArgs.slot(frameId, occurrence, {
1393
+ ...args
1394
+ });
1395
+ });
1396
+ }
1397
+ }
1310
1398
  }
1399
+ return out;
1400
+ } catch (error) {
1401
+ settleRecord && settleRecord(undefined);
1402
+ throw error;
1311
1403
  }
1312
- }
1313
- if (rk !== undefined && (rk === occurrence || out.$face === SLOT_FACE_DATA)) repeats.has(rk) || repeats.set(rk, out);
1404
+ };
1405
+ const out = park(finish);
1406
+ if (rk !== undefined && rk === occurrence) repeats.has(rk) || repeats.set(rk, out);
1314
1407
  return out;
1315
1408
  } catch (error) {
1316
1409
  settleRecord && settleRecord(undefined);
@@ -1326,9 +1419,10 @@ function createDocumentSlotProps(clientProps, frameId) {
1326
1419
  }
1327
1420
  const FRAME_TAG = "solid-frame";
1328
1421
  const FRAME_ID_ATTR = "data-fid";
1329
- function frameElementOpen(id) {
1422
+ const FRAME_ARGS_ATTR = "data-fa";
1423
+ function frameElementOpen(id, args) {
1330
1424
  const escaped = sharedConfig.context ? sharedConfig.context.escape(String(id), true) : String(id);
1331
- return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}" style="display:contents">`;
1425
+ return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}"${args ? ` ${FRAME_ARGS_ATTR}="${args}"` : ""} style="display:contents">`;
1332
1426
  }
1333
1427
  const DOCUMENT_SITES = Symbol();
1334
1428
  function contextSites(ctx) {
@@ -1380,6 +1474,7 @@ function armDocumentLiveHoles(ctx) {
1380
1474
  if (live.holes) {
1381
1475
  ctx.commit = live.commit;
1382
1476
  ctx.commitEpoch = live.commitEpoch;
1477
+ ctx.unsettled = live.unsettled;
1383
1478
  }
1384
1479
  return;
1385
1480
  }
@@ -1388,6 +1483,7 @@ function armDocumentLiveHoles(ctx) {
1388
1483
  if (live) live.holes = null;
1389
1484
  return;
1390
1485
  }
1486
+ let unsettled = false;
1391
1487
  const bindings = new Map();
1392
1488
  let epoch = 0;
1393
1489
  let sweepScheduled = false;
@@ -1395,7 +1491,7 @@ function armDocumentLiveHoles(ctx) {
1395
1491
  let swept = null;
1396
1492
  const sweep = () => {
1397
1493
  epoch++;
1398
- const ops = swept = [];
1494
+ const r = swept = {};
1399
1495
  try {
1400
1496
  for (const b of [...bindings.values()]) {
1401
1497
  try {
@@ -1406,12 +1502,8 @@ function armDocumentLiveHoles(ctx) {
1406
1502
  } finally {
1407
1503
  swept = null;
1408
1504
  }
1409
- pushOps(ops);
1410
- };
1411
- const pushOps = ops => {
1412
- if (ops.length === 1) push(ops[0]);else if (ops.length) push({
1413
- type: "ops",
1414
- ops
1505
+ for (const _ in r) return push({
1506
+ r
1415
1507
  });
1416
1508
  };
1417
1509
  const scheduleSweep = () => {
@@ -1431,49 +1523,57 @@ function armDocumentLiveHoles(ctx) {
1431
1523
  closed = true;
1432
1524
  }
1433
1525
  }));
1434
- const push = op => {
1435
- if (!closed) channel.enqueue(op);
1526
+ const push = batch => {
1527
+ if (!closed) channel.enqueue(batch);
1436
1528
  };
1529
+ const write = r => swept ? Object.assign(swept, r) : push({
1530
+ r
1531
+ });
1437
1532
  ctx.liveHoles = live.holes = createLiveHoles({
1438
1533
  openBinding(key, b) {
1534
+ documentNeeds("wire");
1439
1535
  bindings.set(key, b);
1440
1536
  },
1441
1537
  closeBinding(key) {
1442
1538
  bindings.delete(key);
1443
1539
  },
1444
- hole(key, html) {
1445
- const op = {
1446
- type: "hole",
1447
- key,
1448
- html,
1449
- digest: textDigest(html)
1450
- };
1451
- swept ? swept.push(op) : pushOps([op]);
1540
+ hole(key, value) {
1541
+ write({
1542
+ ["hole:" + key]: {
1543
+ kind: "html",
1544
+ value,
1545
+ digest: textDigest(value)
1546
+ }
1547
+ });
1452
1548
  },
1453
- attr(key, attrs, removed) {
1454
- const op = {
1455
- type: "attr",
1456
- key,
1457
- attrs,
1458
- digest: textDigest(attrs)
1549
+ attr(key, value, removed) {
1550
+ const record = {
1551
+ kind: "attrs",
1552
+ value,
1553
+ digest: textDigest(value)
1459
1554
  };
1460
- if (removed && removed.length) op.removed = removed;
1461
- swept ? swept.push(op) : pushOps([op]);
1555
+ if (removed && removed.length) record.removed = removed;
1556
+ write({
1557
+ ["attr:" + key]: record
1558
+ });
1462
1559
  },
1463
1560
  error(key, error) {
1464
1561
  push({
1465
- type: "error",
1466
- key,
1467
- error
1562
+ r: {
1563
+ [`hole:${key}:error`]: error
1564
+ }
1468
1565
  });
1469
1566
  },
1470
1567
  commit: scheduleSweep,
1471
1568
  get epoch() {
1472
1569
  return epoch;
1473
1570
  }
1474
- }, true);
1571
+ }, true, () => !unsettled, ctx._errorScope);
1475
1572
  ctx.commit = live.commit = scheduleSweep;
1476
1573
  ctx.commitEpoch = live.commitEpoch = () => epoch;
1574
+ ctx.unsettled = live.unsettled = () => {
1575
+ unsettled = true;
1576
+ };
1477
1577
  live.args = {
1478
1578
  openBinding(key, b) {
1479
1579
  bindings.set(key, b);
@@ -1483,19 +1583,23 @@ function armDocumentLiveHoles(ctx) {
1483
1583
  },
1484
1584
  slot(fid, occurrence, args) {
1485
1585
  push({
1486
- type: "slot",
1487
- fid,
1488
- key: occurrence,
1489
- args
1586
+ r: {
1587
+ [`slot:${occurrence}`]: {
1588
+ kind: "slot",
1589
+ args
1590
+ }
1591
+ },
1592
+ fid
1490
1593
  });
1491
1594
  },
1492
1595
  commit: scheduleSweep
1493
1596
  };
1494
1597
  live.error = (fid, error) => {
1495
1598
  push({
1496
- type: "error",
1497
- fid,
1498
- error
1599
+ r: {
1600
+ ":error": error
1601
+ },
1602
+ fid
1499
1603
  });
1500
1604
  };
1501
1605
  live.end = () => {
@@ -1512,17 +1616,17 @@ function frameTransformDirectResult(value, {
1512
1616
  }) {
1513
1617
  if (typeof value !== "function") return value;
1514
1618
  const component = value;
1619
+ const address = frameAddress(id, args);
1515
1620
  const wrapped = props => {
1516
1621
  const siteId = documentSiteId(id);
1517
1622
  return [{
1518
- t: frameElementOpen(siteId)
1623
+ t: frameElementOpen(siteId, address.slice(id.length + 1))
1519
1624
  },
1520
1625
  serverOwned(() => {
1521
1626
  const page = sharedConfig.context;
1522
1627
  armDocumentLiveHoles(page);
1523
1628
  if (tierUrls && page && page.live && !page.live.tierUrls) page.live.tierUrls = tierUrls;
1524
1629
  const ctx = Object.create(page);
1525
- ctx.claims = CLAIMS_DOCUMENT;
1526
1630
  ctx.frameId = siteId;
1527
1631
  sharedConfig.context = ctx;
1528
1632
  try {
@@ -1539,7 +1643,7 @@ function frameTransformDirectResult(value, {
1539
1643
  };
1540
1644
  wrapped[SERVER_COMPONENT] = id;
1541
1645
  wrapped[SERVER_COMPONENT_SOURCE] = component;
1542
- wrapped[SERVER_COMPONENT_ADDRESS] = frameAddress(id, args);
1646
+ wrapped[SERVER_COMPONENT_ADDRESS] = address;
1543
1647
  return wrapped;
1544
1648
  }
1545
1649
  function resolveRegionHtml(ctx, node) {
@@ -1642,6 +1746,15 @@ function createSlotProps(sink, frame) {
1642
1746
  const counts = Object.create(null);
1643
1747
  const getters = new Map();
1644
1748
  const repeats = new Map();
1749
+ let pass = null;
1750
+ let passRepeats = null;
1751
+ const recs = new Map();
1752
+ const forget = occurrence => {
1753
+ const rec = recs.get(occurrence);
1754
+ if (!rec) return;
1755
+ recs.delete(occurrence);
1756
+ for (const key in rec.vals) sink.closeBinding(`${occurrence}:${key}`);
1757
+ };
1645
1758
  const needs = sink.needs || (() => {});
1646
1759
  return new Proxy(Object.create(null), {
1647
1760
  has() {
@@ -1654,25 +1767,38 @@ function createSlotProps(sink, frame) {
1654
1767
  if (!fn) {
1655
1768
  fn = (...callArgs) => {
1656
1769
  if (callArgs.length === 0 || callArgs[0] === undefined) {
1657
- return slotProxy(slotRange(prop), prop, SLOT_FACE_STREAM, undefined, undefined, needs);
1770
+ return slotRange(prop);
1658
1771
  }
1659
- const rk = repeatKey(prop, callArgs[0]);
1660
- const repeat = rk !== undefined && repeats.get(rk);
1661
- if (repeat) return repeat;
1662
1772
  const live = sharedConfig.context && sharedConfig.context.liveHoles;
1663
- if (live) {
1664
- if (live.sweeping) {
1665
- live.gateHit = true;
1666
- return {
1667
- t: "",
1668
- $slot: true
1669
- };
1670
- }
1671
- live.recordStamp++;
1773
+ const sweeping = !!live && live.sweeping;
1774
+ let rmap = repeats;
1775
+ if (sweeping) {
1776
+ if (pass !== live.visit) passRepeats = new Map();
1777
+ pass = live.visit;
1778
+ rmap = passRepeats;
1779
+ }
1780
+ const rk = keyedId(prop, callArgs[0]);
1781
+ const repeat = rk !== undefined && rmap.get(rk);
1782
+ if (repeat) return repeat;
1783
+ if (sweeping && !live.scope) {
1784
+ live.gateHit = true;
1785
+ return {
1786
+ t: "",
1787
+ $slot: true
1788
+ };
1672
1789
  }
1673
1790
  const raw = callArgs[0];
1674
- const occurrence = occurrenceId(prop, raw, counts);
1791
+ let occurrence = keyedId(prop, raw);
1792
+ if (occurrence === undefined) {
1793
+ const positional = sweeping ? undefined : occurrenceId(prop, raw, counts);
1794
+ occurrence = live ? live.slotId(prop, positional) : positional;
1795
+ }
1796
+ if (sweeping && live.dry) return slotRange(occurrence);
1797
+ const prev = recs.get(occurrence);
1798
+ let changed = !prev;
1799
+ const digest = live && live.scope ? argDigest : noDigest;
1675
1800
  const args = {};
1801
+ const vals = {};
1676
1802
  const opened = [];
1677
1803
  for (const key of Object.keys(raw)) {
1678
1804
  if (key === "$key") continue;
@@ -1688,6 +1814,7 @@ function createSlotProps(sink, frame) {
1688
1814
  let evaluate = null;
1689
1815
  let value;
1690
1816
  let state = null;
1817
+ let pending = false;
1691
1818
  const stampBefore = scopeStamp();
1692
1819
  try {
1693
1820
  if (desc.get) {
@@ -1709,6 +1836,7 @@ function createSlotProps(sink, frame) {
1709
1836
  settled: false,
1710
1837
  last: undefined
1711
1838
  };
1839
+ pending = true;
1712
1840
  const pendingState = state;
1713
1841
  value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
1714
1842
  pendingState.settled = true;
@@ -1720,6 +1848,7 @@ function createSlotProps(sink, frame) {
1720
1848
  const t = typeof value;
1721
1849
  if (value == null || t === "string" || t === "number" || t === "boolean") {
1722
1850
  args[key] = value;
1851
+ vals[key] = digest(value);
1723
1852
  if (evaluate) state = {
1724
1853
  settled: true,
1725
1854
  last: value
@@ -1729,21 +1858,27 @@ function createSlotProps(sink, frame) {
1729
1858
  if (resolved.h.length) {
1730
1859
  throw new Error("Async server content in a slot arg needs a boundary (arg '" + key + "' of " + occurrence + "). Wrap the async read in a <Suspense>, or move it above the slot.");
1731
1860
  }
1732
- sink.region(childId, resolved.t[0]);
1861
+ vals[key] = "<" + resolved.t[0];
1862
+ if (!prev || prev.vals[key] !== vals[key]) sink.region(childId, resolved.t[0]);
1733
1863
  args[key] = {
1734
1864
  $frame: childId
1735
1865
  };
1736
1866
  } else {
1737
- const ref = `arg:${occurrence}:${key}`;
1738
- ctx.serialize(ref, argBorderForm(value, key, occurrence, needs));
1739
- args[key] = {
1740
- $ref: ref
1741
- };
1867
+ vals[key] = pending ? PENDING_ARG : digest(value);
1868
+ if (prev && prev.vals[key] === vals[key]) args[key] = prev.args[key];else {
1869
+ const ref = prev ? `arg:${occurrence}:${key}@${sink.nextArgRef(`${occurrence}:${key}`)}` : `arg:${occurrence}:${key}`;
1870
+ if (prev) sink.mintRef(ref);
1871
+ ctx.serialize(ref, argBorderForm(value, needs));
1872
+ args[key] = {
1873
+ $ref: ref
1874
+ };
1875
+ }
1742
1876
  if (evaluate && !state) state = {
1743
1877
  settled: true,
1744
1878
  last: value
1745
1879
  };
1746
1880
  }
1881
+ if (prev && prev.vals[key] !== vals[key]) changed = true;
1747
1882
  if (evaluate && state && !mintedEval) opened.push({
1748
1883
  key,
1749
1884
  evaluate,
@@ -1753,9 +1888,18 @@ function createSlotProps(sink, frame) {
1753
1888
  ctx.registerFragment = origRegister;
1754
1889
  }
1755
1890
  }
1756
- sink.slot(occurrence, {
1757
- ...args
1758
- });
1891
+ if (prev) for (const key in prev.vals) if (!(key in vals)) changed = true;
1892
+ const rec = changed ? {
1893
+ args,
1894
+ vals
1895
+ } : prev;
1896
+ if (changed) {
1897
+ recs.set(occurrence, rec);
1898
+ sink.slot(occurrence, {
1899
+ ...args
1900
+ });
1901
+ }
1902
+ if (live && live.visit) live.seen(occurrence, () => recs.get(occurrence) === rec && forget(occurrence));
1759
1903
  const ctx = sharedConfig.context;
1760
1904
  for (const b of opened) {
1761
1905
  const key = b.key;
@@ -1763,23 +1907,23 @@ function createSlotProps(sink, frame) {
1763
1907
  openArgBinding(sink, ledgerKey, occurrence, key, b.evaluate, b.state, value => {
1764
1908
  const t = typeof value;
1765
1909
  if (value == null || t === "string" || t === "number" || t === "boolean") {
1766
- args[key] = value;
1910
+ rec.args[key] = value;
1767
1911
  } else {
1768
1912
  const ref = `arg:${occurrence}:${key}@${sink.nextArgRef(ledgerKey)}`;
1769
1913
  sink.mintRef(ref);
1770
- ctx.serialize(ref, argBorderForm(value, key, occurrence, needs));
1771
- args[key] = {
1914
+ ctx.serialize(ref, argBorderForm(value, needs));
1915
+ rec.args[key] = {
1772
1916
  $ref: ref
1773
1917
  };
1774
1918
  }
1919
+ rec.vals[key] = digest(value);
1775
1920
  sink.slot(occurrence, {
1776
- ...args
1921
+ ...rec.args
1777
1922
  });
1778
1923
  });
1779
1924
  }
1780
- const keyed = rk === occurrence;
1781
- const out = slotProxy(slotRange(occurrence), occurrence, SLOT_FACE_STREAM, undefined, rk === undefined || keyed ? undefined : () => repeats.has(rk) || repeats.set(rk, out), needs);
1782
- if (keyed) repeats.set(rk, out);
1925
+ const out = slotRange(occurrence);
1926
+ if (rk !== undefined && rk === occurrence) rmap.set(rk, out);
1783
1927
  return out;
1784
1928
  };
1785
1929
  fn.$lhSkip = true;
@@ -1844,11 +1988,11 @@ function serverComponentResponse(component, options = {}, init = {}) {
1844
1988
  teardown.abort();
1845
1989
  });
1846
1990
  stream.pipe({
1847
- write(chunk) {
1848
- if (chunk.type === "error" && !chunk.key) failed = true;
1991
+ write(message) {
1992
+ if (message.r && ":error" in message.r) failed = true;
1849
1993
  if (closed) return;
1850
1994
  try {
1851
- controller.enqueue(frame(JSON.stringify(chunk)));
1995
+ controller.enqueue(frame(JSON.stringify(message)));
1852
1996
  } catch (_) {
1853
1997
  closed = true;
1854
1998
  }
@@ -2006,10 +2150,10 @@ function frameFlightResponse({
2006
2150
  let closed = false;
2007
2151
  const body = new ReadableStream({
2008
2152
  async start(controller) {
2009
- const write = chunk => {
2153
+ const write = message => {
2010
2154
  if (closed) return;
2011
2155
  try {
2012
- controller.enqueue(createChunk(JSON.stringify(chunk)));
2156
+ controller.enqueue(createChunk(JSON.stringify(message)));
2013
2157
  } catch (_) {
2014
2158
  closed = true;
2015
2159
  }