@solidjs/web 2.0.0-rc.0 → 2.0.0-rc.10

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 (108) hide show
  1. package/README.md +1 -1
  2. package/dist/server.dev.js +4472 -0
  3. package/dist/server.js +1363 -224
  4. package/dist/{server.cjs → server.observe.js} +1563 -424
  5. package/dist/{dev.cjs → web.dev.js} +708 -365
  6. package/dist/web.js +460 -144
  7. package/dist/{dev.js → web.observe.js} +511 -213
  8. package/frames/dist/client.dev.js +464 -72
  9. package/frames/dist/client.js +364 -71
  10. package/frames/dist/{client.dev.cjs → client.observe.js} +487 -134
  11. package/frames/dist/server.dev.js +1713 -0
  12. package/frames/dist/server.js +553 -2495
  13. package/frames/dist/server.observe.js +1713 -0
  14. package/frames/package.json +2 -25
  15. package/package.json +214 -254
  16. package/performance-tracks/dist/performance-tracks.dev.js +678 -0
  17. package/performance-tracks/dist/performance-tracks.js +6 -0
  18. package/performance-tracks/dist/performance-tracks.observe.js +666 -0
  19. package/performance-tracks/package.json +7 -0
  20. package/performance-tracks/types/index.d.ts +67 -0
  21. package/serialization/decode/package.json +2 -15
  22. package/serialization/dist/decode.js +101 -12
  23. package/serialization/dist/serialization.js +112 -20
  24. package/serialization/package.json +2 -15
  25. package/serialization/types/index.d.ts +76 -157
  26. package/serialization/types/serializer-decode.d.ts +149 -112
  27. package/serialization/types/serializer.d.ts +101 -0
  28. package/server-functions/dist/client.dev.js +1364 -0
  29. package/server-functions/dist/client.js +745 -85
  30. package/server-functions/dist/client.observe.js +1343 -0
  31. package/server-functions/dist/server.dev.js +2203 -175
  32. package/server-functions/dist/server.js +2111 -176
  33. package/server-functions/dist/server.observe.js +3043 -0
  34. package/server-functions/package.json +2 -35
  35. package/server-functions/rich-args/package.json +2 -15
  36. package/storage/package.json +2 -15
  37. package/types/client.d.ts +193 -288
  38. package/types/constants.d.ts +20 -0
  39. package/types/cookies.d.ts +32 -84
  40. package/types/diagnostics.d.ts +56 -0
  41. package/types/frames/client.d.ts +1 -1
  42. package/types/frames/frame-client.d.ts +323 -259
  43. package/types/frames/frame-container-plugin.d.ts +72 -0
  44. package/types/frames/frame-sink.d.ts +101 -158
  45. package/types/frames/frame-transport.d.ts +192 -190
  46. package/types/frames/serializer-decode.d.ts +219 -0
  47. package/types/frames/serializer.d.ts +76 -157
  48. package/types/frames/server.d.ts +1 -1
  49. package/types/head.d.ts +19 -0
  50. package/types/index.d.ts +62 -76
  51. package/types/index.server.d.ts +174 -0
  52. package/types/jsx.d.ts +33 -26
  53. package/types/observe.d.ts +358 -0
  54. package/types/reconcile.d.ts +1 -0
  55. package/types/render.d.ts +9 -0
  56. package/types/response.d.ts +75 -150
  57. package/types/serializer-decode.d.ts +149 -112
  58. package/types/serializer.d.ts +76 -157
  59. package/types/server-functions/client.d.ts +202 -174
  60. package/types/server-functions/flash.d.ts +28 -30
  61. package/types/server-functions/registry.d.ts +102 -0
  62. package/types/server-functions/rich-args.d.ts +1 -10
  63. package/types/server-functions/server.d.ts +518 -454
  64. package/types/server-functions/shared.d.ts +366 -425
  65. package/types/server-mock.d.ts +110 -13
  66. package/types/server-observe.d.ts +77 -0
  67. package/types/server.d.ts +425 -425
  68. package/types/trace.d.ts +127 -0
  69. package/LICENSE +0 -21
  70. package/dist/web.cjs +0 -2007
  71. package/frames/dist/client.cjs +0 -1916
  72. package/frames/dist/server.cjs +0 -3667
  73. package/serialization/dist/decode.cjs +0 -110
  74. package/serialization/dist/serialization.cjs +0 -232
  75. package/serialization/types-cjs/index.d.cts +0 -182
  76. package/serialization/types-cjs/package.json +0 -3
  77. package/serialization/types-cjs/serializer-decode.d.cts +0 -182
  78. package/server-functions/dist/client.cjs +0 -646
  79. package/server-functions/dist/rich-args.cjs +0 -11
  80. package/server-functions/dist/server.cjs +0 -1077
  81. package/server-functions/dist/server.dev.cjs +0 -1077
  82. package/storage/dist/storage.cjs +0 -12
  83. package/storage/types-cjs/index.d.cts +0 -28
  84. package/storage/types-cjs/package.json +0 -3
  85. package/types/core.d.ts +0 -6
  86. package/types-cjs/client.d.cts +0 -337
  87. package/types-cjs/cookies.d.cts +0 -93
  88. package/types-cjs/core.d.cts +0 -6
  89. package/types-cjs/frames/client.d.cts +0 -36
  90. package/types-cjs/frames/frame-client.d.cts +0 -338
  91. package/types-cjs/frames/frame-sink.d.cts +0 -194
  92. package/types-cjs/frames/frame-transport.d.cts +0 -222
  93. package/types-cjs/frames/serializer.d.cts +0 -182
  94. package/types-cjs/frames/server.d.cts +0 -52
  95. package/types-cjs/index.d.cts +0 -230
  96. package/types-cjs/jsx-properties.d.cts +0 -93
  97. package/types-cjs/jsx.d.cts +0 -4150
  98. package/types-cjs/package.json +0 -3
  99. package/types-cjs/response.d.cts +0 -174
  100. package/types-cjs/serializer-decode.d.cts +0 -182
  101. package/types-cjs/serializer.d.cts +0 -182
  102. package/types-cjs/server-functions/client.d.cts +0 -201
  103. package/types-cjs/server-functions/flash.d.cts +0 -38
  104. package/types-cjs/server-functions/rich-args.d.cts +0 -10
  105. package/types-cjs/server-functions/server.d.cts +0 -588
  106. package/types-cjs/server-functions/shared.d.cts +0 -523
  107. package/types-cjs/server-mock.d.cts +0 -277
  108. package/types-cjs/server.d.cts +0 -523
