@torpor/view 1.2.5 → 1.3.0

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 (44) hide show
  1. package/dist/{AsyncOptions-ClS1_ERX.d.mts → AsyncOptions-BDtArmeL.d.mts} +2 -8
  2. package/dist/AsyncOptions-BDtArmeL.d.mts.map +1 -0
  3. package/dist/{AsyncOptions-BtMe2PAd.d.cts → AsyncOptions-C_7mWR6F.d.cts} +2 -8
  4. package/dist/AsyncOptions-C_7mWR6F.d.cts.map +1 -0
  5. package/dist/{Effect-DazmAdyC.d.mts → Effect-99HYQdzZ.d.mts} +50 -33
  6. package/dist/Effect-99HYQdzZ.d.mts.map +1 -0
  7. package/dist/{Effect-Dewn7MLc.d.cts → Effect-Bf8fz_zC.d.cts} +50 -33
  8. package/dist/Effect-Bf8fz_zC.d.cts.map +1 -0
  9. package/dist/compile.cjs +1509 -120
  10. package/dist/compile.d.cts +268 -1
  11. package/dist/compile.d.cts.map +1 -1
  12. package/dist/compile.d.mts +268 -1
  13. package/dist/compile.d.mts.map +1 -1
  14. package/dist/compile.mjs +1506 -121
  15. package/dist/compile.mjs.map +1 -1
  16. package/dist/dev.d.cts +1 -1
  17. package/dist/dev.d.mts +1 -1
  18. package/dist/{fromWebSocket-DrN-IduP.cjs → fromWebSocket-Cdoghvmh.cjs} +15 -0
  19. package/dist/{fromWebSocket-CFGoMkV2.mjs → fromWebSocket-ERhd9KZR.mjs} +11 -2
  20. package/dist/fromWebSocket-ERhd9KZR.mjs.map +1 -0
  21. package/dist/index.cjs +223 -158
  22. package/dist/index.d.cts +24 -8
  23. package/dist/index.d.cts.map +1 -1
  24. package/dist/index.d.mts +24 -8
  25. package/dist/index.d.mts.map +1 -1
  26. package/dist/index.mjs +223 -158
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/runtime.iife.js +1 -0
  29. package/dist/slotAutoClose-BbKfzpkz.cjs +177 -0
  30. package/dist/slotAutoClose-CgDkf8fM.mjs +156 -0
  31. package/dist/slotAutoClose-CgDkf8fM.mjs.map +1 -0
  32. package/dist/ssr.cjs +57 -3
  33. package/dist/ssr.d.cts +53 -2
  34. package/dist/ssr.d.cts.map +1 -1
  35. package/dist/ssr.d.mts +53 -2
  36. package/dist/ssr.d.mts.map +1 -1
  37. package/dist/ssr.mjs +51 -2
  38. package/dist/ssr.mjs.map +1 -1
  39. package/package.json +8 -5
  40. package/dist/AsyncOptions-BtMe2PAd.d.cts.map +0 -1
  41. package/dist/AsyncOptions-ClS1_ERX.d.mts.map +0 -1
  42. package/dist/Effect-DazmAdyC.d.mts.map +0 -1
  43. package/dist/Effect-Dewn7MLc.d.cts.map +0 -1
  44. package/dist/fromWebSocket-CFGoMkV2.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as devContext } from "./devContext-ZNsPyOgB.mjs";
2
- import { a as buildStyles, c as proxyDataSymbol, i as formatText, n as fromServer, o as buildClasses, r as fromElement, s as $unwrap, t as fromWebSocket } from "./fromWebSocket-CFGoMkV2.mjs";
2
+ import { a as buildStyles, c as proxyDataSymbol, i as formatText, l as proxyKeysSymbol, n as fromServer, o as buildClasses, r as fromElement, s as $unwrap, t as fromWebSocket } from "./fromWebSocket-ERhd9KZR.mjs";
3
3
  //#region src/render/context.ts
4
4
  const CONTEXT_SYMBOL = Symbol.for("torp.Context");
5
5
  const context = globalThis[CONTEXT_SYMBOL] ??= {
@@ -46,6 +46,92 @@ function addEvent(el, type, listener) {
46
46
  });
47
47
  }
48
48
  //#endregion
