@torpor/view 1.2.6 → 1.3.1

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 (38) hide show
  1. package/dist/{Effect-DazmAdyC.d.mts → Effect-99HYQdzZ.d.mts} +50 -33
  2. package/dist/Effect-99HYQdzZ.d.mts.map +1 -0
  3. package/dist/{Effect-Dewn7MLc.d.cts → Effect-Bf8fz_zC.d.cts} +50 -33
  4. package/dist/Effect-Bf8fz_zC.d.cts.map +1 -0
  5. package/dist/compile.cjs +1510 -122
  6. package/dist/compile.d.cts +268 -1
  7. package/dist/compile.d.cts.map +1 -1
  8. package/dist/compile.d.mts +268 -1
  9. package/dist/compile.d.mts.map +1 -1
  10. package/dist/compile.mjs +1507 -123
  11. package/dist/compile.mjs.map +1 -1
  12. package/dist/dev.d.cts +1 -1
  13. package/dist/dev.d.mts +1 -1
  14. package/dist/{fromWebSocket-DrN-IduP.cjs → fromWebSocket-Cdoghvmh.cjs} +15 -0
  15. package/dist/{fromWebSocket-CFGoMkV2.mjs → fromWebSocket-ERhd9KZR.mjs} +11 -2
  16. package/dist/fromWebSocket-ERhd9KZR.mjs.map +1 -0
  17. package/dist/index.cjs +266 -105
  18. package/dist/index.d.cts +54 -12
  19. package/dist/index.d.cts.map +1 -1
  20. package/dist/index.d.mts +54 -12
  21. package/dist/index.d.mts.map +1 -1
  22. package/dist/index.mjs +266 -105
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/runtime.iife.js +1 -0
  25. package/dist/slotAutoClose-BbKfzpkz.cjs +177 -0
  26. package/dist/slotAutoClose-CgDkf8fM.mjs +156 -0
  27. package/dist/slotAutoClose-CgDkf8fM.mjs.map +1 -0
  28. package/dist/ssr.cjs +29 -1
  29. package/dist/ssr.d.cts +32 -1
  30. package/dist/ssr.d.cts.map +1 -1
  31. package/dist/ssr.d.mts +32 -1
  32. package/dist/ssr.d.mts.map +1 -1
  33. package/dist/ssr.mjs +25 -2
  34. package/dist/ssr.mjs.map +1 -1
  35. package/package.json +8 -5
  36. package/dist/Effect-DazmAdyC.d.mts.map +0 -1
  37. package/dist/Effect-Dewn7MLc.d.cts.map +0 -1
  38. 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] ??= {
@@ -115,6 +115,23 @@ function nodeNext(node, text = false) {
115
115
  return node.nextSibling;
116
116
  }
117
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
118
135
  //#region src/watch/clearSources.ts
119
136
  /**
120
137
  * Clear unused source subscriptions after each Computed or Effect has been run.
@@ -384,6 +401,7 @@ function triggerEffects() {
384
401
  //#endregion
385
402
  //#region src/watch/batchEnd.ts
386
403
  function batchEnd() {
404
+ devAssert(context.batch > 0, "batchEnd called without a matching batchStart");
387
405
  if (context.batch > 1) {
388
406
  context.batch--;
389
407
  return;
@@ -1225,22 +1243,76 @@ function isServerComponent(component) {
1225
1243
  return component.constructor?.name === "AsyncFunction";
1226
1244
  }
1227
1245
  //#endregion
1246
+ //#region src/render/regionTreeRegistry.ts
1247
+ /**
1248
+ * Region trees created by `mount`/`hydrate`, keyed by the container they
1249
+ * were created into.
1250
+ *
1251
+ * Root-level calls (the usual `mount`/`hydrate` bootstrap) register the root
1252
+ * region, so `unmount` disposes exactly what was registered. Nested calls —
1253
+ * an embed hydrating server-rendered markup inside a live page — register a
1254
+ * region tree of their own, so their teardown (`unmount(parent)`) disposes
1255
+ * only the embed and leaves the host's render context alone. Without this,
1256
+ * hydrating an embed would replace the host's `rootRegion`/`previousRegion`
1257
+ * and the embed's teardown would clear the host's root.
1258
+ */
1259
+ const trees = /* @__PURE__ */ new Map();
1260
+ function registerRegionTree(parent, region) {
1261
+ trees.set(parent, region);
1262
+ }
1263
+ function registeredRegionTree(parent) {
1264
+ return trees.get(parent);
1265
+ }
1266
+ function unregisterRegionTree(parent) {
1267
+ trees.delete(parent);
1268
+ }
1269
+ /** Entries for trees whose container lives inside `parent` (nested embeds). */
1270
+ function containedTrees(parent) {
1271
+ const found = [];
1272
+ for (const entry of trees) if (entry[0] !== parent && parent.contains(entry[0])) found.push(entry);
1273
+ return found;
1274
+ }
1275
+ //#endregion
1228
1276
  //#region src/render/hydrate.ts
1229
1277
  /**
1230
1278
  * Hydrates a component into an existing DOM tree
1279
+ *
1280
+ * When a root region is already live (an embed hydrating its server-rendered
1281
+ * markup inside a mounted page), the component hydrates against a region
1282
+ * tree of its own and the surrounding render context is restored afterwards
1283
+ * — hydration must not replace the host's `rootRegion`/`previousRegion`.
1284
+ * Tearing the embed down later (`unmount(parent)`) then disposes only the
1285
+ * embed's tree.
1286
+ *
1231
1287
  * @param parent The parent node
1232
1288
  * @param component The component to mount
1233
1289
  * @param props An object containing component props
1234
1290
  */
1235
1291
  function hydrate(parent, component, props, slots) {
1236
1292
  if (isServerComponent(component)) throw new Error("The component was compiled for SSR (it renders to an HTML string) and cannot be hydrated in the browser. Import the client build instead, e.g. with the '?client' import query");
1293
+ const saved = context.rootRegion !== null ? {
1294
+ activeRegion: context.activeRegion,
1295
+ hydrationNode: context.hydrationNode,
1296
+ previousRegion: context.previousRegion,
1297
+ rootRegion: context.rootRegion
1298
+ } : null;
1237
1299
  context.hydrationNode = parent.firstChild;
1238
- context.rootRegion = newRegion(devContext.enabled ? "Root" : void 0);
1239
- context.previousRegion = context.rootRegion;
1240
- pushRegion(context.rootRegion);
1300
+ const root = newRegion(devContext.enabled ? "Root" : void 0);
1301
+ context.rootRegion = root;
1302
+ context.previousRegion = root;
1303
+ pushRegion(root);
1241
1304
  component(parent, null, props, void 0, slots);
1242
1305
  context.hydrationNode = null;
1243
1306
  flushMountEffects();
1307
+ if (saved === null) {
1308
+ registerRegionTree(parent, root);
1309
+ return;
1310
+ }
1311
+ context.hydrationNode = saved.hydrationNode;
1312
+ context.rootRegion = saved.rootRegion;
1313
+ context.previousRegion = saved.previousRegion;
1314
+ context.activeRegion = saved.activeRegion;
1315
+ registerRegionTree(parent, root);
1244
1316
  }
1245
1317
  //#endregion
1246
1318
  //#region src/render/mount.ts
@@ -1253,7 +1325,13 @@ function hydrate(parent, component, props, slots) {
1253
1325
  * handlers. (`hydrate` mounts into server-rendered markup, which is already
1254
1326
  * connected.)
1255
1327
  *
1256
- * @param parent The node to mount the component into
1328
+ * When a root region is already live (an embed mounting into an element
1329
+ * inside a mounted page), the component mounts against a region tree of its
1330
+ * own and the surrounding render context is left untouched — so tearing the
1331
+ * embed down later (`unmount(parent)`) disposes only the embed.
1332
+ *
1333
+ * @param parent The node to mount into. Like `hydrate`, it must have no
1334
+ * child elements
1257
1335
  * @param component The component to mount
1258
1336
  * @param props An object containing component props
1259
1337
  */
@@ -1261,33 +1339,59 @@ function mount(parent, component, props, slots) {
1261
1339
  if (isServerComponent(component)) throw new Error("The component was compiled for SSR (it renders to an HTML string) and cannot be mounted in the browser. Import the client build instead, e.g. with the '?client' import query");
1262
1340
  if (parent.childElementCount > 0) throw new Error("The parent node must have no child elements");
1263
1341
  while (parent.firstChild !== null) parent.firstChild.remove();
1264
- if (context.rootRegion === null) {
1265
- context.rootRegion = newRegion(devContext.enabled ? "Root" : void 0);
1266
- context.previousRegion = context.rootRegion;
1267
- pushRegion(context.rootRegion);
1268
- }
1342
+ const saved = context.rootRegion !== null ? {
1343
+ activeRegion: context.activeRegion,
1344
+ previousRegion: context.previousRegion,
1345
+ rootRegion: context.rootRegion
1346
+ } : null;
1347
+ const root = newRegion(devContext.enabled ? "Root" : void 0);
1348
+ context.rootRegion = root;
1349
+ context.previousRegion = root;
1350
+ pushRegion(root);
1269
1351
  component(parent, null, props, void 0, slots);
1352
+ if (saved !== null) {
1353
+ context.rootRegion = saved.rootRegion;
1354
+ context.previousRegion = saved.previousRegion;
1355
+ context.activeRegion = saved.activeRegion;
1356
+ }
1357
+ registerRegionTree(parent, root);
1270
1358
  }
1271
1359
  //#endregion
1272
1360
  //#region src/render/unmount.ts
1273
1361
  /**
1274
- * Tears down the current UI: disposes the root region tree (running effect
1275
- * cleanups and detaching subscriptions), resets the render context, and
1276
- * removes any remaining child nodes from `parent`.
1362
+ * Tears down the component tree that was mounted/hydrated into `parent`:
1363
+ * disposes its region tree (running effect cleanups and detaching
1364
+ * subscriptions), removes any remaining child nodes from `parent`, and —
1365
+ * when `parent` holds the root tree — resets the render context.
1366
+ *
1367
+ * When `parent` holds a nested tree (an embed inside a live page), only the
1368
+ * embed is disposed and the host's render context is left untouched. Any
1369
+ * embeds living inside a root container are disposed along with it.
1277
1370
  *
1278
1371
  * Call this before `mount`ing a fresh component tree into the same container
1279
1372
  * (e.g. when client-side navigating to a route whose layout chain differs
1280
1373
  * from the previous one). `mount` refuses to mount into a non-empty parent
1281
- * and reuses an existing root region, so both must be cleared first.
1374
+ * and expects no leftover tree, so both must be cleared first.
1282
1375
  *
1283
1376
  * @param parent The container that the previous UI was mounted into
1284
1377
  */
1285
1378
  function unmount(parent) {
1286
- if (context.rootRegion !== null) {
1287
- clearRegion(context.rootRegion);
1288
- context.rootRegion = null;
1289
- context.previousRegion = null;
1290
- context.activeRegion = null;
1379
+ const owned = registeredRegionTree(parent);
1380
+ for (const [nestedParent, nestedTree] of containedTrees(parent)) {
1381
+ clearRegion(nestedTree);
1382
+ unregisterRegionTree(nestedParent);
1383
+ }
1384
+ if (owned !== void 0 && owned !== context.rootRegion) {
1385
+ clearRegion(owned);
1386
+ unregisterRegionTree(parent);
1387
+ } else {
1388
+ if (context.rootRegion !== null) {
1389
+ clearRegion(context.rootRegion);
1390
+ context.rootRegion = null;
1391
+ context.previousRegion = null;
1392
+ context.activeRegion = null;
1393
+ }
1394
+ if (owned !== void 0) unregisterRegionTree(parent);
1291
1395
  }
1292
1396
  while (parent.firstChild !== null) parent.firstChild.remove();
1293
1397
  }
@@ -1516,15 +1620,23 @@ function nodeRoot(parent, text = false) {
1516
1620
  /**
1517
1621
  * Gets the sibling of a node, x nodes after it.
1518
1622
  *
1519
- * When hydrating, sets the hydration node.
1623
+ * When hydrating, sets the hydration node. `textMask` marks steps that
1624
+ * should land on a text node (bit i = the i-th step, counting from
1625
+ * `node`): such a step reuses the current node when it is already text
1626
+ * (text nodes get merged in HTML) and does not skip whitespace-only text
1627
+ * nodes — matching `nodeNext(node, true)`. Steps without their bit set
1628
+ * match `nodeNext(node, false)`.
1520
1629
  *
1521
1630
  * @param node The node.
1522
1631
  * @param count The number of nodes to skip.
1632
+ * @param textMask Bitmask of text steps.
1523
1633
  */
1524
- function nodeSkip(node, count) {
1634
+ function nodeSkip(node, count, textMask = 0) {
1525
1635
  let nextNode = node;
1526
- if (context.hydrationNode !== null) for (let i = 0; i < count; i++) nextNode = nodeCheckHydrationBreak(nextNode.nextSibling);
1527
- else for (let i = 0; i < count; i++) nextNode = nextNode.nextSibling;
1636
+ if (context.hydrationNode !== null) {
1637
+ if (textMask === 0) for (let i = 0; i < count; i++) nextNode = nodeCheckHydrationBreak(nextNode.nextSibling);
1638
+ else for (let i = 0; i < count; i++) nextNode = nodeNext(nextNode, (textMask & 1 << i) !== 0);
1639
+ } else for (let i = 0; i < count; i++) nextNode = nextNode.nextSibling;
1528
1640
  return nextNode;
1529
1641
  }
1530
1642
  //#endregion
@@ -1655,7 +1767,24 @@ function runControl(region, anchor, create, name) {
1655
1767
  }
1656
1768
  //#endregion
1657
1769
  //#region src/render/runControlBranch.ts
1658
- function runControlBranch(region, oldIndex, index) {
1770
+ /**
1771
+ * Runs one branch of a control block (`@if`/`@switch`/`@replace`, and the
1772
+ * runtime-driven `@await`/`@try` groups). Returns the region to pop after
1773
+ * the branch's content has rendered, or `null` when the branch should be
1774
+ * skipped (same index as the previous render and not forced to recreate).
1775
+ *
1776
+ * The branch region is created and pushed here — the single point of branch
1777
+ * bookkeeping, so emitters (and the runtime-driven groups) don't repeat the
1778
+ * region/push/pop dance and can't get it wrong (e.g. forgetting that the
1779
+ * clear above can release the region `context.previousRegion` points at).
1780
+ *
1781
+ * @param region The control's own region
1782
+ * @param oldIndex The branch index of the previous render (callers pass a
1783
+ * sentinel like `0` → `-1` to force a clear-and-rerender)
1784
+ * @param index The branch index of this render
1785
+ * @param name Dev-only name for the pushed branch region
1786
+ */
1787
+ function runControlBranch(region, oldIndex, index, name) {
1659
1788
  const recreate = region.recreate;
1660
1789
  if (recreate) region.recreate = false;
1661
1790
  const anchor = region.ssrBranchAnchor;
@@ -1674,12 +1803,24 @@ function runControlBranch(region, oldIndex, index) {
1674
1803
  if (oldIndex === index) {
1675
1804
  if (recreate) {
1676
1805
  if (region.nextRegion !== null && region.nextRegion.depth > region.depth) clearRegion(region.nextRegion);
1677
- return true;
1806
+ return pushBranchRegion(region, name);
1678
1807
  }
1679
- return false;
1808
+ return null;
1680
1809
  }
1681
1810
  if (!firstRender && region.nextRegion !== null && region.nextRegion.depth > region.depth) clearRegion(region.nextRegion);
1682
- return true;
1811
+ return pushBranchRegion(region, name);
1812
+ }
1813
+ /**
1814
+ * Creates and pushes the region the branch's content renders into.
1815
+ *
1816
+ * The clear above can release the region `context.previousRegion` points at
1817
+ * (the previous branch subtree's last region), so re-anchor it to the control
1818
+ * region before linking — otherwise the fresh branch would chain off a
1819
+ * released region instead of the control's.
1820
+ */
1821
+ function pushBranchRegion(region, name) {
1822
+ context.previousRegion = region;
1823
+ return pushRegion(newRegion(devContext.enabled ? name : void 0), true);
1683
1824
  }
1684
1825
  /**
1685
1826
  * Clears a server-rendered control branch that the client didn't pick, so the
@@ -1760,47 +1901,6 @@ function formatKey(key) {
1760
1901
  }
1761
1902
  }
1762
1903
  //#endregion
1763
- //#region src/render/AwaitSuspend.ts
1764
- /**
1765
- * Thrown when content rendered speculatively inside an `@await` boundary
1766
- * dereferences (or calls) a first-load pending `$async` value.
1767
- *
1768
- * `suspendRead` normally returns `staleValue` so refresh suspends can keep
1769
- * stale content mounted. On a first load there is no stale value, so returning
1770
- * `undefined` would let user code throw a `TypeError` before the boundary can
1771
- * switch to its `with` branch. Throwing this sentinel aborts the speculative
1772
- * render instead; `runAwait` catches it and renders the fallback.
1773
- */
1774
- var AwaitSuspend = class extends Error {
1775
- constructor() {
1776
- super("Suspended async value");
1777
- this.name = "AwaitSuspend";
1778
- }
1779
- };
1780
- //#endregion
1781
- //#region src/watch/deepWrap.ts
1782
- /**
1783
- * Wraps a value with `$watch` if it is a plain object (or Date/Map/Set) that
1784
- * is not already watched and is not a promise. Returns the value unchanged
1785
- * otherwise.
1786
- *
1787
- * Used by the `get` trap (wrap values on read) and the `set` trap (wrap
1788
- * values on write), so a value stored in watched state is reactive whether
1789
- * it's been read yet or not.
1790
- */
1791
- const proxyCache = /* @__PURE__ */ new WeakMap();
1792
- function deepWrap(value) {
1793
- if (value === void 0 || value === null || typeof value !== "object") return value;
1794
- if (value[proxyDataSymbol] !== void 0) return proxyCache.get(value) ?? value;
1795
- if (value.then !== void 0) return value;
1796
- if (value.nodeType !== void 0) return value;
1797
- const cached = proxyCache.get(value);
1798
- if (cached !== void 0) return cached;
1799
- const proxy = $watch(value);
1800
- proxyCache.set(value, proxy);
1801
- return proxy;
1802
- }
1803
- //#endregion
1804
1904
  //#region src/watch/propagateSignal.ts
1805
1905
  /**
1806
1906
  * Walk the target graph from a signal source (ProxySignal or Computed),
@@ -1858,6 +1958,7 @@ function propagateSignal(proxy, key) {
1858
1958
  if (signal !== void 0 && signal.firstTarget !== null) {
1859
1959
  batchStart();
1860
1960
  try {
1961
+ devAssert(context.firstSignalToUpdate === null === (context.lastSignalToUpdate === null), "Signal update chain head/tail out of sync");
1861
1962
  if (context.lastSignalToUpdate === null) {
1862
1963
  context.firstSignalToUpdate = signal;
1863
1964
  context.lastSignalToUpdate = signal;
@@ -1872,6 +1973,48 @@ function propagateSignal(proxy, key) {
1872
1973
  }
1873
1974
  }
1874
1975
  //#endregion
1976
+ //#region src/render/AwaitSuspend.ts
1977
+ /**
1978
+ * Thrown when content rendered speculatively inside an `@await` boundary
1979
+ * dereferences (or calls) a first-load pending `$async` value.
1980
+ *
1981
+ * `suspendRead` normally returns the retained settle value so refresh suspends
1982
+ * can keep
1983
+ * stale content mounted. On a first load there is no stale value, so returning
1984
+ * `undefined` would let user code throw a `TypeError` before the boundary can
1985
+ * switch to its `with` branch. Throwing this sentinel aborts the speculative
1986
+ * render instead; `runAwait` catches it and renders the fallback.
1987
+ */
1988
+ var AwaitSuspend = class extends Error {
1989
+ constructor() {
1990
+ super("Suspended async value");
1991
+ this.name = "AwaitSuspend";
1992
+ }
1993
+ };
1994
+ //#endregion
1995
+ //#region src/watch/deepWrap.ts
1996
+ /**
1997
+ * Wraps a value with `$watch` if it is a plain object (or Date/Map/Set) that
1998
+ * is not already watched and is not a promise. Returns the value unchanged
1999
+ * otherwise.
2000
+ *
2001
+ * Used by the `get` trap (wrap values on read) and the `set` trap (wrap
2002
+ * values on write), so a value stored in watched state is reactive whether
2003
+ * it's been read yet or not.
2004
+ */
2005
+ const proxyCache = /* @__PURE__ */ new WeakMap();
2006
+ function deepWrap(value) {
2007
+ if (value === void 0 || value === null || typeof value !== "object") return value;
2008
+ if (value[proxyDataSymbol] !== void 0) return proxyCache.get(value) ?? value;
2009
+ if (value.then !== void 0) return value;
2010
+ if (value.nodeType !== void 0) return value;
2011
+ const cached = proxyCache.get(value);
2012
+ if (cached !== void 0) return cached;
2013
+ const proxy = $watch(value);
2014
+ proxyCache.set(value, proxy);
2015
+ return proxy;
2016
+ }
2017
+ //#endregion
1875
2018
  //#region src/watch/trackProxySignal.ts
1876
2019
  function trackProxySignal(data, key) {
1877
2020
  let signal = data.signals.get(key);
@@ -1894,8 +2037,8 @@ function trackProxySignal(data, key) {
1894
2037
  * nearest `@await` boundary.
1895
2038
  *
1896
2039
  * Return value (ASYNC.md → "Stale-while-revalidate"): on a refresh suspend
1897
- * (the computed has resolved before) returns the previously resolved value
1898
- * held in `staleValue`, so readers keep displaying the old content instead of
2040
+ * (the computed has settled before) returns the previously resolved value
2041
+ * held in `settle`, so readers keep displaying the old content instead of
1899
2042
  * a placeholder — an `@await` boundary thus keeps its content mounted
1900
2043
  * rather than flashing the `with` branch. On a first load (or a retry after a
1901
2044
  * rejection, both of which have no stale value), inside an `@await` boundary,
@@ -1928,9 +2071,9 @@ function suspendRead(signal) {
1928
2071
  trackSignal(signal);
1929
2072
  context.activeTarget = oldActive;
1930
2073
  }
1931
- if (!signal.hasResolved || signal.lastErrored) throw new AwaitSuspend();
2074
+ if (signal.settle === void 0 || !signal.settle.ok) throw new AwaitSuspend();
1932
2075
  }
1933
- return signal.staleValue;
2076
+ return signal.settle !== void 0 && signal.settle.ok ? signal.settle.value : void 0;
1934
2077
  }
1935
2078
  function proxyGet(target, key, receiver) {
1936
2079
  let data = target[proxyDataSymbol];
@@ -2069,6 +2212,7 @@ function arrayHandle(data, target, key) {
2069
2212
  return function(...args) {
2070
2213
  const result = target[key].apply(target, args);
2071
2214
  propagateSignal(data, "length");
2215
+ if (key !== "sort" && key !== "reverse") propagateSignal(data, proxyKeysSymbol);
2072
2216
  return result;
2073
2217
  };
2074
2218
  }
@@ -2302,8 +2446,10 @@ function proxySet(target, key, value, receiver) {
2302
2446
  let data = target[proxyDataSymbol];
2303
2447
  devContext.signalSet(data, key);
2304
2448
  if (data.shallow !== true) value = deepWrap(value);
2449
+ const isNewKey = !Object.prototype.hasOwnProperty.call(target, key);
2305
2450
  Reflect.set(target, key, value, receiver);
2306
2451
  propagateSignal(data, key);
2452
+ if (isNewKey) propagateSignal(data, proxyKeysSymbol);
2307
2453
  if (data.isArray && typeof key !== "symbol" && !isNaN(+key)) propagateSignal(data, "length");
2308
2454
  }
2309
2455
  return true;
@@ -2312,7 +2458,21 @@ function proxySet(target, key, value, receiver) {
2312
2458
  //#region src/watch/$watch.ts
2313
2459
  const sharedHandler = {
2314
2460
  get: proxyGet,
2315
- set: proxySet
2461
+ set: proxySet,
2462
+ ownKeys: (target) => {
2463
+ const data = target[proxyDataSymbol];
2464
+ if (data !== void 0) trackProxySignal(data, proxyKeysSymbol);
2465
+ return Reflect.ownKeys(target);
2466
+ },
2467
+ deleteProperty: (target, key) => {
2468
+ const deleted = Reflect.deleteProperty(target, key);
2469
+ const data = target[proxyDataSymbol];
2470
+ if (deleted && data !== void 0) {
2471
+ propagateSignal(data, key);
2472
+ propagateSignal(data, proxyKeysSymbol);
2473
+ }
2474
+ return deleted;
2475
+ }
2316
2476
  };
2317
2477
  /**
2318
2478
  * Watches an object and runs effects when its properties are changed.
@@ -2471,13 +2631,13 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
2471
2631
  let chainNeedsRelink = false;
2472
2632
  while (oldStart <= oldEnd && newStart <= newEnd) if (oldItems[oldStart].key === newSpecs[newStart].key) {
2473
2633
  const item = oldItems[oldStart];
2474
- update(item, newSpecs[newStart]);
2634
+ if (item.data !== newSpecs[newStart].data) update(item, newSpecs[newStart]);
2475
2635
  newItems[newStart] = item;
2476
2636
  oldStart++;
2477
2637
  newStart++;
2478
2638
  } else if (oldItems[oldEnd].key === newSpecs[newEnd].key) {
2479
2639
  const item = oldItems[oldEnd];
2480
- update(item, newSpecs[newEnd]);
2640
+ if (item.data !== newSpecs[newEnd].data) update(item, newSpecs[newEnd]);
2481
2641
  newItems[newEnd] = item;
2482
2642
  oldEnd--;
2483
2643
  newEnd--;
@@ -2485,7 +2645,7 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
2485
2645
  const item = oldItems[oldStart];
2486
2646
  moveRegion(parent, item, oldItems[oldEnd].endNode?.nextSibling ?? anchor);
2487
2647
  chainNeedsRelink = true;
2488
- update(item, newSpecs[newEnd]);
2648
+ if (item.data !== newSpecs[newEnd].data) update(item, newSpecs[newEnd]);
2489
2649
  newItems[newEnd] = item;
2490
2650
  oldStart++;
2491
2651
  newEnd--;
@@ -2493,7 +2653,7 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
2493
2653
  const item = oldItems[oldEnd];
2494
2654
  moveRegion(parent, item, oldItems[oldStart].startNode);
2495
2655
  chainNeedsRelink = true;
2496
- update(item, newSpecs[newStart]);
2656
+ if (item.data !== newSpecs[newStart].data) update(item, newSpecs[newStart]);
2497
2657
  newItems[newStart] = item;
2498
2658
  oldEnd--;
2499
2659
  newStart++;
@@ -2527,7 +2687,7 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
2527
2687
  const newIdx = newKeyToIndex.get(oldItem.key);
2528
2688
  if (newIdx !== void 0) {
2529
2689
  newIndexToOld[newIdx - newStart] = i + 1;
2530
- update(oldItem, newSpecs[newIdx]);
2690
+ if (oldItem.data !== newSpecs[newIdx].data) update(oldItem, newSpecs[newIdx]);
2531
2691
  newItems[newIdx] = oldItem;
2532
2692
  } else clearRegion(oldItem);
2533
2693
  }
@@ -2645,7 +2805,7 @@ const SERVER_VALUES_PREFIX = "t-await:";
2645
2805
  * Stale-while-revalidate (ASYNC.md): once content has been produced
2646
2806
  * (`hasContent`), a subsequent suspend during a refresh does NOT switch to
2647
2807
  * the `with` branch — the boundary keeps the stale content mounted. `$async`
2648
- * retains the previous resolved value (`Computed.staleValue`) and
2808
+ * retains the previous resolved value (`Computed.settle.value`) and
2649
2809
  * `suspendRead` returns it, so child effects keep displaying the old value
2650
2810
  * until the new promise resolves and updates them in place. The `with` branch
2651
2811
  * is shown only on the first load, before content has ever rendered
@@ -2684,9 +2844,8 @@ function runAwait(region, anchor, renderContent, renderWith, name) {
2684
2844
  const oldRegion = pushRegion(region, first);
2685
2845
  first = false;
2686
2846
  const renderBranch = (targetIndex, fn) => {
2687
- runControlBranch(region, index, targetIndex);
2688
- context.previousRegion = region;
2689
- const oldR = pushRegion(newRegion(targetIndex === 0 ? "await_content" : "await_with"), true);
2847
+ const oldR = runControlBranch(region, index, targetIndex, targetIndex === 0 ? "await_content" : "await_with");
2848
+ if (oldR === null) return;
2690
2849
  try {
2691
2850
  fn(anchor);
2692
2851
  } finally {
@@ -2719,7 +2878,8 @@ function runAwait(region, anchor, renderContent, renderWith, name) {
2719
2878
  }
2720
2879
  if (boundary.suspended && renderWith !== null) renderBranch(1, renderWith);
2721
2880
  else if (boundary.suspended && aborted) {
2722
- runControlBranch(region, index, 1);
2881
+ const oldR = runControlBranch(region, index, 1, "await_with");
2882
+ if (oldR !== null) popRegion(oldR);
2723
2883
  index = 1;
2724
2884
  } else if (!boundary.suspended) hasContent = true;
2725
2885
  };
@@ -2736,7 +2896,8 @@ function runAwait(region, anchor, renderContent, renderWith, name) {
2736
2896
  else if (!hasContent) {
2737
2897
  if (renderWith !== null) renderBranch(1, renderWith);
2738
2898
  else {
2739
- runControlBranch(region, index, 1);
2899
+ const oldR = runControlBranch(region, index, 1, "await_with");
2900
+ if (oldR !== null) popRegion(oldR);
2740
2901
  index = 1;
2741
2902
  }
2742
2903
  }
@@ -2821,9 +2982,8 @@ function runTry(region, anchor, renderTry, renderCatch, name) {
2821
2982
  const oldRegion = pushRegion(region, first);
2822
2983
  first = false;
2823
2984
  const renderBranch = (targetIndex, fn) => {
2824
- runControlBranch(region, index, targetIndex);
2825
- context.previousRegion = region;
2826
- const oldR = pushRegion(newRegion(targetIndex === 0 ? "try" : "catch"), true);
2985
+ const oldR = runControlBranch(region, index, targetIndex, targetIndex === 0 ? "try" : "catch");
2986
+ if (oldR === null) return;
2827
2987
  fn(anchor);
2828
2988
  popRegion(oldR);
2829
2989
  index = targetIndex;
@@ -2972,10 +3132,8 @@ function $async(fn, _options) {
2972
3132
  didError: false,
2973
3133
  didSuspend: false,
2974
3134
  generation: 0,
2975
- hasResolved: false,
2976
- lastErrored: false,
3135
+ settle: void 0,
2977
3136
  suspendQuiet: false,
2978
- staleValue: void 0,
2979
3137
  rollback: null
2980
3138
  };
2981
3139
  const serverValues = context.serverValues;
@@ -2987,25 +3145,29 @@ function $async(fn, _options) {
2987
3145
  if (value !== null && value !== void 0 && typeof value.then === "function") {
2988
3146
  const gen = ++computed.generation;
2989
3147
  computed.didSuspend = true;
2990
- computed.suspendQuiet = computed.hasResolved && !computed.recalc;
3148
+ computed.suspendQuiet = computed.settle !== void 0 && !computed.recalc;
2991
3149
  value.then((v) => {
2992
3150
  if (computed.generation !== gen) return;
3151
+ devAssert(computed.didSuspend, "$async: resolved while not suspended (settle bookkeeping is broken)");
2993
3152
  computed.value = v;
2994
3153
  computed.didSuspend = false;
2995
- computed.hasResolved = true;
2996
- computed.lastErrored = false;
2997
- computed.staleValue = v;
3154
+ computed.settle = {
3155
+ ok: true,
3156
+ value: v
3157
+ };
2998
3158
  batchStart();
2999
3159
  propagateFromSignal(computed);
3000
3160
  batchEnd();
3001
3161
  }, (e) => {
3002
3162
  if (computed.generation !== gen) return;
3163
+ devAssert(computed.didSuspend, "$async: rejected while not suspended (settle bookkeeping is broken)");
3003
3164
  computed.value = e;
3004
3165
  computed.didError = true;
3005
3166
  computed.didSuspend = false;
3006
- computed.hasResolved = true;
3007
- computed.lastErrored = true;
3008
- computed.staleValue = void 0;
3167
+ computed.settle = {
3168
+ ok: false,
3169
+ error: e
3170
+ };
3009
3171
  batchStart();
3010
3172
  propagateFromSignal(computed);
3011
3173
  batchEnd();
@@ -3019,10 +3181,11 @@ function $async(fn, _options) {
3019
3181
  computed.generation++;
3020
3182
  computed.didSuspend = false;
3021
3183
  computed.didError = false;
3022
- computed.hasResolved = true;
3023
- computed.lastErrored = false;
3024
3184
  computed.value = serverValues.values[serverValues.index++];
3025
- computed.staleValue = computed.value;
3185
+ computed.settle = {
3186
+ ok: true,
3187
+ value: computed.value
3188
+ };
3026
3189
  }
3027
3190
  return computed.value;
3028
3191
  }
@@ -3098,10 +3261,8 @@ function $cache(fn) {
3098
3261
  didError: false,
3099
3262
  didSuspend: false,
3100
3263
  generation: 0,
3101
- hasResolved: false,
3102
- lastErrored: false,
3264
+ settle: void 0,
3103
3265
  suspendQuiet: false,
3104
- staleValue: void 0,
3105
3266
  rollback: null
3106
3267
  };
3107
3268
  context.registerComputed(computed);
@@ -3158,7 +3319,7 @@ function $onmount(fn) {
3158
3319
  * re-asking the same question shouldn't ping the user. First loads and
3159
3320
  * dependency-change refreshes are loud (`true`), as is the default (loud)
3160
3321
  * `$refresh(fn)`. Quiet-ness is captured per computed at suspend time via
3161
- * `suspendQuiet` (computed in `$async`'s run from `hasResolved` and `recalc`).
3322
+ * `suspendQuiet` (computed in `$async`'s run from `settle` and `recalc`).
3162
3323
  *
3163
3324
  * @param fn A function that reads the reactive values to check.
3164
3325
  */
@@ -3186,7 +3347,7 @@ function $pending(fn) {
3186
3347
  * *loud*: `$pending(fn)` returns `true` while the re-fetch is in flight and
3187
3348
  * subscribers are notified at suspend *start*, so an inline "updating…"
3188
3349
  * indicator appears immediately. Readers keep displaying the previous
3189
- * resolved value (`Computed.staleValue`) until the new promise resolves and
3350
+ * resolved value (`Computed.settle.value`) until the new promise resolves and
3190
3351
  * propagates through the reactive graph; an `@await` boundary keeps its
3191
3352
  * content mounted instead of flashing fallback.
3192
3353
  *