@@ -1,11 +1,12 @@
1
- import { getOwner, onCleanup, createMemo, runWithOwner, createSignal, createRenderEffect, createLoadingBoundary, createOwner, sharedConfig, materializeContainerTrace } from 'solid-js';
2
- import { insert } from '@solidjs/web';
3
- import { ChunkReader, frameAddress, SINGLE_FLIGHT_HEADER, deserializeStream, getServerFunctionsCodec, createChunk, getFlightDataConsumer, ERROR_HEADER, REVALIDATE_HEADER, configureServerFunctionsClient } from '@solidjs/web/server-functions/client';
1
+ import { getOwner, onCleanup, createMemo, runWithOwner, createSignal, createRenderEffect, createLoadingBoundary, createOwner, sharedConfig } from 'solid-js';
2
+ import { delegateEvents, insert } from '@solidjs/web';
3
+ import { LIVE_WIRE, isEventStream, ChunkReader, frameAddress, SINGLE_FLIGHT_HEADER, deserializeStream, getServerFunctionsCodec, createChunk, deliverFlightData, ERROR_HEADER, hasFlightMetadata, configureServerFunctionsClient } from '@solidjs/web/server-functions/client';
4
+ import { materializeContainerTrace } from 'solid-js/internal';
4
5
 
5
6
  const ELEMENT_NODE = 1;
6
7
  const TEXT_NODE = 3;
7
8
  const COMMENT_NODE = 8;
8
- const CLAIM_SEAM = Symbol.for("dom-expressions.element-claims");
9
+ const CLAIM_SEAM = Symbol.for("solid.element-claims");
9
10
  const CLAIMED_ELEMENTS = "a[href], form[action]";