49
+ //#region src/render/isTextNode.ts
50
+ function isTextNode(node) {
51
+ return node.nodeType === 3;
52
+ }
53
+ const HYDRATION_BREAK_REGEX = /^\^(?:\d+)?$/;
54
+ /**
55
+ * Whether a comment node's data is a branch-break marker (`^`, or `^<index>`
56
+ * when the server recorded the branch it rendered).
57
+ */
58
+ function isHydrationBreak(data) {
59
+ return HYDRATION_BREAK_REGEX.test(data);
60
+ }
61
+ /**
62
+ * The branch index encoded in a `^<index>` branch-break marker, or `undefined`
63
+ * for a plain `^` marker (e.g. from `@for`, which has no branch index).
64
+ */
65
+ function hydrationBreakIndex(data) {
66
+ if (!data.startsWith("^") || data.length === 1) return;
67
+ const index = Number(data.slice(1));
68
+ return Number.isNaN(index) ? void 0 : index;
69
+ }
70
+ //#endregion
71
+ //#region src/render/isCommentNode.ts
72
+ function isCommentNode(node) {
73
+ return node.nodeType === 8;
74
+ }
75
+ //#endregion
76
+ //#region src/render/nodeCheckHydrationBreak.ts
77
+ /**
78
+ * When hydrating, removes and skips hydration comments that are inserted at the
79
+ * start of branches and used to split up text nodes that would otherwise be
80
+ * joined in HTML.
81
+ *
82
+ * @param node The node to check and maybe skip.
83
+ * @returns The next node.
84
+ */
85
+ function nodeCheckHydrationBreak(node) {
86
+ if (node !== null && isCommentNode(node) && isHydrationBreak(node.data)) {
87
+ let comment = node;
88
+ node = node.nextSibling;
89
+ comment.remove();
90
+ }
91
+ context.hydrationNode = node;
92
+ return node;
93
+ }
94
+ //#endregion
95
+ //#region src/render/nodeNext.ts
96
+ /**
97
+ * Gets the next sibling of a node.
98
+ *
99
+ * When hydrating, sets the hydration node.
100
+ *
101
+ * @param node The node.
102
+ * @param text Whether we require a text node.
103
+ */
104
+ function nodeNext(node, text = false) {
105
+ if (context.hydrationNode !== null) {
106
+ if (text && isTextNode(node)) return node;
107
+ let next = nodeCheckHydrationBreak(node.nextSibling);
108
+ while (!text && next !== null && isTextNode(next) && next.textContent?.trim() === "") next = nodeCheckHydrationBreak(next.nextSibling);
109
+ if (!text && next !== null && next.nodeName === "TBODY" && next.firstChild && isTextNode(node)) {
110
+ next = next.firstChild;
111
+ context.hydrationNode = next;
112
+ }
113
+ return next;
114
+ }
115
+ return node.nextSibling;
116
+ }
117
+ //#endregion
118
+ //#region src/dev/devAssert.ts
119
+ /**
120
+ * Throws when `condition` is false — but only when dev mode is enabled (the
121
+ * dev-tools build calls `setDevMode`). Used for invariant checks on the
122
+ * runtime's implicit state machines (the batch counter, the signal update
123
+ * chain, the `$async` settle latch): violations mean the machine's
124
+ * bookkeeping is corrupt, and failing loudly in dev beats silently leaking
125
+ * subscriptions or dropping settles in ways that only show up as subtle UI
126
+ * glitches later. Production builds pay one boolean read per check.
127
+ *
128
+ * @param condition The invariant to hold.
129
+ * @param message What the violation means — the thrown error's message.
130
+ */
131
+ function devAssert(condition, message) {
132
+ if (devContext.enabled && !condition) throw new Error(message);
133
+ }
134
+ //#endregion
49
135
  //#region src/watch/clearSources.ts
