@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 { OBSERVE, DEV, getOwner, NoHydration, runWithOwner, createMemo, Hydration, createOwner } from 'solid-js';
3
- import { isResponseEnvelope, renderToStream, createLiveHoles, CLAIMS_STREAM, CLAIMS_DOCUMENT, SLOT_FACE_DATA, SLOT_FACE_MARKUP, slotValue, SLOT_FACE_STREAM, isSlotValue, SLOT_VALUE } from '@solidjs/web';
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';
@@ -186,15 +186,6 @@ const ContainerTracePlugin = {
186
186
  }
187
187
  };
188
188
 
189
- function emitFinding(finding, subject = getOwner()) {
190
- if (OBSERVE === undefined) return;
191
- const entry = OBSERVE.diagnostics.emit(finding, subject);
192
- if (DEV !== undefined) DEV.report(entry);
193
- }
194
- function devCheck(finding, subject) {
195
- emitFinding(finding, subject);
196
- }
197
-
198
189
  setContainerTraceStreamMint(iterable => {
199
190
  const stream = createStream();
200
191
  (async () => {
@@ -216,14 +207,16 @@ function resolveSerializerPlugins(customPlugins) {
216
207
  }
217
208
  const jsonCodecDisabledFeatures = () => Feature.RegExp;
218
209
  const JSON_CODEC_DEPTH_LIMIT = 64;
219
- function resolveCodecOptions({
220
- plugins,
221
- disabledFeatures,
222
- depthLimit,
223
- serializeErrorStacks
224
- } = {}) {
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;
225
218
  return {
226
- plugins: resolveSerializerPlugins(plugins),
219
+ plugins: options[RESOLVED_PLUGINS] || resolveSerializerPlugins(plugins),
227
220
  disabledFeatures: disabledFeatures === undefined ? jsonCodecDisabledFeatures() : disabledFeatures,
228
221
  depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit,
229
222
  serializeErrorStacks
@@ -303,8 +296,17 @@ const RECORDS = Symbol.for("@solidjs/signals/observe/records");
303
296
  function records() {
304
297
  return globalThis[RECORDS];
305
298
  }
306
- function frameCensus(event, type, own) {
307
- event.chunks++;
299
+ function frameRecordCensus(event, message, own) {
300
+ const r = message.r;
301
+ let counted = !r;
302
+ for (const key in r) {
303
+ if (key === ":complete" || key === ":bound") continue;
304
+ counted = true;
305
+ countEvent(event, key === "" ? "html" : key.endsWith(":error") ? "error" : key.startsWith("slot:") ? "slot" : key.startsWith("seg:") && r[key] && r[key].kind === "html" ? "fragment" : key, own);
306
+ }
307
+ if (counted) event.chunks++;
308
+ }
309
+ function countEvent(event, type, own) {
308
310
  switch (type) {
309
311
  case "html":
310
312
  if (!own) event.regions++;else if (event.shellMs === undefined) event.shellMs = performance.now() - event.at;
@@ -339,9 +341,8 @@ function observeFrame(frame) {
339
341
  };
340
342
  let settled = false;
341
343
  return {
342
- chunk(chunk) {
343
- if (chunk.type === "complete") return;
344
- frameCensus(event, chunk.type, chunk.id === frame.id);
344
+ chunk(message) {
345
+ frameRecordCensus(event, message, message.id === frame.id);
345
346
  },
346
347
  settle(outcome, error) {
347
348
  if (settled) return;
@@ -494,14 +495,41 @@ function createFrameSink(write, frame, have, hooks) {
494
495
  } = frame;
495
496
  const tiers = new Set();
496
497
  let staged = [];
497
- const emit = chunk => {
498
- if (swept) swept.emitted = true;
498
+ const send = message => {
499
499
  if (staged.length) {
500
- chunk.tiers = staged;
500
+ message.tiers = staged;
501
501
  staged = [];
502
502
  }
503
- write(chunk);
503
+ write(message);
504
+ };
505
+ let queue = [];
506
+ let open = null;
507
+ let scheduled = false;
508
+ const flush = () => {
509
+ scheduled = false;
510
+ open = null;
511
+ const out = queue;
512
+ queue = [];
513
+ for (const message of out) send(message);
504
514
  };
515
+ const put = (fid, r) => {
516
+ if (swept) swept.emitted = true;
517
+ showing(r);
518
+ let merge = open && open.id === fid;
519
+ if (merge) for (const key in r) if (key in open.r) merge = false;
520
+ if (merge) Object.assign(open.r, r);else queue.push(open = {
521
+ id: fid,
522
+ version,
523
+ r
524
+ });
525
+ if (!scheduled) {
526
+ scheduled = true;
527
+ queueMicrotask(flush);
528
+ }
529
+ };
530
+ const putError = (fid, key, error) => put(fid, {
531
+ [key ? `${/^lha?:/.test(key) ? "hole" : "seg"}:${key}:error` : ":error"]: error
532
+ });
505
533
  const needs = name => {
506
534
  if (!tiers.has(name)) {
507
535
  tiers.add(name);
@@ -511,36 +539,44 @@ function createFrameSink(write, frame, have, hooks) {
511
539
  let conditional = false;
512
540
  const skipped = new Set();
513
541
  const attrText = new Map();
514
- const emitDiffering = html => {
515
- for (const m of html.matchAll(HOLE_RANGE)) {
542
+ const holeDigest = new Map();
543
+ if (have) for (const key in have) key.startsWith("lh:") && holeDigest.set(key, have[key]);
544
+ function showing(r) {
545
+ if ("" in r) holeDigest.clear();
546
+ for (const k in r) {
547
+ const record = r[k];
548
+ if (k.startsWith("hole:lh:") && !k.endsWith(":error")) holeDigest.set(k.slice(5), record.digest);
549
+ if (record) for (const key in record.holes) key.startsWith("lh:") && holeDigest.set(key, record.holes[key]);
550
+ }
551
+ }
552
+ const html = (value, digest, holes) => withHoles({
553
+ kind: "html",
554
+ value,
555
+ digest
556
+ }, holes);
557
+ const emitDiffering = source => {
558
+ for (const m of source.matchAll(HOLE_RANGE)) {
516
559
  const key = "lh:" + m[1];
517
560
  const digest = textDigest(stripHoleMarkers(m[2]));
518
561
  if (have[key] === digest) continue;
519
- emit(withHoles({
520
- type: "hole",
521
- id,
522
- version,
523
- key,
524
- html: m[2],
525
- digest
526
- }, holeDigests(m[2], null)));
562
+ put(id, {
563
+ ["hole:" + key]: html(m[2], digest, holeDigests(m[2], null))
564
+ });
527
565
  }
528
- for (const m of html.matchAll(ATTR_ADDRESS)) {
566
+ for (const m of source.matchAll(ATTR_ADDRESS)) {
529
567
  const text = attrText.get("lha:" + m[1]);
530
568
  if (text === undefined) continue;
531
569
  const digest = textDigest(text);
532
570
  if (have["lha:" + m[1]] === digest) continue;
533
- emit({
534
- type: "attr",
535
- id,
536
- version,
537
- key: m[1],
538
- attrs: text,
539
- digest
571
+ put(id, {
572
+ ["attr:" + m[1]]: {
573
+ kind: "attrs",
574
+ value: text,
575
+ digest
576
+ }
540
577
  });
541
578
  }
542
579
  };
543
- const styledKeys = new Set();
544
580
  const bindings = new Map();
545
581
  const sweepMinted = new Set();
546
582
  const argRefVersions = new Map();
@@ -551,34 +587,27 @@ function createFrameSink(write, frame, have, hooks) {
551
587
  const sweep = () => {
552
588
  epoch++;
553
589
  const pass = swept = {
554
- ops: [],
590
+ r: {},
555
591
  emitted: false
556
592
  };
557
593
  try {
558
- for (const b of [...bindings.values()]) {
594
+ for (const [key, b] of [...bindings]) {
595
+ if (bindings.get(key) !== b) continue;
559
596
  try {
560
597
  b.sweep();
561
598
  } catch (_) {
562
599
  }
563
600
  }
564
- emitOps(pass.ops);
601
+ for (const _ in pass.r) {
602
+ put(id, pass.r);
603
+ break;
604
+ }
605
+ flush();
565
606
  if (pass.emitted && hooks && hooks.onYield) hooks.onYield();
566
607
  } finally {
567
608
  swept = null;
568
609
  }
569
610
  };
570
- const emitOps = ops => {
571
- if (ops.length === 1) emit(Object.assign({
572
- type: ops[0].type,
573
- id,
574
- version
575
- }, ops[0]));else if (ops.length) emit({
576
- type: "ops",
577
- id,
578
- version,
579
- ops
580
- });
581
- };
582
611
  const scheduleSweep = () => {
583
612
  if (closed || sweepScheduled || !bindings.size) return;
584
613
  sweepScheduled = true;
@@ -593,52 +622,47 @@ function createFrameSink(write, frame, have, hooks) {
593
622
  tagRegion(key, childId) {
594
623
  if (!regionKeys.has(key)) regionKeys.set(key, childId);
595
624
  },
596
- shell(html, meta = {}) {
597
- const digest = textDigest(frameSkeleton(html));
625
+ shell(source, meta = {}) {
626
+ const digest = textDigest(frameSkeleton(source));
598
627
  if (have && have[""] === digest) {
599
628
  conditional = true;
600
- emitDiffering(html);
629
+ emitDiffering(source);
601
630
  return;
602
631
  }
603
632
  if (meta.preloads && meta.preloads.size || meta.preloadLinks) {
604
- const chunk = {
605
- type: "assets",
606
- id,
607
- version,
608
- key: ""
609
- };
633
+ const record = {};
610
634
  if (meta.preloads && meta.preloads.size) {
611
635
  const styles = [];
612
636
  const modules = [];
613
637
  for (const url of meta.preloads) {
614
638
  (url.endsWith(".css") ? styles : modules).push(url);
615
639
  }
616
- if (styles.length) chunk.styles = styles;
617
- if (modules.length) chunk.modules = modules;
640
+ if (styles.length) record.styles = styles;
641
+ if (modules.length) record.modules = modules;
618
642
  }
619
643
  if (meta.preloadLinks) {
620
- chunk.preloads = [];
644
+ record.preloads = [];
621
645
  for (const entry of meta.preloadLinks) {
622
- chunk.preloads.push(wirePreload(entry));
646
+ record.preloads.push(wirePreload(entry));
623
647
  }
624
648
  }
625
649
  needs("assets");
626
- emit(chunk);
650
+ put(id, {
651
+ "seg::assets": record
652
+ });
627
653
  }
628
- emit(withHoles({
629
- type: "html",
630
- id,
631
- version,
632
- html,
633
- digest
634
- }, holeDigests(html, attrText)));
654
+ put(id, {
655
+ "": html(source, digest, holeDigests(source, attrText))
656
+ });
635
657
  },
636
658
  data(record) {
637
659
  if (record && typeof record.key === "string" && (record.key.endsWith("_fr") || /^\d+$/.test(record.key))) {
638
660
  return;
639
661
  }
662
+ if (swept) swept.emitted = true;
663
+ flush();
640
664
  if (typeof record === "string") {
641
- emit({
665
+ send({
642
666
  type: "data",
643
667
  id,
644
668
  version,
@@ -646,7 +670,7 @@ function createFrameSink(write, frame, have, hooks) {
646
670
  });
647
671
  scheduleSweep();
648
672
  } else {
649
- emit({
673
+ send({
650
674
  type: "data",
651
675
  id,
652
676
  version,
@@ -663,73 +687,40 @@ function createFrameSink(write, frame, have, hooks) {
663
687
  skipped.add(key);
664
688
  scheduleSweep();
665
689
  if (meta.error) {
666
- emit({
667
- type: "error",
668
- id: fid,
669
- version,
670
- key,
671
- error: {
672
- message: String(meta.error && meta.error.message || meta.error)
673
- }
690
+ putError(fid, key, {
691
+ message: String(meta.error && meta.error.message || meta.error)
674
692
  });
675
693
  } else emitDiffering(value);
676
694
  return;
677
695
  }
678
696
  const links = meta.styles && meta.styles.links || [];
679
697
  const inline = meta.styles && meta.styles.inline || [];
698
+ const r = {};
680
699
  if (links.length || inline.length) {
681
- if (links.length) styledKeys.add(key);
682
- const chunk = {
683
- type: "assets",
684
- id: fid,
685
- version,
686
- key
687
- };
700
+ const record = {};
688
701
  if (links.length) {
689
- chunk.styles = links.map(e => typeof e === "string" ? e : e.attrs ? {
702
+ record.styles = links.map(e => typeof e === "string" ? e : e.attrs ? {
690
703
  href: e.href,
691
704
  attrs: e.attrs
692
705
  } : e.href);
693
706
  }
694
707
  if (inline.length) {
695
- chunk.inlineStyles = inline.map(e => ({
708
+ record.inlineStyles = inline.map(e => ({
696
709
  id: e.id,
697
710
  content: e.content,
698
711
  attrs: e.attrs
699
712
  }));
700
713
  }
701
714
  needs("assets");
702
- emit(chunk);
715
+ r[`seg:${key}:assets`] = record;
703
716
  }
704
- emit(withHoles({
705
- type: "fragment",
706
- id: fid,
707
- version,
708
- key,
709
- html: value,
710
- digest: textDigest(value)
711
- }, holeDigests(value, attrText)));
717
+ r[`seg:${key}`] = html(value, textDigest(value), holeDigests(value, attrText));
712
718
  scheduleSweep();
713
- if (meta.error) {
714
- emit({
715
- type: "error",
716
- id: fid,
717
- version,
718
- key,
719
- error: {
720
- message: String(meta.error && meta.error.message || meta.error)
721
- }
722
- });
723
- }
724
- if (!meta.revealGroup) {
725
- emit({
726
- type: "reveal",
727
- id: fid,
728
- version,
729
- keys: [key],
730
- waitForStyles: !!links.length
731
- });
732
- }
719
+ if (meta.error) r[`seg:${key}:error`] = {
720
+ message: String(meta.error && meta.error.message || meta.error)
721
+ };
722
+ if (!meta.revealGroup) r[`seg:${key}:reveal`] = true;
723
+ put(fid, r);
733
724
  },
734
725
  reveal(keys, meta = {}) {
735
726
  const byFrame = new Map();
@@ -740,38 +731,27 @@ function createFrameSink(write, frame, have, hooks) {
740
731
  if (!group) byFrame.set(fid, group = []);
741
732
  group.push(key);
742
733
  }
734
+ const gate = meta.fallback ? "fallback" : "reveal";
743
735
  for (const [fid, groupKeys] of byFrame) {
744
- let waitForStyles = false;
745
- for (const key of groupKeys) if (styledKeys.has(key)) waitForStyles = true;
746
- const chunk = {
747
- type: "reveal",
748
- id: fid,
749
- version,
750
- keys: groupKeys,
751
- waitForStyles
752
- };
753
- if (meta.fallback) chunk.fallback = true;
754
- emit(chunk);
736
+ const r = {};
737
+ for (const key of groupKeys) r[`seg:${key}:${gate}`] = true;
738
+ put(fid, r);
755
739
  }
756
740
  },
757
741
  asset(type, value) {
758
742
  if (type === "module") {
759
743
  needs("assets");
760
- emit({
761
- type: "assets",
762
- id,
763
- version,
764
- key: "",
765
- modules: [value]
744
+ put(id, {
745
+ "seg::assets": {
746
+ modules: [value]
747
+ }
766
748
  });
767
749
  } else if (type === "preload") {
768
750
  needs("assets");
769
- emit({
770
- type: "assets",
771
- id,
772
- version,
773
- key: "",
774
- preloads: [wirePreload(value)]
751
+ put(id, {
752
+ "seg::assets": {
753
+ preloads: [wirePreload(value)]
754
+ }
775
755
  });
776
756
  }
777
757
  },
@@ -779,64 +759,69 @@ function createFrameSink(write, frame, have, hooks) {
779
759
  if (closed) return;
780
760
  if (bindings.size && !swept) sweep();
781
761
  closed = true;
782
- const chunk = {
783
- type: "complete",
784
- id,
785
- version
786
- };
787
- if (bound) chunk.bound = bound;
788
- emit(chunk);
762
+ put(id, bound ? {
763
+ ":complete": true,
764
+ ":bound": bound
765
+ } : {
766
+ ":complete": true
767
+ });
768
+ flush();
789
769
  },
790
770
  error(errorId, error) {
791
- emit({
792
- type: "error",
793
- id,
794
- version,
795
- key: errorId,
796
- error
797
- });
771
+ putError(id, errorId, error);
798
772
  },
773
+ flush,
799
774
  slot(key, args) {
800
- emit({
801
- type: "slot",
802
- id,
803
- version,
804
- key,
805
- args
775
+ put(id, {
776
+ [`slot:${key}`]: {
777
+ kind: "slot",
778
+ args
779
+ }
806
780
  });
807
781
  },
808
- region(childId, html) {
782
+ region(childId, value) {
809
783
  needs("regions");
810
- emit({
811
- type: "html",
812
- id: childId,
813
- version,
814
- html
784
+ put(childId, {
785
+ "": {
786
+ kind: "html",
787
+ value
788
+ }
815
789
  });
816
790
  },
817
- hole(key, html) {
818
- const op = {
819
- type: "hole",
820
- key,
821
- html,
822
- digest: textDigest(html)
791
+ hole(key, source, rows) {
792
+ const record = {
793
+ kind: "html",
794
+ digest: textDigest(source)
795
+ };
796
+ const base = holeDigest.get(key);
797
+ if (rows && base && hooks && hooks.live) {
798
+ record.rows = rows;
799
+ record.base = base;
800
+ } else record.value = source;
801
+ withHoles(record, holeDigests(record.rows ? rows.r.map(r => r[1]).join("") : source, null));
802
+ const r = {
803
+ ["hole:" + key]: record
823
804
  };
824
- swept ? swept.ops.push(op) : emitOps([op]);
805
+ showing(r);
806
+ swept ? Object.assign(swept.r, r) : put(id, r);
825
807
  },
826
808
  attr(key, attrs, removed) {
827
- const op = {
828
- type: "attr",
829
- key,
830
- attrs,
809
+ const record = {
810
+ kind: "attrs",
811
+ value: attrs,
831
812
  digest: textDigest(attrs)
832
813
  };
833
- if (removed && removed.length) op.removed = removed;
834
- swept ? swept.ops.push(op) : emitOps([op]);
814
+ if (removed && removed.length) record.removed = removed;
815
+ const r = {
816
+ ["attr:" + key]: record
817
+ };
818
+ swept ? Object.assign(swept.r, r) : put(id, r);
835
819
  },
836
820
  attrBaseline(key, text) {
837
821
  attrText.set(key, text);
838
822
  },
839
823
  openBinding(key, b) {
824
+ if (/^lha?:/.test(key)) needs("wire");
840
825
  bindings.set(key, b);
841
826
  },
842
827
  closeBinding(key) {
@@ -869,8 +854,9 @@ function renderServerComponent(component, options = {}) {
869
854
  if (ctx) {
870
855
  ctx.commit = sink.commit;
871
856
  ctx.commitEpoch = () => sink.epoch;
872
- ctx.liveHoles = createLiveHoles(sink);
873
- ctx.claims = CLAIMS_STREAM;
857
+ let unsettled = !!options.live;
858
+ if (!unsettled) ctx.unsettled = () => void (unsettled = true);
859
+ ctx.liveHoles = createLiveHoles(sink, false, () => !unsettled, ctx._errorScope);
874
860
  }
875
861
  return serverComponentScope(() => component(props));
876
862
  };
@@ -903,6 +889,7 @@ function frameStream(makeCode, options) {
903
889
  function finish() {
904
890
  if (ended) return;
905
891
  ended = true;
892
+ sink.flush();
906
893
  if (timer) clearTimeout(timer);
907
894
  if (upstream) upstream.removeEventListener("abort", onSignal);
908
895
  w.end && w.end();
@@ -923,19 +910,20 @@ function frameStream(makeCode, options) {
923
910
  finish();
924
911
  render.abort(upstream.reason);
925
912
  }
926
- const emit = chunk => {
927
- if (observation) observation.chunk(chunk);
928
- w.write(chunk);
929
- if (bounded && !flushed && chunk.type === "html" && chunk.id === id) {
913
+ const emit = message => {
914
+ if (observation) observation.chunk(message);
915
+ w.write(message);
916
+ if (bounded && !flushed && message.id === id && message.r && "" in message.r) {
930
917
  flushed = true;
931
918
  if (maxDurationMs > 0 && maxDurationMs !== Infinity) timer = setTimeout(() => cut("time"), maxDurationMs);
932
919
  }
933
920
  };
934
- const sink = createFrameSink(emit, frame, options.resume && options.resume.have, bounded ? {
935
- onYield() {
921
+ const sink = createFrameSink(emit, frame, options.resume && options.resume.have, {
922
+ live: options.live,
923
+ onYield: bounded ? () => {
936
924
  if (flushed && maxYields > 0 && ++yields >= maxYields) cut("yields");
937
- }
938
- } : undefined);
925
+ } : undefined
926
+ });
939
927
  if (options.live) sink.needs("wire");
940
928
  w.write({
941
929
  type: "start",
@@ -970,6 +958,7 @@ function frameStream(makeCode, options) {
970
958
  finish();
971
959
  }
972
960
  if (w[ANNOUNCE]) w[ANNOUNCE](sink.announce());
961
+ sink.flush();
973
962
  }
974
963
  return {
975
964
  pipe: stream,
@@ -991,100 +980,21 @@ function frameStream(makeCode, options) {
991
980
  function slotRange(occurrence) {
992
981
  return {
993
982
  t: `<!--slot:${occurrence}:start--><!--slot:${occurrence}:end-->`,
994
- $slot: true,
995
- $occurrence: occurrence
983
+ $slot: true
996
984
  };
997
985
  }
998
- const RANGE_KEYS = new Set(["t", "h", "p", "then", "length", "slice", "constructor", "toString", "valueOf", "toJSON"]);
999
- const NODE_KEYS = new Set(["t", "h", "p"]);
1000
- function isRangeKey(key) {
1001
- const c = key.charCodeAt(0);
1002
- return c === 36 || c >= 48 && c <= 57 || RANGE_KEYS.has(key);
1003
- }
1004
- function slotProxy(range, occurrence, face, content, onData, needs) {
1005
- return new Proxy(range, {
1006
- get(target, key, receiver) {
1007
- if (typeof key !== "string" || isRangeKey(key)) return Reflect.get(target, key, receiver);
1008
- if (onData) onData = void onData();
1009
- if (face !== SLOT_FACE_MARKUP) needs("bind");
1010
- return slotValue(occurrence, key, content ? content[key] : undefined, face);
1011
- }
1012
- });
986
+ function argBorderForm(value, needs) {
987
+ return toBorderForm(noteTraces(value, needs));
1013
988
  }
1014
- function argBorderForm(value, key, occurrence, needs) {
1015
- return toBorderForm(withoutStandIns(value, key, occurrence, needs));
1016
- }
1017
- function withoutStandIns(value, key, occurrence, needs) {
1018
- return rewriteTree(value, (v, path) => {
989
+ function noteTraces(value, needs) {
990
+ return rewriteTree(value, v => {
1019
991
  if (isContainerTraced(v)) {
1020
992
  needs("trace");
1021
993
  return v;
1022
994
  }
1023
- if (Object.getPrototypeOf(v) === Object.prototype && isSlotValue(v)) {
1024
- standInArgFinding(v, key, occurrence, path);
1025
- return undefined;
1026
- }
1027
995
  return DESCEND;
1028
996
  }, true);
1029
997
  }
1030
- function standInArgFinding(sv, key, occurrence, path) {
1031
- {
1032
- const ctx = sharedConfig.context;
1033
- if (ctx) {
1034
- const id = `${occurrence}\u0000${key}${path}\u0000arg`;
1035
- const seen = ctx.slotFindings || (ctx.slotFindings = new Set());
1036
- if (seen.has(id)) return;
1037
- seen.add(id);
1038
- }
1039
- const where = path === "" ? `Arg \`${key}\`` : `Arg \`${key}${path}\``;
1040
- devCheck({
1041
- code: "BINDING_SLOT_POSITION",
1042
- kind: "ssr",
1043
- severity: "warn",
1044
- 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.`,
1045
- data: {
1046
- reason: "arg",
1047
- occurrence,
1048
- key,
1049
- path: path === "" ? undefined : path,
1050
- from: sv[SLOT_VALUE],
1051
- fromKey: sv.k
1052
- }
1053
- });
1054
- }
1055
- }
1056
- function slotFace(range, content) {
1057
- if (content == null) return SLOT_FACE_DATA;
1058
- if (typeof content !== "object" || Array.isArray(content)) return SLOT_FACE_MARKUP;
1059
- if (isServerContent(content)) {
1060
- let data = false;
1061
- for (const key in content) {
1062
- if (!NODE_KEYS.has(key)) {
1063
- data = true;
1064
- break;
1065
- }
1066
- }
1067
- if (!data) return SLOT_FACE_MARKUP;
1068
- }
1069
- {
1070
- for (const key of Object.keys(content)) {
1071
- if (isRangeKey(key)) {
1072
- devCheck({
1073
- code: "BINDING_SLOT_POSITION",
1074
- kind: "ssr",
1075
- severity: "warn",
1076
- 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.`,
1077
- data: {
1078
- reason: "reserved-key",
1079
- occurrence: range.$occurrence,
1080
- key
1081
- }
1082
- });
1083
- }
1084
- }
1085
- }
1086
- return SLOT_FACE_DATA;
1087
- }
1088
998
  const OCCURRENCE_UNSAFE = /[^A-Za-z0-9_.-]/g;
1089
999
  function encodeOccurrenceKey(key) {
1090
1000
  return String(key).replace(OCCURRENCE_UNSAFE, c => {
@@ -1139,12 +1049,19 @@ function structuralArgsKey(raw) {
1139
1049
  };
1140
1050
  return walk(raw, true) ? out : undefined;
1141
1051
  }
1142
- function repeatKey(prop, raw) {
1143
- const keyed = keyedId(prop, raw);
1144
- if (keyed !== undefined) return keyed;
1145
- const structural = structuralArgsKey(raw);
1146
- return structural === undefined ? undefined : prop + "\0" + structural;
1052
+ function argDigest(value) {
1053
+ const t = typeof value;
1054
+ if (value == null || t !== "object" && t !== "function" && value === value) return value;
1055
+ if (isContainerTraced(value)) return value;
1056
+ try {
1057
+ const key = structuralArgsKey([value]);
1058
+ return key === undefined ? value : key;
1059
+ } catch (_) {
1060
+ return value;
1061
+ }
1147
1062
  }
1063
+ const PENDING_ARG = {};
1064
+ const noDigest = () => NaN;
1148
1065
  function isAsyncValue(v) {
1149
1066
  return !!v && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
1150
1067
  }
@@ -1160,6 +1077,37 @@ function tapFirstYield(iterable) {
1160
1077
  rest
1161
1078
  };
1162
1079
  }
1080
+ function packOccurrences(occs) {
1081
+ const out = [];
1082
+ let prop = "",
1083
+ a = -1,
1084
+ b = -1;
1085
+ const flush = () => a >= 0 && out.push(prop + "#" + (a === b ? a : a + "-" + b));
1086
+ for (const o of occs) {
1087
+ const m = /^(.*)#(\d+)$/.exec(o);
1088
+ if (m && m[1] === prop && +m[2] === b + 1 && a >= 0) {
1089
+ b++;
1090
+ continue;
1091
+ }
1092
+ flush();
1093
+ a = b = -1;
1094
+ if (m) {
1095
+ prop = m[1];
1096
+ a = b = +m[2];
1097
+ } else out.push(o);
1098
+ }
1099
+ flush();
1100
+ return out.join(" ");
1101
+ }
1102
+ function hasAsyncHoles(node, depth = 0) {
1103
+ if (!node || typeof node !== "object" || depth > 64) return false;
1104
+ if (Array.isArray(node)) {
1105
+ for (const n of node) if (hasAsyncHoles(n, depth + 1)) return true;
1106
+ return false;
1107
+ }
1108
+ if (node.h && node.h.length) return true;
1109
+ return false;
1110
+ }
1163
1111
  function suppressedFill(render) {
1164
1112
  const live = sharedConfig.context && sharedConfig.context.liveHoles;
1165
1113
  if (!live) return render();
@@ -1170,25 +1118,96 @@ function suppressedFill(render) {
1170
1118
  live.suppressed--;
1171
1119
  }
1172
1120
  }
1121
+ let parked = null;
1122
+ let parkedIds = 0;
1123
+ const PARKED = /<!--sc-n:(\d+)-->/;
1124
+ function park(render) {
1125
+ if (!parked) return render();
1126
+ const id = ++parkedIds;
1127
+ parked.set(id, {
1128
+ render,
1129
+ out: undefined
1130
+ });
1131
+ return {
1132
+ t: `<!--sc-n:${id}-->`
1133
+ };
1134
+ }
1135
+ const runParked = (entry, owner) => entry.out || (entry.out = entry.render(owner));
1136
+ function placeParked(node, nested, owner) {
1137
+ const out = expandParked(node, nested, owner);
1138
+ for (const entry of nested.values()) runParked(entry, owner);
1139
+ return out;
1140
+ }
1141
+ function expandParked(node, nested, owner) {
1142
+ if (Array.isArray(node)) {
1143
+ const out = node.map(n => expandParked(n, nested, owner));
1144
+ out.$slot = node.$slot;
1145
+ return out;
1146
+ }
1147
+ if (!node || node.t === undefined) return node;
1148
+ if (!node.h) return splitParked(node.t, nested, owner) || node;
1149
+ const out = [];
1150
+ node.t.forEach((t, i) => {
1151
+ out.push(splitParked(t, nested, owner) || {
1152
+ t
1153
+ });
1154
+ if (i < node.h.length) out.push({
1155
+ t: ["", ""],
1156
+ h: [node.h[i]],
1157
+ p: [node.p[i]]
1158
+ });
1159
+ });
1160
+ return out;
1161
+ }
1162
+ function splitParked(t, nested, owner) {
1163
+ const parts = typeof t === "string" ? t.split(PARKED) : [t];
1164
+ return parts.length > 1 ? parts.map((part, i) => i & 1 ? runParked(nested.get(+part), owner) : {
1165
+ t: part
1166
+ }) : undefined;
1167
+ }
1173
1168
  function createDocumentSlotProps(clientProps, frameId) {
1174
1169
  const counts = Object.create(null);
1170
+ let depsBatch = null;
1171
+ let depsN = 0;
1172
+ let wideSent = 0;
1173
+ const depsContext = sharedConfig.context;
1174
+ const noteDeps = (occurrence, reads, untracked) => {
1175
+ if (!depsContext || !depsContext.serialize || !depsContext.edges) return;
1176
+ const own = `sc-${frameId}-${occurrence}-`;
1177
+ const batch = () => {
1178
+ if (depsBatch) return depsBatch;
1179
+ queueMicrotask(() => {
1180
+ const b = {};
1181
+ for (const sid in depsBatch) b[sid] = packOccurrences(depsBatch[sid]);
1182
+ depsBatch = null;
1183
+ const wide = depsContext.edgeWide?.s || null;
1184
+ if (wide && wide.size > wideSent) {
1185
+ b["*"] = [...wide].slice(wideSent).join(" ");
1186
+ wideSent = wide.size;
1187
+ }
1188
+ if (depsN === 0 || Object.keys(b).length) depsContext.serialize(`sc:deps:${frameId}:${depsN++}`, b);
1189
+ });
1190
+ return depsBatch = Object.create(null);
1191
+ };
1192
+ const b = batch();
1193
+ if (reads) for (const sid of reads) if (!sid.startsWith(own)) (b[sid] ||= []).push(occurrence);
1194
+ if (untracked) (b["!"] ||= []).push(occurrence);
1195
+ };
1175
1196
  const getters = new Map();
1176
1197
  const repeats = new Map();
1177
- const range = (occurrence, content) => {
1198
+ const range = (occurrence, content, tail) => {
1178
1199
  const r = [{
1179
1200
  t: `<!--slot:${occurrence}:start-->`
1180
- }, content, {
1201
+ }, content, tail, {
1181
1202
  t: `<!--slot:${occurrence}:end-->`
1182
1203
  }];
1183
1204
  r.$slot = true;
1184
- r.$occurrence = occurrence;
1185
- const face = slotFace(r, content);
1186
- r.$face = face;
1187
- return slotProxy(r, occurrence, face, face === SLOT_FACE_DATA ? content : undefined, undefined, documentNeeds);
1205
+ return r;
1188
1206
  };
1189
1207
  const zoneOwner = getOwner ? getOwner() : null;
1190
- const scoped = (occurrence, render) => {
1208
+ const scoped = (occurrence, render, owner) => {
1191
1209
  const id = `sc-${frameId}-${occurrence}-`;
1210
+ if (owner) return runWithOwner(owner, () => runWithHydrationScope(id, render));
1192
1211
  const run = () => Hydration ? Hydration({
1193
1212
  id,
1194
1213
  get children() {
@@ -1208,18 +1227,13 @@ function createDocumentSlotProps(clientProps, frameId) {
1208
1227
  if (!fn) {
1209
1228
  fn = (...callArgs) => {
1210
1229
  if (callArgs.length === 0 || callArgs[0] === undefined) {
1211
- const rk = prop + "\0";
1212
- const repeat = repeats.get(rk);
1213
- if (repeat) return repeat;
1214
- const out = suppressedFill(() => scoped(prop, () => {
1230
+ return park(owner => suppressedFill(() => scoped(prop, () => {
1215
1231
  const value = clientProps[prop];
1216
1232
  return range(prop, typeof value === "function" ? value() : value);
1217
- }));
1218
- if (out.$face === SLOT_FACE_DATA) repeats.set(rk, out);
1219
- return out;
1233
+ }, owner)));
1220
1234
  }
1221
1235
  const raw = callArgs[0];
1222
- const rk = repeatKey(prop, raw);
1236
+ const rk = keyedId(prop, raw);
1223
1237
  const repeat = rk !== undefined && repeats.get(rk);
1224
1238
  if (repeat) return repeat;
1225
1239
  const occurrence = occurrenceId(prop, raw, counts);
@@ -1227,10 +1241,10 @@ function createDocumentSlotProps(clientProps, frameId) {
1227
1241
  if (typeof slot !== "function") return range(occurrence, undefined);
1228
1242
  const context = sharedConfig.context;
1229
1243
  const recordKey = `sc:slot:${frameId}:${occurrence}`;
1244
+ const deferred = !!parked;
1230
1245
  let settleRecord;
1231
- if (context && context.async) {
1232
- context.serialize(recordKey, new Promise(resolve => settleRecord = resolve));
1233
- }
1246
+ const declare = () => context && context.async && context.serialize(recordKey, new Promise(resolve => settleRecord = resolve));
1247
+ deferred || declare();
1234
1248
  try {
1235
1249
  const resolved = {};
1236
1250
  const liveArgs = sharedConfig.context && sharedConfig.context.live && sharedConfig.context.live.args;
@@ -1238,6 +1252,7 @@ function createDocumentSlotProps(clientProps, frameId) {
1238
1252
  const evals = {};
1239
1253
  const states = {};
1240
1254
  const minted = {};
1255
+ const nestedOf = {};
1241
1256
  for (const key of Object.keys(raw)) {
1242
1257
  if (key === "$key") continue;
1243
1258
  const desc = Object.getOwnPropertyDescriptor(raw, key);
@@ -1256,6 +1271,8 @@ function createDocumentSlotProps(clientProps, frameId) {
1256
1271
  if (evaluate) {
1257
1272
  evals[key] = evaluate;
1258
1273
  const stampBefore = scopeStamp();
1274
+ const outer = parked;
1275
+ const nested = nestedOf[key] = parked = new Map();
1259
1276
  try {
1260
1277
  value = evaluate();
1261
1278
  states[key] = {
@@ -1263,6 +1280,9 @@ function createDocumentSlotProps(clientProps, frameId) {
1263
1280
  last: value
1264
1281
  };
1265
1282
  } catch (err) {
1283
+ parked = outer;
1284
+ for (const entry of nested.values()) runParked(entry);
1285
+ nested.clear();
1266
1286
  const blocked = ssrHandleError && ssrHandleError(err);
1267
1287
  if (!blocked) throw err;
1268
1288
  const state = states[key] = {
@@ -1275,6 +1295,7 @@ function createDocumentSlotProps(clientProps, frameId) {
1275
1295
  if (liveArgs) liveArgs.commit();
1276
1296
  });
1277
1297
  }
1298
+ parked = outer;
1278
1299
  if (scopeStamp() !== stampBefore) minted[key] = true;
1279
1300
  }
1280
1301
  vals[key] = value;
@@ -1291,6 +1312,7 @@ function createDocumentSlotProps(clientProps, frameId) {
1291
1312
  key,
1292
1313
  childId,
1293
1314
  value,
1315
+ nested: nestedOf[key],
1294
1316
  used: false,
1295
1317
  locked: false
1296
1318
  };
@@ -1301,7 +1323,7 @@ function createDocumentSlotProps(clientProps, frameId) {
1301
1323
  region.used = true;
1302
1324
  return [{
1303
1325
  t: frameElementOpen(childId)
1304
- }, value, {
1326
+ }, region.nested && region.nested.size ? placeParked(value, region.nested, getOwner()) : value, {
1305
1327
  t: FRAME_ELEMENT_CLOSE
1306
1328
  }];
1307
1329
  };
@@ -1322,49 +1344,67 @@ function createDocumentSlotProps(clientProps, frameId) {
1322
1344
  configurable: true
1323
1345
  });
1324
1346
  } else {
1325
- resolved[key] = vals[key] = withoutStandIns(value, key, occurrence, documentNeeds);
1347
+ resolved[key] = vals[key] = noteTraces(value, documentNeeds);
1326
1348
  }
1327
1349
  }
1328
- const out = suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved))));
1329
- const unused = regions.filter(r => !r.used);
1330
- if (context) {
1331
- const args = {};
1332
- for (const key of Object.keys(vals)) {
1333
- const value = vals[key];
1334
- const region = regions.find(r => r.key === key);
1335
- if (region) {
1336
- args[key] = {
1337
- $frame: region.childId
1338
- };
1339
- continue;
1340
- }
1341
- if (!isContainerTraced(value) && isServerContent(value)) continue;
1342
- args[key] = argBorderForm(value, key, occurrence, documentNeeds);
1343
- }
1344
- settleRecord ? settleRecord({
1345
- ...args
1346
- }) : context.serialize(recordKey, {
1347
- ...args
1348
- });
1349
- for (const region of unused) {
1350
+ for (const key in nestedOf) if (!regions.some(r => r.key === key)) for (const entry of nestedOf[key].values()) runParked(entry);
1351
+ const flip = () => {
1352
+ if (flip.done || !context) return;
1353
+ flip.done = true;
1354
+ for (const region of regions) {
1355
+ if (region.used) continue;
1350
1356
  region.locked = true;
1351
- context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(context, region.value));
1357
+ context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(context, region.nested && region.nested.size ? placeParked(region.value, region.nested) : region.value));
1352
1358
  }
1353
- if (liveArgs) {
1354
- for (const key of Object.keys(evals)) {
1355
- if (regions.some(r => r.key === key)) continue;
1356
- if (minted[key]) continue;
1357
- const ledgerKey = `${frameId}:${occurrence}:${key}`;
1358
- openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
1359
- args[key] = argBorderForm(value, key, occurrence, documentNeeds);
1360
- liveArgs.slot(frameId, occurrence, {
1361
- ...args
1362
- });
1359
+ };
1360
+ flip.$lhSkip = true;
1361
+ const finish = owner => {
1362
+ if (deferred) declare();
1363
+ try {
1364
+ const tracked = trackFillReads(() => suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved), flip), owner)));
1365
+ const out = tracked.result;
1366
+ noteDeps(occurrence, tracked.reads, tracked.untracked || hasAsyncHoles(out));
1367
+ if (context) {
1368
+ const args = {};
1369
+ for (const key of Object.keys(vals)) {
1370
+ const value = vals[key];
1371
+ const region = regions.find(r => r.key === key);
1372
+ if (region) {
1373
+ args[key] = {
1374
+ $frame: region.childId
1375
+ };
1376
+ continue;
1377
+ }
1378
+ if (!isContainerTraced(value) && isServerContent(value)) continue;
1379
+ args[key] = argBorderForm(value, documentNeeds);
1380
+ }
1381
+ settleRecord ? settleRecord({
1382
+ ...args
1383
+ }) : context.serialize(recordKey, {
1384
+ ...args
1363
1385
  });
1386
+ if (liveArgs) {
1387
+ for (const key of Object.keys(evals)) {
1388
+ if (regions.some(r => r.key === key)) continue;
1389
+ if (minted[key]) continue;
1390
+ const ledgerKey = `${frameId}:${occurrence}:${key}`;
1391
+ openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
1392
+ args[key] = argBorderForm(value, documentNeeds);
1393
+ liveArgs.slot(frameId, occurrence, {
1394
+ ...args
1395
+ });
1396
+ });
1397
+ }
1398
+ }
1364
1399
  }
1400
+ return out;
1401
+ } catch (error) {
1402
+ settleRecord && settleRecord(undefined);
1403
+ throw error;
1365
1404
  }
1366
- }
1367
- if (rk !== undefined && (rk === occurrence || out.$face === SLOT_FACE_DATA)) repeats.has(rk) || repeats.set(rk, out);
1405
+ };
1406
+ const out = park(finish);
1407
+ if (rk !== undefined && rk === occurrence) repeats.has(rk) || repeats.set(rk, out);
1368
1408
  return out;
1369
1409
  } catch (error) {
1370
1410
  settleRecord && settleRecord(undefined);
@@ -1380,9 +1420,10 @@ function createDocumentSlotProps(clientProps, frameId) {
1380
1420
  }
1381
1421
  const FRAME_TAG = "solid-frame";
1382
1422
  const FRAME_ID_ATTR = "data-fid";
1383
- function frameElementOpen(id) {
1423
+ const FRAME_ARGS_ATTR = "data-fa";
1424
+ function frameElementOpen(id, args) {
1384
1425
  const escaped = sharedConfig.context ? sharedConfig.context.escape(String(id), true) : String(id);
1385
- return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}" style="display:contents">`;
1426
+ return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}"${args ? ` ${FRAME_ARGS_ATTR}="${args}"` : ""} style="display:contents">`;
1386
1427
  }
1387
1428
  const DOCUMENT_SITES = Symbol();
1388
1429
  function contextSites(ctx) {
@@ -1434,6 +1475,7 @@ function armDocumentLiveHoles(ctx) {
1434
1475
  if (live.holes) {
1435
1476
  ctx.commit = live.commit;
1436
1477
  ctx.commitEpoch = live.commitEpoch;
1478
+ ctx.unsettled = live.unsettled;
1437
1479
  }
1438
1480
  return;
1439
1481
  }
@@ -1442,6 +1484,7 @@ function armDocumentLiveHoles(ctx) {
1442
1484
  if (live) live.holes = null;
1443
1485
  return;
1444
1486
  }
1487
+ let unsettled = false;
1445
1488
  const bindings = new Map();
1446
1489
  let epoch = 0;
1447
1490
  let sweepScheduled = false;
@@ -1449,7 +1492,7 @@ function armDocumentLiveHoles(ctx) {
1449
1492
  let swept = null;
1450
1493
  const sweep = () => {
1451
1494
  epoch++;
1452
- const ops = swept = [];
1495
+ const r = swept = {};
1453
1496
  try {
1454
1497
  for (const b of [...bindings.values()]) {
1455
1498
  try {
@@ -1460,12 +1503,8 @@ function armDocumentLiveHoles(ctx) {
1460
1503
  } finally {
1461
1504
  swept = null;
1462
1505
  }
1463
- pushOps(ops);
1464
- };
1465
- const pushOps = ops => {
1466
- if (ops.length === 1) push(ops[0]);else if (ops.length) push({
1467
- type: "ops",
1468
- ops
1506
+ for (const _ in r) return push({
1507
+ r
1469
1508
  });
1470
1509
  };
1471
1510
  const scheduleSweep = () => {
@@ -1485,49 +1524,57 @@ function armDocumentLiveHoles(ctx) {
1485
1524
  closed = true;
1486
1525
  }
1487
1526
  }));
1488
- const push = op => {
1489
- if (!closed) channel.enqueue(op);
1527
+ const push = batch => {
1528
+ if (!closed) channel.enqueue(batch);
1490
1529
  };
1530
+ const write = r => swept ? Object.assign(swept, r) : push({
1531
+ r
1532
+ });
1491
1533
  ctx.liveHoles = live.holes = createLiveHoles({
1492
1534
  openBinding(key, b) {
1535
+ documentNeeds("wire");
1493
1536
  bindings.set(key, b);
1494
1537
  },
1495
1538
  closeBinding(key) {
1496
1539
  bindings.delete(key);
1497
1540
  },
1498
- hole(key, html) {
1499
- const op = {
1500
- type: "hole",
1501
- key,
1502
- html,
1503
- digest: textDigest(html)
1504
- };
1505
- swept ? swept.push(op) : pushOps([op]);
1541
+ hole(key, value) {
1542
+ write({
1543
+ ["hole:" + key]: {
1544
+ kind: "html",
1545
+ value,
1546
+ digest: textDigest(value)
1547
+ }
1548
+ });
1506
1549
  },
1507
- attr(key, attrs, removed) {
1508
- const op = {
1509
- type: "attr",
1510
- key,
1511
- attrs,
1512
- digest: textDigest(attrs)
1550
+ attr(key, value, removed) {
1551
+ const record = {
1552
+ kind: "attrs",
1553
+ value,
1554
+ digest: textDigest(value)
1513
1555
  };
1514
- if (removed && removed.length) op.removed = removed;
1515
- swept ? swept.push(op) : pushOps([op]);
1556
+ if (removed && removed.length) record.removed = removed;
1557
+ write({
1558
+ ["attr:" + key]: record
1559
+ });
1516
1560
  },
1517
1561
  error(key, error) {
1518
1562
  push({
1519
- type: "error",
1520
- key,
1521
- error
1563
+ r: {
1564
+ [`hole:${key}:error`]: error
1565
+ }
1522
1566
  });
1523
1567
  },
1524
1568
  commit: scheduleSweep,
1525
1569
  get epoch() {
1526
1570
  return epoch;
1527
1571
  }
1528
- }, true);
1572
+ }, true, () => !unsettled, ctx._errorScope);
1529
1573
  ctx.commit = live.commit = scheduleSweep;
1530
1574
  ctx.commitEpoch = live.commitEpoch = () => epoch;
1575
+ ctx.unsettled = live.unsettled = () => {
1576
+ unsettled = true;
1577
+ };
1531
1578
  live.args = {
1532
1579
  openBinding(key, b) {
1533
1580
  bindings.set(key, b);
@@ -1537,19 +1584,23 @@ function armDocumentLiveHoles(ctx) {
1537
1584
  },
1538
1585
  slot(fid, occurrence, args) {
1539
1586
  push({
1540
- type: "slot",
1541
- fid,
1542
- key: occurrence,
1543
- args
1587
+ r: {
1588
+ [`slot:${occurrence}`]: {
1589
+ kind: "slot",
1590
+ args
1591
+ }
1592
+ },
1593
+ fid
1544
1594
  });
1545
1595
  },
1546
1596
  commit: scheduleSweep
1547
1597
  };
1548
1598
  live.error = (fid, error) => {
1549
1599
  push({
1550
- type: "error",
1551
- fid,
1552
- error
1600
+ r: {
1601
+ ":error": error
1602
+ },
1603
+ fid
1553
1604
  });
1554
1605
  };
1555
1606
  live.end = () => {
@@ -1566,17 +1617,17 @@ function frameTransformDirectResult(value, {
1566
1617
  }) {
1567
1618
  if (typeof value !== "function") return value;
1568
1619
  const component = value;
1620
+ const address = frameAddress(id, args);
1569
1621
  const wrapped = props => {
1570
1622
  const siteId = documentSiteId(id);
1571
1623
  return [{
1572
- t: frameElementOpen(siteId)
1624
+ t: frameElementOpen(siteId, address.slice(id.length + 1))
1573
1625
  },
1574
1626
  serverOwned(() => {
1575
1627
  const page = sharedConfig.context;
1576
1628
  armDocumentLiveHoles(page);
1577
1629
  if (tierUrls && page && page.live && !page.live.tierUrls) page.live.tierUrls = tierUrls;
1578
1630
  const ctx = Object.create(page);
1579
- ctx.claims = CLAIMS_DOCUMENT;
1580
1631
  ctx.frameId = siteId;
1581
1632
  sharedConfig.context = ctx;
1582
1633
  try {
@@ -1593,7 +1644,7 @@ function frameTransformDirectResult(value, {
1593
1644
  };
1594
1645
  wrapped[SERVER_COMPONENT] = id;
1595
1646
  wrapped[SERVER_COMPONENT_SOURCE] = component;
1596
- wrapped[SERVER_COMPONENT_ADDRESS] = frameAddress(id, args);
1647
+ wrapped[SERVER_COMPONENT_ADDRESS] = address;
1597
1648
  return wrapped;
1598
1649
  }
1599
1650
  function resolveRegionHtml(ctx, node) {
@@ -1696,6 +1747,15 @@ function createSlotProps(sink, frame) {
1696
1747
  const counts = Object.create(null);
1697
1748
  const getters = new Map();
1698
1749
  const repeats = new Map();
1750
+ let pass = null;
1751
+ let passRepeats = null;
1752
+ const recs = new Map();
1753
+ const forget = occurrence => {
1754
+ const rec = recs.get(occurrence);
1755
+ if (!rec) return;
1756
+ recs.delete(occurrence);
1757
+ for (const key in rec.vals) sink.closeBinding(`${occurrence}:${key}`);
1758
+ };
1699
1759
  const needs = sink.needs || (() => {});
1700
1760
  return new Proxy(Object.create(null), {
1701
1761
  has() {
@@ -1708,25 +1768,38 @@ function createSlotProps(sink, frame) {
1708
1768
  if (!fn) {
1709
1769
  fn = (...callArgs) => {
1710
1770
  if (callArgs.length === 0 || callArgs[0] === undefined) {
1711
- return slotProxy(slotRange(prop), prop, SLOT_FACE_STREAM, undefined, undefined, needs);
1771
+ return slotRange(prop);
1712
1772
  }
1713
- const rk = repeatKey(prop, callArgs[0]);
1714
- const repeat = rk !== undefined && repeats.get(rk);
1715
- if (repeat) return repeat;
1716
1773
  const live = sharedConfig.context && sharedConfig.context.liveHoles;
1717
- if (live) {
1718
- if (live.sweeping) {
1719
- live.gateHit = true;
1720
- return {
1721
- t: "",
1722
- $slot: true
1723
- };
1724
- }
1725
- live.recordStamp++;
1774
+ const sweeping = !!live && live.sweeping;
1775
+ let rmap = repeats;
1776
+ if (sweeping) {
1777
+ if (pass !== live.visit) passRepeats = new Map();
1778
+ pass = live.visit;
1779
+ rmap = passRepeats;
1780
+ }
1781
+ const rk = keyedId(prop, callArgs[0]);
1782
+ const repeat = rk !== undefined && rmap.get(rk);
1783
+ if (repeat) return repeat;
1784
+ if (sweeping && !live.scope) {
1785
+ live.gateHit = true;
1786
+ return {
1787
+ t: "",
1788
+ $slot: true
1789
+ };
1726
1790
  }
1727
1791
  const raw = callArgs[0];
1728
- const occurrence = occurrenceId(prop, raw, counts);
1792
+ let occurrence = keyedId(prop, raw);
1793
+ if (occurrence === undefined) {
1794
+ const positional = sweeping ? undefined : occurrenceId(prop, raw, counts);
1795
+ occurrence = live ? live.slotId(prop, positional) : positional;
1796
+ }
1797
+ if (sweeping && live.dry) return slotRange(occurrence);
1798
+ const prev = recs.get(occurrence);
1799
+ let changed = !prev;
1800
+ const digest = live && live.scope ? argDigest : noDigest;
1729
1801
  const args = {};
1802
+ const vals = {};
1730
1803
  const opened = [];
1731
1804
  for (const key of Object.keys(raw)) {
1732
1805
  if (key === "$key") continue;
@@ -1742,6 +1815,7 @@ function createSlotProps(sink, frame) {
1742
1815
  let evaluate = null;
1743
1816
  let value;
1744
1817
  let state = null;
1818
+ let pending = false;
1745
1819
  const stampBefore = scopeStamp();
1746
1820
  try {
1747
1821
  if (desc.get) {
@@ -1763,6 +1837,7 @@ function createSlotProps(sink, frame) {
1763
1837
  settled: false,
1764
1838
  last: undefined
1765
1839
  };
1840
+ pending = true;
1766
1841
  const pendingState = state;
1767
1842
  value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
1768
1843
  pendingState.settled = true;
@@ -1774,6 +1849,7 @@ function createSlotProps(sink, frame) {
1774
1849
  const t = typeof value;
1775
1850
  if (value == null || t === "string" || t === "number" || t === "boolean") {
1776
1851
  args[key] = value;
1852
+ vals[key] = digest(value);
1777
1853
  if (evaluate) state = {
1778
1854
  settled: true,
1779
1855
  last: value
@@ -1783,21 +1859,27 @@ function createSlotProps(sink, frame) {
1783
1859
  if (resolved.h.length) {
1784
1860
  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.");
1785
1861
  }
1786
- sink.region(childId, resolved.t[0]);
1862
+ vals[key] = "<" + resolved.t[0];
1863
+ if (!prev || prev.vals[key] !== vals[key]) sink.region(childId, resolved.t[0]);
1787
1864
  args[key] = {
1788
1865
  $frame: childId
1789
1866
  };
1790
1867
  } else {
1791
- const ref = `arg:${occurrence}:${key}`;
1792
- ctx.serialize(ref, argBorderForm(value, key, occurrence, needs));
1793
- args[key] = {
1794
- $ref: ref
1795
- };
1868
+ vals[key] = pending ? PENDING_ARG : digest(value);
1869
+ if (prev && prev.vals[key] === vals[key]) args[key] = prev.args[key];else {
1870
+ const ref = prev ? `arg:${occurrence}:${key}@${sink.nextArgRef(`${occurrence}:${key}`)}` : `arg:${occurrence}:${key}`;
1871
+ if (prev) sink.mintRef(ref);
1872
+ ctx.serialize(ref, argBorderForm(value, needs));
1873
+ args[key] = {
1874
+ $ref: ref
1875
+ };
1876
+ }
1796
1877
  if (evaluate && !state) state = {
1797
1878
  settled: true,
1798
1879
  last: value
1799
1880
  };
1800
1881
  }
1882
+ if (prev && prev.vals[key] !== vals[key]) changed = true;
1801
1883
  if (evaluate && state && !mintedEval) opened.push({
1802
1884
  key,
1803
1885
  evaluate,
@@ -1807,9 +1889,18 @@ function createSlotProps(sink, frame) {
1807
1889
  ctx.registerFragment = origRegister;
1808
1890
  }
1809
1891
  }
1810
- sink.slot(occurrence, {
1811
- ...args
1812
- });
1892
+ if (prev) for (const key in prev.vals) if (!(key in vals)) changed = true;
1893
+ const rec = changed ? {
1894
+ args,
1895
+ vals
1896
+ } : prev;
1897
+ if (changed) {
1898
+ recs.set(occurrence, rec);
1899
+ sink.slot(occurrence, {
1900
+ ...args
1901
+ });
1902
+ }
1903
+ if (live && live.visit) live.seen(occurrence, () => recs.get(occurrence) === rec && forget(occurrence));
1813
1904
  const ctx = sharedConfig.context;
1814
1905
  for (const b of opened) {
1815
1906
  const key = b.key;
@@ -1817,23 +1908,23 @@ function createSlotProps(sink, frame) {
1817
1908
  openArgBinding(sink, ledgerKey, occurrence, key, b.evaluate, b.state, value => {
1818
1909
  const t = typeof value;
1819
1910
  if (value == null || t === "string" || t === "number" || t === "boolean") {
1820
- args[key] = value;
1911
+ rec.args[key] = value;
1821
1912
  } else {
1822
1913
  const ref = `arg:${occurrence}:${key}@${sink.nextArgRef(ledgerKey)}`;
1823
1914
  sink.mintRef(ref);
1824
- ctx.serialize(ref, argBorderForm(value, key, occurrence, needs));
1825
- args[key] = {
1915
+ ctx.serialize(ref, argBorderForm(value, needs));
1916
+ rec.args[key] = {
1826
1917
  $ref: ref
1827
1918
  };
1828
1919
  }
1920
+ rec.vals[key] = digest(value);
1829
1921
  sink.slot(occurrence, {
1830
- ...args
1922
+ ...rec.args
1831
1923
  });
1832
1924
  });
1833
1925
  }
1834
- const keyed = rk === occurrence;
1835
- const out = slotProxy(slotRange(occurrence), occurrence, SLOT_FACE_STREAM, undefined, rk === undefined || keyed ? undefined : () => repeats.has(rk) || repeats.set(rk, out), needs);
1836
- if (keyed) repeats.set(rk, out);
1926
+ const out = slotRange(occurrence);
1927
+ if (rk !== undefined && rk === occurrence) rmap.set(rk, out);
1837
1928
  return out;
1838
1929
  };
1839
1930
  fn.$lhSkip = true;
@@ -1898,11 +1989,11 @@ function serverComponentResponse(component, options = {}, init = {}) {
1898
1989
  teardown.abort();
1899
1990
  });
1900
1991
  stream.pipe({
1901
- write(chunk) {
1902
- if (chunk.type === "error" && !chunk.key) failed = true;
1992
+ write(message) {
1993
+ if (message.r && ":error" in message.r) failed = true;
1903
1994
  if (closed) return;
1904
1995
  try {
1905
- controller.enqueue(frame(JSON.stringify(chunk)));
1996
+ controller.enqueue(frame(JSON.stringify(message)));
1906
1997
  } catch (_) {
1907
1998
  closed = true;
1908
1999
  }
@@ -2060,10 +2151,10 @@ function frameFlightResponse({
2060
2151
  let closed = false;
2061
2152
  const body = new ReadableStream({
2062
2153
  async start(controller) {
2063
- const write = chunk => {
2154
+ const write = message => {
2064
2155
  if (closed) return;
2065
2156
  try {
2066
- controller.enqueue(createChunk(JSON.stringify(chunk)));
2157
+ controller.enqueue(createChunk(JSON.stringify(message)));
2067
2158
  } catch (_) {
2068
2159
  closed = true;
2069
2160
  }