10
11
  function claimHandlers() {
11
12
  const handlers = globalThis[CLAIM_SEAM];
@@ -15,6 +16,71 @@ function claimNode(handlers, el) {
15
16
  for (let i = 0; i < handlers.length; i++) handlers[i](el);
16
17
  }
17
18
  const claimedAttr = name => name === "href" || name === "action";
19
+ const BOUND_SEAM = Symbol.for("solid.bnd");
20
+ const boundSeam = globalThis[BOUND_SEAM] || (globalThis[BOUND_SEAM] = {});
21
+ const BND_ATTR = "_bnd";
22
+ const BND_SELECTOR = "[_bnd]";
23
+ function bndMap(el) {
24
+ const s = el.getAttribute(BND_ATTR);
25
+ if (!s) return undefined;
26
+ const map = {};
27
+ for (const entry of s.split(",")) {
28
+ const eq = entry.indexOf("=");
29
+ if (eq < 1) continue;
30
+ const pos = entry.slice(0, eq);
31
+ const prop = decodeURIComponent(entry.slice(eq + 1));
32
+ const prev = map[pos];
33
+ if (prev === undefined) map[pos] = prop;else if (Array.isArray(prev)) prev.push(prop);else map[pos] = [prev, prop];
34
+ }
35
+ return map;
36
+ }
37
+ boundSeam.resolve = (el, type) => {
38
+ const frame = el._$bndFrame;
39
+ if (!frame) return undefined;
40
+ const map = bndMap(el);
41
+ const prop = map && map[type];
42
+ if (typeof prop !== "string") return undefined;
43
+ return claimFn(frame, type, prop);
44
+ };
45
+ function claimFn(frame, pos, prop) {
46
+ const fn = frame.clientProp(prop);
47
+ if (typeof fn === "function") return fn;
48
+ return undefined;
49
+ }
50
+ function sweepBound(root, frame, delegate, scope) {
51
+ const isElement = root.nodeType === ELEMENT_NODE;
52
+ if (!isElement && root.nodeType !== 11 ) return;
53
+ let els;
54
+ if (isElement && root.hasAttribute(BND_ATTR)) (els = []).push(root);
55
+ const found = root.querySelectorAll(BND_SELECTOR);
56
+ if (found.length) {
57
+ els || (els = []);
58
+ for (let i = 0; i < found.length; i++) els.push(found[i]);
59
+ }
60
+ if (!els) return;
61
+ const run = () => {
62
+ let types;
63
+ for (const el of els) {
64
+ el._$bndFrame = frame;
65
+ const map = bndMap(el);
66
+ if (!map) continue;
67
+ for (const pos in map) {
68
+ if (pos === "ref") fireRefs(frame, el, map.ref);else (types || (types = [])).push(pos);
69
+ }
70
+ }
71
+ if (types && delegate) delegate(types);
72
+ };
73
+ scope ? scope(run) : run();
74
+ }
75
+ function fireRefs(frame, el, prop) {
76
+ const fired = el._$bndFired || (el._$bndFired = new Set());
77
+ for (const p of Array.isArray(prop) ? prop : [prop]) {
78
+ if (fired.has(p)) continue;
79
+ fired.add(p);
80
+ const fn = claimFn(frame, "ref", p);
81
+ if (fn) fn(el);
82
+ }
83
+ }
18
84
  function claimTree(handlers, root) {
19
85
  const isElement = root.nodeType === ELEMENT_NODE;
20
86
  if (!isElement && root.nodeType !== 11 ) return;
@@ -35,14 +101,18 @@ function chunkToRecords(chunk) {
35
101
  return {
36
102
  "": {
37
103
  kind: "html",
38
- value: chunk.html
104
+ value: chunk.html,
105
+ digest: chunk.digest,
106
+ holes: chunk.holes
39
107
  }
40
108
  };
41
109
  case "fragment":
42
110
  return {
43
111
  [`seg:${chunk.key}`]: {
44
112
  kind: "html",
45
- value: chunk.html
113
+ value: chunk.html,
114
+ digest: chunk.digest,
115
+ holes: chunk.holes
46
116
  }
47
117
  };
48
118
  case "reveal":
@@ -67,7 +137,9 @@ function chunkToRecords(chunk) {
67
137
  return {
68
138
  [`hole:${chunk.key}`]: {
69
139
  kind: "html",
70
- value: chunk.html
140
+ value: chunk.html,
141
+ digest: chunk.digest,
142
+ holes: chunk.holes
71
143
  }
72
144
  };
73
145
  case "attr":
@@ -75,7 +147,8 @@ function chunkToRecords(chunk) {
75
147
  [`attr:${chunk.key}`]: {
76
148
  kind: "attrs",
77
149
  value: chunk.attrs,
78
- removed: chunk.removed
150
+ removed: chunk.removed,
151
+ digest: chunk.digest
79
152
  }
80
153
  };
81
154
  case "complete":
@@ -110,10 +183,22 @@ function createFrameHost(options = {}) {
110
183
  store.version = version;
111
184
  clearStreamRecords(store.records);
112
185
  }
113
- Object.assign(store.records, records);
186
+ const assets = records["seg::assets"];
187
+ const previous = assets && store.records["seg::assets"];
188
+ if (!previous || previous === assets) {
189
+ Object.assign(store.records, records);
190
+ } else {
191
+ for (const name in assets) {
192
+ const values = assets[name];
193
+ if (Array.isArray(values)) {
194
+ previous[name] ? previous[name].push(...values) : previous[name] = values;
195
+ }
196
+ }
197
+ }
114
198
  return true;
115
199
  };
116
200
  return {
201
+ delegate: options.delegate,
117
202
  register(id, frame) {
118
203
  let set = frames.get(id);
119
204
  if (!set) frames.set(id, set = new Set());
@@ -193,6 +278,7 @@ class FrameImpl {
193
278
  #revealed = new Set();
194
279
  #fallbackShown = new Set();
195
280
  #appliedHoles = new Map();
281
+ #have;
196
282
  #slots;
197
283
  #mountedSlots = new Set();
198
284
  #slotCleanups = new Map();
@@ -201,17 +287,25 @@ class FrameImpl {
201
287
  #slotRegions = new Map();
202
288
  #slotResolvedRefs = new Map();
203
289
  #slotNodes = new Map();
204
- #processedAssets = new Set();
290
+ #processedAssets = new WeakSet();
205
291
  #recordRefresh = null;
206
292
  #disposed = false;
207
293
  #styleFlush = () => {
208
294
  if (!this.#disposed) this.#flush();
209
295
  };
210
296
  #claimTree = (node, direct) => {
297
+ if (!direct && node.nodeType !== TEXT_NODE && node.nodeType !== COMMENT_NODE) {
298
+ const o = this.#options;
299
+ sweepBound(node, this, o.delegate || o.host && o.host.delegate, o.ownerScope);
300
+ }
211
301
  const handlers = claimHandlers();
212
302
  if (!handlers) return;
213
303
  this.#scoped(() => direct ? claimNode(handlers, node) : claimTree(handlers, node));
214
304
  };
305
+ clientProp(name) {
306
+ const props = this.#options.props;
307
+ return props ? props[name] : undefined;
308
+ }
215
309
  #scoped(fn) {
216
310
  const scope = this.#options.ownerScope;
217
311
  return scope ? scope(fn) : fn();
@@ -294,6 +388,7 @@ class FrameImpl {
294
388
  this.#revealed.clear();
295
389
  this.#fallbackShown.clear();
296
390
  this.#appliedHoles.clear();
391
+ this.#processedAssets = new WeakSet();
297
392
  this.#errorNotified = false;
298
393
  clearStreamRecords(this.#store, root);
299
394
  }
@@ -305,6 +400,10 @@ class FrameImpl {
305
400
  const reason = this.#hasContent ? "morph" : "materialize";
306
401
  this.#applyRoot(root.value);
307
402
  this.#appliedRootValue = root.value;
403
+ this.#have = root.digest === undefined ? undefined : {
404
+ "": root.digest,
405
+ ...root.holes
406
+ };
308
407
  this.#applied(version, reason);
309
408
  }
310
409
  if (this.#store[":error"] && !this.#errorNotified) {
@@ -343,22 +442,29 @@ class FrameImpl {
343
442
  this.#appliedHoles.set(key, record);
344
443
  } else if (this.#applyHole(key.slice(5), record.value)) {
345
444
  this.#appliedHoles.set(key, record);
445
+ this.#recordHave(key.slice(5), record);
346
446
  this.#applied(version, "morph");
347
447
  }
348
448
  } else if (key.startsWith("attr:")) {
349
449
  if (this.#applyAttrs(key.slice(5), record.value, record.removed)) {
350
450
  this.#appliedHoles.set(key, record);
451
+ this.#recordHave("lha:" + key.slice(5), record);
351
452
  this.#applied(version, "morph");
352
453
  }
353
454
  }
354
455
  }
355
456
  for (const key in this.#store) {
356
- if (this.#processedAssets.has(key) || !key.endsWith(":assets")) continue;
357
- this.#processedAssets.add(key);
358
457
  const record = this.#store[key];
359
- if (record && record.modules) {
458
+ if (!key.endsWith(":assets") || !record || this.#processedAssets.has(record)) {
459
+ continue;
460
+ }
461
+ this.#processedAssets.add(record);
462
+ if (record.modules) {
360
463
  for (const href of record.modules) ensureModulePreload(href);
361
464
  }
465
+ if (record.preloads) {
466
+ for (const entry of record.preloads) ensurePreload(entry);
467
+ }
362
468
  }
363
469
  this.#syncSlots();
364
470
  }
@@ -633,6 +739,14 @@ class FrameImpl {
633
739
  rebase() {
634
740
  this.#version = undefined;
635
741
  }
742
+ have() {
743
+ return this.#have;
744
+ }
745
+ #recordHave(key, record) {
746
+ if (!this.#have || !record || record.digest === undefined) return;
747
+ this.#have[key] = record.digest;
748
+ if (record.holes) Object.assign(this.#have, record.holes);
749
+ }
636
750
  dispose() {
637
751
  if (this.#disposed) return;
638
752
  const {
@@ -660,7 +774,7 @@ class FrameImpl {
660
774
  parent.insertBefore(fragment, this.#end);
661
775
  this.#hasContent = true;
662
776
  } else {
663
- const claim = claimHandlers() ? this.#claimTree : null;
777
+ const claim = this.#claimTree;
664
778
  const ranges = new Map();
665
779
  this.#collectSlots(ranges);
666
780
  const grafts = [];
@@ -676,8 +790,7 @@ class FrameImpl {
676
790
  if (!close) {
677
791
  return false;
678
792
  }
679
- const claim = claimHandlers() ? this.#claimTree : null;
680
- reconcileChildren(open.parentNode, parseFragment(html), open, close, claim);
793
+ reconcileChildren(open.parentNode, parseFragment(html), open, close, this.#claimTree);
681
794
  return true;
682
795
  }
683
796
  #applyAttrs(addr, text, removed) {
@@ -685,23 +798,30 @@ class FrameImpl {
685
798
  const el = findLiveTarget(this.#firstContent(), this.#end, n => n.nodeType === ELEMENT_NODE && n.getAttribute("data-lha") === addr);
686
799
  if (!el) return false;
687
800
  const parsed = parseFragment(`<i${text}></i>`).firstChild;
801
+ const keepOpen = preservesOpen(el);
802
+ const current = el.attributes;
803
+ for (let i = current.length - 1; i >= 0; i--) {
804
+ const name = current[i].name;
805
+ if (name === "data-lha" || keepOpen && name === "open") continue;
806
+ if (!parsed || !parsed.hasAttribute(name)) el.removeAttribute(name);
807
+ }
688
808
  if (parsed) {
689
809
  for (let i = 0; i < parsed.attributes.length; i++) {
690
810
  const {
691
811
  name,
692
812
  value
693
813
  } = parsed.attributes[i];
814
+ if (keepOpen && name === "open") continue;
694
815
  if (el.getAttribute(name) !== value) el.setAttribute(name, value);
695
816
  }
696
817
  }
697
- if (removed) for (const name of removed) el.removeAttribute(name);
818
+ if (removed) for (const name of removed) if (!(keepOpen && name === "open")) el.removeAttribute(name);
698
819
  return true;
699
820
  }
700
821
  #clearContent() {
701
822
  removeUntil(this.#parent(), this.#firstContent(), this.#end);
702
823
  }
703
824
  #claimContent() {
704
- if (!claimHandlers()) return;
705
825
  let n = this.#firstContent();
706
826
  while (n && n !== this.#end) {
707
827
  this.#claimTree(n);
@@ -745,6 +865,7 @@ class FrameImpl {
745
865
  });
746
866
  tpl.remove();
747
867
  this.#revealed.add(name);
868
+ this.#recordHave(name, content);
748
869
  return;
749
870
  }
750
871
  const materialized = this.#materialize(content);
@@ -753,6 +874,7 @@ class FrameImpl {
753
874
  tpl.remove();
754
875
  closing && closing.remove();
755
876
  this.#revealed.add(name);
877
+ this.#recordHave(name, content);
756
878
  }
757
879
  #showFallback(name) {
758
880
  const tpl = this.#findPlaceholder(name);
@@ -771,7 +893,7 @@ class FrameImpl {
771
893
  function createFrame(boundary, options) {
772
894
  return new FrameImpl(boundary, null, null, options);
773
895
  }
774
- const FRAME_TAG = "dx-frame";
896
+ const FRAME_TAG = "solid-frame";
775
897
  const FRAME_ID_ATTR = "data-fid";
776
898
  function createFrameElement(options) {
777
899
  const el = makeFrameElement(options.id);
@@ -828,12 +950,36 @@ function parseFragment(html) {
828
950
  template.innerHTML = html;
829
951
  return template.content;
830
952
  }
831
- function findHeadElement(selector, attr, value) {
832
- for (const node of document.head.querySelectorAll(selector)) {
833
- if (node.getAttribute(attr) === value) return node;
953
+ const PRELOAD_QUALIFIERS = ["as", "crossorigin", "type", "media", "imagesrcset", "imagesizes"];
954
+ function qualifierValue(name, value) {
955
+ if (value == null) return null;
956
+ if (name === "imagesrcset" || name === "imagesizes") return value === "" ? null : value;
957
+ if (name === "as") return value.replace(/[A-Z]/g, c => String.fromCharCode(c.charCodeAt(0) + 32));
958
+ if (name !== "crossorigin") return value;
959
+ return value.length === 15 && value.toLowerCase() === "use-credentials" ? "use-credentials" : "anonymous";
960
+ }
961
+ function findHeadElement(selector, attr, value, qualifiers) {
962
+ candidate: for (const node of document.head.querySelectorAll(selector)) {
963
+ if (node.getAttribute(attr) !== value) continue;
964
+ if (!qualifiers) return node;
965
+ for (let i = 0; i < PRELOAD_QUALIFIERS.length; i++) {
966
+ const name = PRELOAD_QUALIFIERS[i];
967
+ if (qualifierValue(name, node.getAttribute(name)) !== qualifierValue(name, qualifiers[name] ?? null)) continue candidate;
968
+ }
969
+ return node;
834
970
  }
835
971
  return null;
836
972
  }
973
+ function ensurePreload(entry) {
974
+ const attrs = entry.attrs;
975
+ const href = entry.href;
976
+ if (findHeadElement('link[rel="preload"]', "href", href || null, attrs)) return;
977
+ const link = document.createElement("link");
978
+ link.rel = "preload";
979
+ for (const name in attrs) link.setAttribute(name, attrs[name]);
980
+ if (href) link.setAttribute("href", href);
981
+ document.head.appendChild(link);
982
+ }
837
983
  function ensureStylesheet(entry, onSettle) {
838
984
  const href = typeof entry === "string" ? entry : entry.href;
839
985
  let link = findHeadElement('link[rel="stylesheet"]', "href", href);
@@ -993,7 +1139,7 @@ function isSlotMarker(node) {
993
1139
  }
994
1140
  function compatible(a, b) {
995
1141
  if (a.nodeType !== b.nodeType) return false;
996
- if (a.nodeType === ELEMENT_NODE) return a.nodeName === b.nodeName;
1142
+ if (a.nodeType === ELEMENT_NODE) return a.nodeName === b.nodeName && a.getAttribute("_key") === b.getAttribute("_key");
997
1143
  return a.nodeType === TEXT_NODE || a.nodeType === COMMENT_NODE;
998
1144
  }
999
1145
  function preservesOpen(el) {
@@ -1198,37 +1344,99 @@ function stashRange(frag, start, id) {
1198
1344
  }
1199
1345
 
1200
1346
  const FRAME_STREAM_HEADER = "X-Frame-Stream";
1347
+ const FRAME_HAVE_HEADER = "X-Frame-Have";
1348
+ const FRAME_HAVE_BUDGET = 4096;
1349
+ function encodeHaveList(have) {
1350
+ let out = "";
1351
+ for (const key in have) {
1352
+ const digest = have[key];
1353
+ if (typeof digest !== "string") continue;
1354
+ out += (out ? "," : "") + key + "=" + digest;
1355
+ if (out.length > FRAME_HAVE_BUDGET) return undefined;
1356
+ }
1357
+ return out || undefined;
1358
+ }
1201
1359
  function isFrameStreamResponse(response) {
1202
1360
  return response.headers.has(FRAME_STREAM_HEADER);
1203
1361
  }
1204
- async function applyFrameResponse(response, host, options = {}) {
1362
+ const applyFrameResponse = applyFrames;
1363
+ function applyFrames(response, host, options = {}, observation) {
1205
1364
  const rootId = response.headers.get(FRAME_STREAM_HEADER) ?? "";
1206
1365
  const as = options.as;
1207
1366
  const version = options.version;
1208
1367
  const perFrame = typeof version === "function" ? new Map() : null;
1209
- const reader = new ChunkReader(response.body);
1210
- let result = await reader.next();
1211
- while (!result.done) {
1212
- const chunk = JSON.parse(result.value);
1213
- if (chunk.type === "outcome") {
1214
- if (options.onOutcome) options.onOutcome(chunk.payload);
1215
- } else {
1216
- if (as !== undefined && chunk.id === rootId) chunk.id = as;
1217
- if (perFrame) {
1218
- let v = perFrame.get(chunk.id);
1219
- if (v === undefined) perFrame.set(chunk.id, v = version(chunk.id));
1220
- chunk.version = v;
1221
- } else if (version !== undefined) chunk.version = version;
1222
- if (chunk.type === "data" && host.prepareData) await host.prepareData();
1223
- host.apply(chunk);
1224
- }
1225
- result = await reader.next();
1226
- }
1227
- return as !== undefined ? as : rootId;
1228
- }
1229
- const SERVER_COMPONENT = /*#__PURE__*/Symbol.for("dom-expressions.server-component");
1230
- const SERVER_COMPONENT_ADDRESS = /*#__PURE__*/Symbol.for("dom-expressions.server-component-address");
1231
- const COMPONENT_BINDING = /*#__PURE__*/Symbol.for("dom-expressions.component-binding");
1368
+ const wire = options[LIVE_WIRE];
1369
+ const connection = wire && wire.connection;
1370
+ const reader = wire && isEventStream(response) ? wire.open(response.body) : new ChunkReader(response.body);
1371
+ const open = new Map();
1372
+ let cancelled;
1373
+ let resolveEnd;
1374
+ if (connection) {
1375
+ connection.ended = new Promise(resolve => resolveEnd = resolve);
1376
+ connection.cancel = reason => {
1377
+ if (cancelled !== undefined) return;
1378
+ cancelled = reason;
1379
+ try {
1380
+ const r = reader.cancel && reader.cancel(reason);
1381
+ if (r && typeof r.then === "function") r.then(undefined, () => {});
1382
+ } catch {}
1383
+ };
1384
+ }
1385
+ const errorRecord = (id, error) => ({
1386
+ type: "error",
1387
+ id,
1388
+ version: open.get(id),
1389
+ error: {
1390
+ message: String(error && error.message)
1391
+ }
1392
+ });
1393
+ const drain = async () => {
1394
+ let result = await reader.next();
1395
+ while (!result.done) {
1396
+ const chunk = JSON.parse(result.value);
1397
+ if (chunk.type === "outcome") {
1398
+ if (options.onOutcome) options.onOutcome(chunk.payload);
1399
+ } else {
1400
+ chunk.id;
1401
+ if (as !== undefined && chunk.id === rootId) chunk.id = as;
1402
+ if (perFrame) {
1403
+ let v = perFrame.get(chunk.id);
1404
+ if (v === undefined) perFrame.set(chunk.id, v = version(chunk.id));
1405
+ chunk.version = v;
1406
+ } else if (version !== undefined) chunk.version = version;
1407
+ if (chunk.type === "start") open.set(chunk.id, chunk.version);else if (chunk.type === "complete" || chunk.type === "error" && !chunk.key) open.delete(chunk.id);
1408
+ if (chunk.type === "data" && host.prepareData) await host.prepareData();
1409
+ host.apply(chunk);
1410
+ }
1411
+ result = await reader.next();
1412
+ }
1413
+ };
1414
+ const end = error => {
1415
+ const dead = error || cancelled || new Error("Frame stream ended before the frame completed.");
1416
+ const sweep = () => {
1417
+ for (const id of open.keys()) host.apply(errorRecord(id, dead));
1418
+ };
1419
+ if (connection) {
1420
+ connection.done = true;
1421
+ resolveEnd({
1422
+ open: open.size,
1423
+ error: dead,
1424
+ sweep,
1425
+ close: () => {}
1426
+ });
1427
+ } else if (error === undefined) sweep();
1428
+ };
1429
+ return drain().then(() => {
1430
+ end(undefined);
1431
+ return as !== undefined ? as : rootId;
1432
+ }, error => {
1433
+ end(error);
1434
+ throw error;
1435
+ });
1436
+ }
1437
+ const SERVER_COMPONENT = /*#__PURE__*/Symbol.for("solid.server-component");
1438
+ const SERVER_COMPONENT_ADDRESS = /*#__PURE__*/Symbol.for("solid.server-component-address");
1439
+ const COMPONENT_BINDING = /*#__PURE__*/Symbol.for("solid.component-binding");
1232
1440
  let resolveServerComponent;
1233
1441
  function parseServerComponent(value, ctx) {
1234
1442
  return {
@@ -1237,7 +1445,7 @@ function parseServerComponent(value, ctx) {
1237
1445
  };
1238
1446
  }
1239
1447
  const ServerComponentPlugin = {
1240
- tag: "dom-expressions/server-component",
1448
+ tag: "solid/server-component",
1241
1449
  test(value) {
1242
1450
  return typeof value === "function" && SERVER_COMPONENT in value;
1243
1451
  },
@@ -1276,9 +1484,7 @@ function createServerComponentHandler({
1276
1484
  host,
1277
1485
  component,
1278
1486
  onStream,
1279
- intercept,
1280
- consumer = getFlightDataConsumer,
1281
- codec = getServerFunctionsCodec
1487
+ intercept
1282
1488
  }) {
1283
1489
  const byFn = new Map();
1284
1490
  const componentFor = fnId => {
@@ -1302,17 +1508,45 @@ function createServerComponentHandler({
1302
1508
  };
1303
1509
  resolveServerComponent = (id, address) => bindingFor(address, id);
1304
1510
  const versions = new Map();
1511
+ const connections = new Map();
1305
1512
  const bump = address => {
1306
1513
  const version = (versions.get(address) || 0) + 1;
1307
1514
  versions.set(address, version);
1515
+ const connection = connections.get(address);
1516
+ if (connection) {
1517
+ connections.delete(address);
1518
+ connection.cancel(new Error("Superseded by a newer response for the address."));
1519
+ }
1308
1520
  return version;
1309
1521
  };
1522
+ const hold = (address, connection) => {
1523
+ connections.set(address, connection);
1524
+ connection.ended.then(() => {
1525
+ if (connections.get(address) === connection) connections.delete(address);
1526
+ });
1527
+ };
1310
1528
  return {
1311
1529
  intercept: intercept && (info => {
1312
1530
  const hit = intercept(info);
1313
1531
  if (hit === undefined) return undefined;
1314
- return bindingFor(frameAddress(info.id, info.args), info.id);
1532
+ const binding = () => bindingFor(frameAddress(info.id, info.args), info.id);
1533
+ if (typeof hit.then === "function") return hit.then(landed => landed ? binding() : undefined);
1534
+ return binding();
1315
1535
  }),
1536
+ resume(info) {
1537
+ const address = frameAddress(info.id, info.args);
1538
+ const version = versions.get(address);
1539
+ const frame = host.get(address);
1540
+ const have = frame && frame.have ? frame.have() : undefined;
1541
+ if (version === undefined && !have) return undefined;
1542
+ const encoded = have && encodeHaveList(have);
1543
+ return {
1544
+ position: String(version || 0),
1545
+ headers: encoded ? {
1546
+ [FRAME_HAVE_HEADER]: encoded
1547
+ } : undefined
1548
+ };
1549
+ },
1316
1550
  handle(response, ctx) {
1317
1551
  if (!isFrameStreamResponse(response)) return undefined;
1318
1552
  const address = frameAddress(ctx.id, ctx.args);
@@ -1320,6 +1554,26 @@ function createServerComponentHandler({
1320
1554
  if (response.headers.has(SINGLE_FLIGHT_HEADER)) {
1321
1555
  return applyFlightResponse(response, address, binding);
1322
1556
  }
1557
+ const wire = ctx[LIVE_WIRE];
1558
+ const connection = wire && wire.connection;
1559
+ if (connection) {
1560
+ const current = connections.get(address);
1561
+ if (current && !current.done) {
1562
+ connection.ended = current.ended;
1563
+ const body = response.body;
1564
+ if (body) body.cancel().catch(() => {});
1565
+ return binding;
1566
+ }
1567
+ const version = bump(address);
1568
+ if (onStream) onStream(address, version, response);
1569
+ applyFrameResponse(response, host, {
1570
+ as: address,
1571
+ version,
1572
+ [LIVE_WIRE]: wire
1573
+ }).catch(() => {});
1574
+ hold(address, connection);
1575
+ return binding;
1576
+ }
1323
1577
  const version = bump(address);
1324
1578
  if (onStream) onStream(address, version, response);
1325
1579
  applyFrameResponse(response, host, {
@@ -1355,7 +1609,7 @@ function createServerComponentHandler({
1355
1609
  feed = controller;
1356
1610
  }
1357
1611
  });
1358
- const payload = deserializeStream(new Response(source), flightCodec(codec()));
1612
+ const payload = deserializeStream(new Response(source), flightCodec(getServerFunctionsCodec()));
1359
1613
  let carried = false;
1360
1614
  await applyFrameResponse(response, host, {
1361
1615
  as,
@@ -1372,18 +1626,15 @@ function createServerComponentHandler({
1372
1626
  feed.close();
1373
1627
  if (!carried) throw new Error("Single-flight frame response carried no outcome");
1374
1628
  const envelope = await payload;
1375
- const deliver = consumer();
1376
- if (deliver) await deliver(envelope.data, {
1377
- response
1378
- });
1379
- if (response.headers.has(ERROR_HEADER) && !response.headers.has("Location") && !response.headers.has(REVALIDATE_HEADER)) {
1629
+ await deliverFlightData(response, envelope.data);
1630
+ if (response.headers.has(ERROR_HEADER) && !hasFlightMetadata(response)) {
1380
1631
  throw envelope.value;
1381
1632
  }
1382
1633
  return rootId ? binding : envelope.value;
1383
1634
  }
1384
1635
  }
1385
1636
 
1386
- const STATE = Symbol.for("dom-expressions.container-trace-state");
1637
+ const STATE = Symbol.for("solid.container-trace-state");
1387
1638
  const state = globalThis[STATE] || (globalThis[STATE] = {
1388
1639
  materialized: new WeakMap(),
1389
1640
  materializedValues: new WeakSet()
@@ -1404,7 +1655,9 @@ function isMaterializedContainer(value) {
1404
1655
  return value !== null && typeof value === "object" && state.materializedValues.has(value);
1405
1656
  }
1406
1657
  function isContainerTraceMarker(value) {
1407
- return value != null && typeof value === "object" && value.$tr != null && typeof value.$tr[Symbol.asyncIterator] === "function";
1658
+ if (value == null || typeof value !== "object" || value.$tr == null) return false;
1659
+ const tr = value.$tr;
1660
+ return tr.__SEROVAL_STREAM__ === true || typeof tr[Symbol.asyncIterator] === "function";
1408
1661
  }
1409
1662
  function reviveContainerTraces(value) {
1410
1663
  if (!state.materializeTrace || value == null || typeof value !== "object") return value;
@@ -1450,7 +1703,8 @@ function getFrameHost() {
1450
1703
  applyData: c => tableFor(c.id)?.apply(c),
1451
1704
  resolve: (ref, id) => tableFor(id)?.resolve(ref),
1452
1705
  revive: reviveContainerTraces,
1453
- isContainer: isMaterializedContainer
1706
+ isContainer: isMaterializedContainer,
1707
+ delegate: delegateEvents
1454
1708
  });
1455
1709
  }
1456
1710
  return sharedHost;
@@ -1526,7 +1780,16 @@ function slotArgsProxy(args) {
1526
1780
  if (!isAsyncValue(v)) return v;
1527
1781
  let read = asyncReads.get(key);
1528
1782
  if (!read) {
1529
- const make = () => createMemo(() => args()[key]);
1783
+ const make = () => createMemo(() => {
1784
+ const raw = args()[key];
1785
+ if (raw != null && typeof raw.then === "function") {
1786
+ if (raw.s === 1) return raw.v;
1787
+ if (raw.s === 2) throw raw.v;
1788
+ }
1789
+ return raw;
1790
+ }, {
1791
+ transparent: true
1792
+ });
1530
1793
  read = owner ? runWithOwner(owner, make) : make();
1531
1794
  asyncReads.set(key, read);
1532
1795
  }
@@ -1645,6 +1908,7 @@ function boundaryComponent(host, fnId) {
1645
1908
  host,
1646
1909
  id,
1647
1910
  slots: slotsFor(props),
1911
+ props,
1648
1912
  ownerScope: boundaryScope(owner),
1649
1913
  reveal: revealSeam(owner),
1650
1914
  onApply: () => {
@@ -1708,6 +1972,19 @@ function findBoundaryElement(id) {
1708
1972
  return boundaryIndex.get(id);
1709
1973
  }
1710
1974
  const boundaryWaiters = new Map();
1975
+ const arrivals = new Map();
1976
+ function awaitBoundary(id) {
1977
+ let arrival = arrivals.get(id);
1978
+ if (!arrival) {
1979
+ let resolve;
1980
+ const promise = new Promise(r => resolve = r);
1981
+ arrivals.set(id, arrival = {
1982
+ promise,
1983
+ resolve
1984
+ });
1985
+ }
1986
+ return arrival.promise;
1987
+ }
1711
1988
  function boundaryMayArrive() {
1712
1989
  const hy = globalThis._$HY;
1713
1990
  if (!hy) return false;
@@ -1721,7 +1998,7 @@ function installRevealHook() {
1721
1998
  if (!boundaryIndex) return;
1722
1999
  const root = parent || (typeof document !== "undefined" ? document.body : null);
1723
2000
  if (root) indexBoundaries(root);
1724
- if (!boundaryWaiters.size) return;
2001
+ if (!boundaryWaiters.size && !arrivals.size) return;
1725
2002
  const exhausted = hy.done && !hy.fr.pending();
1726
2003
  for (const [id, notify] of boundaryWaiters) {
1727
2004
  const el = boundaryIndex && boundaryIndex.get(id);
@@ -1729,6 +2006,12 @@ function installRevealHook() {
1729
2006
  boundaryWaiters.delete(id);
1730
2007
  notify(el);
1731
2008
  }
2009
+ for (const [id, arrival] of arrivals) {
2010
+ const el = boundaryIndex && boundaryIndex.get(id);
2011
+ if (!el && !exhausted) continue;
2012
+ arrivals.delete(id);
2013
+ arrival.resolve(!!el);
2014
+ }
1732
2015
  });
1733
2016
  }
1734
2017
  function documentBoundary(host, id, props, binding) {
@@ -1829,6 +2112,7 @@ function adoptBoundary(host, id, el, props, binding) {
1829
2112
  host,
1830
2113
  id: address,
1831
2114
  slots: slotsFor(props),
2115
+ props,
1832
2116
  ownerScope: boundaryScope(owner),
1833
2117
  reveal: revealSeam(owner),
1834
2118
  onApply: () => {
@@ -1870,12 +2154,18 @@ function installServerComponents(host = getFrameHost()) {
1870
2154
  g._$SC = {
1871
2155
  c: {},
1872
2156
  a: {},
2157
+ b: {},
1873
2158
  r(i, a) {
1874
- if (a) {
1875
- g._$SC.a[a] = i;
1876
- g._$SC.reg && g._$SC.reg(a, i);
1877
- }
1878
- return g._$SC.c[i] || (g._$SC.c[i] = (p, b) => g._$SC.impl(i, p, b));
2159
+ const c = g._$SC.c[i] || (g._$SC.c[i] = (p, b) => g._$SC.impl(i, p, b));
2160
+ if (!a) return c;
2161
+ g._$SC.a[a] = i;
2162
+ g._$SC.reg && g._$SC.reg(a, i);
2163
+ return g._$SC.b[a] || (g._$SC.b[a] = Object.assign(p => c(p, () => a), {
2164
+ [COMPONENT_BINDING]: {
2165
+ component: c,
2166
+ address: a
2167
+ }
2168
+ }));
1879
2169
  }
1880
2170
  };
1881
2171
  }
@@ -1888,8 +2178,11 @@ function installServerComponents(host = getFrameHost()) {
1888
2178
  intercept: ({
1889
2179
  id
1890
2180
  }) => {
1891
- if (claimedBoundaries.has(id) || !findBoundaryElement(id)) return undefined;
1892
- return g._$SC.r(id);
2181
+ if (claimedBoundaries.has(id)) return undefined;
2182
+ if (findBoundaryElement(id)) return true;
2183
+ if (!boundaryMayArrive()) return undefined;
2184
+ installRevealHook();
2185
+ return awaitBoundary(id);
1893
2186
  }
1894
2187
  });
1895
2188
  const showing = (address, id) => handler.showing(address, id);
@@ -1901,4 +2194,4 @@ function installServerComponents(host = getFrameHost()) {
1901
2194
  });
1902
2195
  }
1903
2196
 
1904
- export { FRAME_APPLIED_EVENT, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents, isFrameStreamResponse };
2197
+ export { FRAME_APPLIED_EVENT, FRAME_HAVE_BUDGET, FRAME_HAVE_HEADER, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents, isFrameStreamResponse };