50
136
  /**
51
137
  * Clear unused source subscriptions after each Computed or Effect has been run.
@@ -315,6 +401,7 @@ function triggerEffects() {
315
401
  //#endregion
316
402
  //#region src/watch/batchEnd.ts
317
403
  function batchEnd() {
404
+ devAssert(context.batch > 0, "batchEnd called without a matching batchStart");
318
405
  if (context.batch > 1) {
319
406
  context.batch--;
320
407
  return;
@@ -839,6 +926,7 @@ function addElement(node, parent, before) {
839
926
  parent = before?.parentNode ?? parent;
840
927
  if (hydrationNode === null) parent.insertBefore(node, before);
841
928
  runMountSideEffects(parent, activeRegion, hydrationNode);
929
+ if (hydrationNode !== null) nodeNext(node);
842
930
  }
843
931
  //#endregion
844
932
  //#region src/render/addFragment.ts
@@ -855,6 +943,7 @@ function addFragment(fragment, parent, before, endNode, startNode) {
855
943
  parent = before?.parentNode ?? parent;
856
944
  if (hydrationNode === null) parent.insertBefore(fragment, before);
857
945
  runMountSideEffects(parent, activeRegion, hydrationNode);
946
+ if (hydrationNode !== null && endNode !== void 0) nodeNext(endNode);
858
947
  }
859
948
  //#endregion
860
949
  //#region src/render/applyProps.ts
@@ -965,19 +1054,6 @@ function releaseRegion(region) {
965
1054
  region.effects.length = 0;
966
1055
  }
967
1056
  //#endregion
968
- //#region src/render/clearLayoutSlot.ts
969
- /**
970
- * Clears a region that was created by `fillLayoutSlot`: tears down the
971
- * rendered content and its effects, leaving the surrounding layout intact
972
- * so the slot can be refilled.
973
- *
974
- * @param region The region to clear
975
- */
976
- function clearLayoutSlot(region) {
977
- context.previousRegion = region.previousRegion;
978
- clearRegion(region);
979
- }
980
- //#endregion
981
1057
  //#region src/render/newRegion.ts
