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