982
1058
  function newRegion(name) {
983
1059
  return {
@@ -1017,6 +1093,17 @@ function pushRegion(region, toParent = false) {
1017
1093
  }
1018
1094
  //#endregion
1019
1095
  //#region src/render/fillLayoutSlot.ts
1096
+ const refillDepths = /* @__PURE__ */ new WeakMap();
1097
+ /**
1098
+ * Records the depth of a cleared layout-slot region for the fill that replaces
1099
+ * it (see `clearLayoutSlot`).
1100
+ *
1101
+ * @param parent The node the slot renders into
1102
+ * @param depth The cleared region's depth
1103
+ */
1104
+ function rememberSlotRefillDepth(parent, depth) {
1105
+ refillDepths.set(parent, depth);
1106
+ }
1020
1107
  /**
1021
1108
  * Renders a component into a persistent layout slot, and returns the region
1022
1109
  * it was rendered into. Used by the layout engine during navigation: the
@@ -1035,12 +1122,31 @@ function pushRegion(region, toParent = false) {
1035
1122
  function fillLayoutSlot(component, slot, parent, anchor, $props, $context) {
1036
1123
  const region = newRegion(devContext.enabled ? "Layout slot" : void 0);
1037
1124
  const oldRegion = pushRegion(region, true);
1038
- region.depth = region.previousRegion === null ? 0 : region.previousRegion.depth + 1;
1125
+ const refillDepth = refillDepths.get(parent);
1126
+ if (refillDepth !== void 0) {
1127
+ region.depth = refillDepth;
1128
+ refillDepths.delete(parent);
1129
+ }
1039
1130
  component(parent, anchor, $props, $context, { _: slot });
1040
1131
  popRegion(oldRegion);
1041
1132
  return region;
1042
1133
  }
1043
1134
  //#endregion
1135
+ //#region src/render/clearLayoutSlot.ts
1136
+ /**
1137
+ * Clears a region that was created by `fillLayoutSlot`: tears down the
1138
+ * rendered content and its effects, leaving the surrounding layout intact
1139
+ * so the slot can be refilled.
1140
+ *
1141
+ * @param region The region to clear
1142
+ */
1143
+ function clearLayoutSlot(region) {
1144
+ context.previousRegion = region.previousRegion;
1145
+ const parent = region.startNode?.parentNode;
1146
+ if (parent) rememberSlotRefillDepth(parent, region.depth);
1147
+ clearRegion(region);
1148
+ }
1149
+ //#endregion
1044
1150
  //#region src/render/firstInsideNode.ts
1045
1151
  /**
1046
1152
  * During hydration, `nodeAnchor` finds the first node inside a hydration
@@ -1247,75 +1353,6 @@ function takeBranchIndex(anchor) {
1247
1353
  if (index !== void 0) branchIndexes.delete(anchor);
1248
1354
  return index;
1249
1355
  }
1250
- const HYDRATION_BREAK_REGEX = /^\^(?:\d+)?$/;
1251
- /**
1252
- * Whether a comment node's data is a branch-break marker (`^`, or `^<index>`
1253
- * when the server recorded the branch it rendered).
1254
- */
1255
- function isHydrationBreak(data) {
1256
- return HYDRATION_BREAK_REGEX.test(data);
1257
- }
1258
- /**
1259
- * The branch index encoded in a `^<index>` branch-break marker, or `undefined`
1260
- * for a plain `^` marker (e.g. from `@for`, which has no branch index).
1261
- */
1262
- function hydrationBreakIndex(data) {
1263
- if (!data.startsWith("^") || data.length === 1) return;
1264
- const index = Number(data.slice(1));
1265
- return Number.isNaN(index) ? void 0 : index;
1266
- }
1267
- //#endregion
1268
- //#region src/render/isCommentNode.ts
1269
- function isCommentNode(node) {
1270
- return node.nodeType === 8;
1271
- }
1272
- //#endregion
1273
- //#region src/render/isTextNode.ts
1274
- function isTextNode(node) {
1275
- return node.nodeType === 3;
1276
- }
1277
- //#endregion
1278
- //#region src/render/nodeCheckHydrationBreak.ts
1279
- /**
1280
- * When hydrating, removes and skips hydration comments that are inserted at the
1281
- * start of branches and used to split up text nodes that would otherwise be
1282
- * joined in HTML.
1283
- *
1284
- * @param node The node to check and maybe skip.
1285
- * @returns The next node.
1286
- */
1287
- function nodeCheckHydrationBreak(node) {
1288
- if (node !== null && isCommentNode(node) && isHydrationBreak(node.data)) {
1289
- let comment = node;
1290
- node = node.nextSibling;
1291
- comment.remove();
1292
- }
1293
- context.hydrationNode = node;
1294
- return node;
1295
- }
1296
- //#endregion
1297
- //#region src/render/nodeNext.ts
1298
- /**
1299
- * Gets the next sibling of a node.
1300
- *
1301
- * When hydrating, sets the hydration node.
1302
- *
1303
- * @param node The node.
1304
- * @param text Whether we require a text node.
1305
- */
1306
- function nodeNext(node, text = false) {
1307
- if (context.hydrationNode !== null) {
1308
- if (text && isTextNode(node)) return node;
1309
- let next = nodeCheckHydrationBreak(node.nextSibling);
1310
- while (!text && next !== null && isTextNode(next) && next.textContent?.trim() === "") next = nodeCheckHydrationBreak(next.nextSibling);
1311
- if (!text && next !== null && next.nodeName === "TBODY" && next.firstChild && isTextNode(node)) {
1312
- next = next.firstChild;
1313
- context.hydrationNode = next;
1314
- }
1315
- return next;
1316
- }
1317
- return node.nextSibling;
1318
- }
1319
1356
  //#endregion
1320
1357
  //#region src/render/nodeAnchor.ts
1321
1358
  /**
@@ -1497,15 +1534,23 @@ function nodeRoot(parent, text = false) {
1497
1534
  /**
1498
1535
  * Gets the sibling of a node, x nodes after it.
1499
1536
  *
1500
- * When hydrating, sets the hydration node.
1537
+ * When hydrating, sets the hydration node. `textMask` marks steps that
1538
+ * should land on a text node (bit i = the i-th step, counting from
1539
+ * `node`): such a step reuses the current node when it is already text
1540
+ * (text nodes get merged in HTML) and does not skip whitespace-only text
1541
+ * nodes — matching `nodeNext(node, true)`. Steps without their bit set
1542
+ * match `nodeNext(node, false)`.
1501
1543
  *
1502
1544
  * @param node The node.
1503
1545
  * @param count The number of nodes to skip.
1546
+ * @param textMask Bitmask of text steps.
1504
1547
  */
1505
- function nodeSkip(node, count) {
1548
+ function nodeSkip(node, count, textMask = 0) {
1506
1549
  let nextNode = node;
1507
- if (context.hydrationNode !== null) for (let i = 0; i < count; i++) nextNode = nodeCheckHydrationBreak(nextNode.nextSibling);
1508
- else for (let i = 0; i < count; i++) nextNode = nextNode.nextSibling;
1550
+ if (context.hydrationNode !== null) {
1551
+ if (textMask === 0) for (let i = 0; i < count; i++) nextNode = nodeCheckHydrationBreak(nextNode.nextSibling);
1552
+ else for (let i = 0; i < count; i++) nextNode = nodeNext(nextNode, (textMask & 1 << i) !== 0);
1553
+ } else for (let i = 0; i < count; i++) nextNode = nextNode.nextSibling;
1509
1554
  return nextNode;
1510
1555
  }
1511
1556
  //#endregion
@@ -1741,47 +1786,6 @@ function formatKey(key) {
1741
1786
  }
1742
1787
  }
1743
1788
  //#endregion
1744
- //#region src/render/AwaitSuspend.ts
1745
- /**
1746
- * Thrown when content rendered speculatively inside an `@await` boundary
1747
- * dereferences (or calls) a first-load pending `$async` value.
1748
- *
1749
- * `suspendRead` normally returns `staleValue` so refresh suspends can keep
1750
- * stale content mounted. On a first load there is no stale value, so returning
1751
- * `undefined` would let user code throw a `TypeError` before the boundary can
1752
- * switch to its `with` branch. Throwing this sentinel aborts the speculative
1753
- * render instead; `runAwait` catches it and renders the fallback.
1754
- */
1755
- var AwaitSuspend = class extends Error {
1756
- constructor() {
1757
- super("Suspended async value");
1758
- this.name = "AwaitSuspend";
1759
- }
1760
- };
1761
- //#endregion
1762
- //#region src/watch/deepWrap.ts
1763
- /**
1764
- * Wraps a value with `$watch` if it is a plain object (or Date/Map/Set) that
1765
- * is not already watched and is not a promise. Returns the value unchanged
1766
- * otherwise.
1767
- *
1768
- * Used by the `get` trap (wrap values on read) and the `set` trap (wrap
1769
- * values on write), so a value stored in watched state is reactive whether
1770
- * it's been read yet or not.
1771
- */
1772
- const proxyCache = /* @__PURE__ */ new WeakMap();
1773
- function deepWrap(value) {
1774
- if (value === void 0 || value === null || typeof value !== "object") return value;
1775
- if (value[proxyDataSymbol] !== void 0) return proxyCache.get(value) ?? value;
1776
- if (value.then !== void 0) return value;
1777
- if (value.nodeType !== void 0) return value;
1778
- const cached = proxyCache.get(value);
1779
- if (cached !== void 0) return cached;
1780
- const proxy = $watch(value);
1781
- proxyCache.set(value, proxy);
1782
- return proxy;
1783
- }
1784
- //#endregion
1785
1789
  //#region src/watch/propagateSignal.ts
1786
1790
  /**
1787
1791
  * Walk the target graph from a signal source (ProxySignal or Computed),
@@ -1839,6 +1843,7 @@ function propagateSignal(proxy, key) {
1839
1843
  if (signal !== void 0 && signal.firstTarget !== null) {
1840
1844
  batchStart();
1841
1845
  try {
1846
+ devAssert(context.firstSignalToUpdate === null === (context.lastSignalToUpdate === null), "Signal update chain head/tail out of sync");
1842
1847
  if (context.lastSignalToUpdate === null) {
1843
1848
  context.firstSignalToUpdate = signal;
1844
1849
  context.lastSignalToUpdate = signal;
@@ -1853,6 +1858,48 @@ function propagateSignal(proxy, key) {
1853
1858
  }
1854
1859
  }
1855
1860
  //#endregion
1861
+ //#region src/render/AwaitSuspend.ts
1862
+ /**
1863
+ * Thrown when content rendered speculatively inside an `@await` boundary
1864
+ * dereferences (or calls) a first-load pending `$async` value.
1865
+ *
1866
+ * `suspendRead` normally returns the retained settle value so refresh suspends
1867
+ * can keep
1868
+ * stale content mounted. On a first load there is no stale value, so returning
1869
+ * `undefined` would let user code throw a `TypeError` before the boundary can
1870
+ * switch to its `with` branch. Throwing this sentinel aborts the speculative
1871
+ * render instead; `runAwait` catches it and renders the fallback.
1872
+ */
1873
+ var AwaitSuspend = class extends Error {
1874
+ constructor() {
1875
+ super("Suspended async value");
1876
+ this.name = "AwaitSuspend";
1877
+ }
1878
+ };
1879
+ //#endregion
1880
+ //#region src/watch/deepWrap.ts
1881
+ /**
1882
+ * Wraps a value with `$watch` if it is a plain object (or Date/Map/Set) that
1883
+ * is not already watched and is not a promise. Returns the value unchanged
1884
+ * otherwise.
1885
+ *
1886
+ * Used by the `get` trap (wrap values on read) and the `set` trap (wrap
1887
+ * values on write), so a value stored in watched state is reactive whether
1888
+ * it's been read yet or not.
1889
+ */
1890
+ const proxyCache = /* @__PURE__ */ new WeakMap();
1891
+ function deepWrap(value) {
1892
+ if (value === void 0 || value === null || typeof value !== "object") return value;
1893
+ if (value[proxyDataSymbol] !== void 0) return proxyCache.get(value) ?? value;
1894
+ if (value.then !== void 0) return value;
1895
+ if (value.nodeType !== void 0) return value;
1896
+ const cached = proxyCache.get(value);
1897
+ if (cached !== void 0) return cached;
1898
+ const proxy = $watch(value);
1899
+ proxyCache.set(value, proxy);
1900
+ return proxy;
1901
+ }
1902
+ //#endregion
1856
1903
  //#region src/watch/trackProxySignal.ts
1857
1904
  function trackProxySignal(data, key) {
1858
1905
  let signal = data.signals.get(key);
@@ -1875,8 +1922,8 @@ function trackProxySignal(data, key) {
1875
1922
  * nearest `@await` boundary.
1876
1923
  *
1877
1924
  * Return value (ASYNC.md → "Stale-while-revalidate"): on a refresh suspend
1878
- * (the computed has resolved before) returns the previously resolved value
1879
- * held in `staleValue`, so readers keep displaying the old content instead of
1925
+ * (the computed has settled before) returns the previously resolved value
1926
+ * held in `settle`, so readers keep displaying the old content instead of
1880
1927
  * a placeholder — an `@await` boundary thus keeps its content mounted
1881
1928
  * rather than flashing the `with` branch. On a first load (or a retry after a
1882
1929
  * rejection, both of which have no stale value), inside an `@await` boundary,
@@ -1909,9 +1956,9 @@ function suspendRead(signal) {
1909
1956
  trackSignal(signal);
1910
1957
  context.activeTarget = oldActive;
1911
1958
  }
1912
- if (!signal.hasResolved || signal.lastErrored) throw new AwaitSuspend();
1959
+ if (signal.settle === void 0 || !signal.settle.ok) throw new AwaitSuspend();
1913
1960
  }
1914
- return signal.staleValue;
1961
+ return signal.settle !== void 0 && signal.settle.ok ? signal.settle.value : void 0;
1915
1962
  }
1916
1963
  function proxyGet(target, key, receiver) {
1917
1964
  let data = target[proxyDataSymbol];
@@ -2050,6 +2097,7 @@ function arrayHandle(data, target, key) {
2050
2097
  return function(...args) {
2051
2098
  const result = target[key].apply(target, args);
2052
2099
  propagateSignal(data, "length");
2100
+ if (key !== "sort" && key !== "reverse") propagateSignal(data, proxyKeysSymbol);
2053
2101
  return result;
2054
2102
  };
2055
2103
  }
@@ -2283,8 +2331,10 @@ function proxySet(target, key, value, receiver) {
2283
2331
  let data = target[proxyDataSymbol];
2284
2332
  devContext.signalSet(data, key);
2285
2333
  if (data.shallow !== true) value = deepWrap(value);
2334
+ const isNewKey = !Object.prototype.hasOwnProperty.call(target, key);
2286
2335
  Reflect.set(target, key, value, receiver);
2287
2336
  propagateSignal(data, key);
2337
+ if (isNewKey) propagateSignal(data, proxyKeysSymbol);
2288
2338
  if (data.isArray && typeof key !== "symbol" && !isNaN(+key)) propagateSignal(data, "length");
2289
2339
  }
2290
2340
  return true;
@@ -2293,7 +2343,21 @@ function proxySet(target, key, value, receiver) {
2293
2343
  //#region src/watch/$watch.ts
2294
2344
  const sharedHandler = {
2295
2345
  get: proxyGet,
2296
- set: proxySet
2346
+ set: proxySet,
2347
+ ownKeys: (target) => {
2348
+ const data = target[proxyDataSymbol];
2349
+ if (data !== void 0) trackProxySignal(data, proxyKeysSymbol);
2350
+ return Reflect.ownKeys(target);
2351
+ },
2352
+ deleteProperty: (target, key) => {
2353
+ const deleted = Reflect.deleteProperty(target, key);
2354
+ const data = target[proxyDataSymbol];
2355
+ if (deleted && data !== void 0) {
2356
+ propagateSignal(data, key);
2357
+ propagateSignal(data, proxyKeysSymbol);
2358
+ }
2359
+ return deleted;
2360
+ }
2297
2361
  };
2298
2362
  /**
2299
2363
  * Watches an object and runs effects when its properties are changed.
@@ -2452,13 +2516,13 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
2452
2516
  let chainNeedsRelink = false;
2453
2517
  while (oldStart <= oldEnd && newStart <= newEnd) if (oldItems[oldStart].key === newSpecs[newStart].key) {
2454
2518
  const item = oldItems[oldStart];
2455
- update(item, newSpecs[newStart]);
2519
+ if (item.data !== newSpecs[newStart].data) update(item, newSpecs[newStart]);
2456
2520
  newItems[newStart] = item;
2457
2521
  oldStart++;
2458
2522
  newStart++;
2459
2523
  } else if (oldItems[oldEnd].key === newSpecs[newEnd].key) {
2460
2524
  const item = oldItems[oldEnd];
2461
- update(item, newSpecs[newEnd]);
2525
+ if (item.data !== newSpecs[newEnd].data) update(item, newSpecs[newEnd]);
2462
2526
  newItems[newEnd] = item;
2463
2527
  oldEnd--;
2464
2528
  newEnd--;
@@ -2466,7 +2530,7 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
2466
2530
  const item = oldItems[oldStart];
2467
2531
  moveRegion(parent, item, oldItems[oldEnd].endNode?.nextSibling ?? anchor);
2468
2532
  chainNeedsRelink = true;
2469
- update(item, newSpecs[newEnd]);
2533
+ if (item.data !== newSpecs[newEnd].data) update(item, newSpecs[newEnd]);
2470
2534
  newItems[newEnd] = item;
2471
2535
  oldStart++;
2472
2536
  newEnd--;
@@ -2474,7 +2538,7 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
2474
2538
  const item = oldItems[oldEnd];
2475
2539
  moveRegion(parent, item, oldItems[oldStart].startNode);
2476
2540
  chainNeedsRelink = true;
2477
- update(item, newSpecs[newStart]);
2541
+ if (item.data !== newSpecs[newStart].data) update(item, newSpecs[newStart]);
2478
2542
  newItems[newStart] = item;
2479
2543
  oldEnd--;
2480
2544
  newStart++;
@@ -2508,7 +2572,7 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
2508
2572
  const newIdx = newKeyToIndex.get(oldItem.key);
2509
2573
  if (newIdx !== void 0) {
2510
2574
  newIndexToOld[newIdx - newStart] = i + 1;
2511
- update(oldItem, newSpecs[newIdx]);
2575
+ if (oldItem.data !== newSpecs[newIdx].data) update(oldItem, newSpecs[newIdx]);
2512
2576
  newItems[newIdx] = oldItem;
2513
2577
  } else clearRegion(oldItem);
2514
2578
  }
@@ -2626,7 +2690,7 @@ const SERVER_VALUES_PREFIX = "t-await:";
2626
2690
  * Stale-while-revalidate (ASYNC.md): once content has been produced
2627
2691
  * (`hasContent`), a subsequent suspend during a refresh does NOT switch to
2628
2692
  * the `with` branch — the boundary keeps the stale content mounted. `$async`
2629
- * retains the previous resolved value (`Computed.staleValue`) and
2693
+ * retains the previous resolved value (`Computed.settle.value`) and
2630
2694
  * `suspendRead` returns it, so child effects keep displaying the old value
2631
2695
  * until the new promise resolves and updates them in place. The `with` branch
2632
2696
  * is shown only on the first load, before content has ever rendered
@@ -2953,10 +3017,8 @@ function $async(fn, _options) {
2953
3017
  didError: false,
2954
3018
  didSuspend: false,
2955
3019
  generation: 0,
2956
- hasResolved: false,
2957
- lastErrored: false,
3020
+ settle: void 0,
2958
3021
  suspendQuiet: false,
2959
- staleValue: void 0,
2960
3022
  rollback: null
2961
3023
  };
2962
3024
  const serverValues = context.serverValues;
@@ -2968,25 +3030,29 @@ function $async(fn, _options) {
2968
3030
  if (value !== null && value !== void 0 && typeof value.then === "function") {
2969
3031
  const gen = ++computed.generation;
2970
3032
  computed.didSuspend = true;
2971
- computed.suspendQuiet = computed.hasResolved && !computed.recalc;
3033
+ computed.suspendQuiet = computed.settle !== void 0 && !computed.recalc;
2972
3034
  value.then((v) => {
2973
3035
  if (computed.generation !== gen) return;
3036
+ devAssert(computed.didSuspend, "$async: resolved while not suspended (settle bookkeeping is broken)");
2974
3037
  computed.value = v;
2975
3038
  computed.didSuspend = false;
2976
- computed.hasResolved = true;
2977
- computed.lastErrored = false;
2978
- computed.staleValue = v;
3039
+ computed.settle = {
3040
+ ok: true,
3041
+ value: v
3042
+ };
2979
3043
  batchStart();
2980
3044
  propagateFromSignal(computed);
2981
3045
  batchEnd();
2982
3046
  }, (e) => {
2983
3047
  if (computed.generation !== gen) return;
3048
+ devAssert(computed.didSuspend, "$async: rejected while not suspended (settle bookkeeping is broken)");
2984
3049
  computed.value = e;
2985
3050
  computed.didError = true;
2986
3051
  computed.didSuspend = false;
2987
- computed.hasResolved = true;
2988
- computed.lastErrored = true;
2989
- computed.staleValue = void 0;
3052
+ computed.settle = {
3053
+ ok: false,
3054
+ error: e
3055
+ };
2990
3056
  batchStart();
2991
3057
  propagateFromSignal(computed);
2992
3058
  batchEnd();
@@ -3000,10 +3066,11 @@ function $async(fn, _options) {
3000
3066
  computed.generation++;
3001
3067
  computed.didSuspend = false;
3002
3068
  computed.didError = false;
3003
- computed.hasResolved = true;
3004
- computed.lastErrored = false;
3005
3069
  computed.value = serverValues.values[serverValues.index++];
3006
- computed.staleValue = computed.value;
3070
+ computed.settle = {
3071
+ ok: true,
3072
+ value: computed.value
3073
+ };
3007
3074
  }
3008
3075
  return computed.value;
3009
3076
  }
@@ -3079,10 +3146,8 @@ function $cache(fn) {
3079
3146
  didError: false,
3080
3147
  didSuspend: false,
3081
3148
  generation: 0,
3082
- hasResolved: false,
3083
- lastErrored: false,
3149
+ settle: void 0,
3084
3150
  suspendQuiet: false,
3085
- staleValue: void 0,
3086
3151
  rollback: null
3087
3152
  };
3088
3153
  context.registerComputed(computed);
@@ -3139,7 +3204,7 @@ function $onmount(fn) {
3139
3204
  * re-asking the same question shouldn't ping the user. First loads and
3140
3205
  * dependency-change refreshes are loud (`true`), as is the default (loud)
3141
3206
  * `$refresh(fn)`. Quiet-ness is captured per computed at suspend time via
3142
- * `suspendQuiet` (computed in `$async`'s run from `hasResolved` and `recalc`).
3207
+ * `suspendQuiet` (computed in `$async`'s run from `settle` and `recalc`).
3143
3208
  *
3144
3209
  * @param fn A function that reads the reactive values to check.
3145
3210
  */
@@ -3167,7 +3232,7 @@ function $pending(fn) {
3167
3232
  * *loud*: `$pending(fn)` returns `true` while the re-fetch is in flight and
3168
3233
  * subscribers are notified at suspend *start*, so an inline "updating…"
3169
3234
  * indicator appears immediately. Readers keep displaying the previous
3170
- * resolved value (`Computed.staleValue`) until the new promise resolves and
3235
+ * resolved value (`Computed.settle.value`) until the new promise resolves and
3171
3236
  * propagates through the reactive graph; an `@await` boundary keeps its
3172
3237
  * content mounted instead of flashing fallback.
3173
3238
  *