brumate 0.8.1 → 0.9.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 (122) hide show
  1. package/dist/{boot-DQuAhAd5.d.ts → boot-ej-9NRT3.d.ts} +20 -2
  2. package/dist/cli.js +88 -82
  3. package/dist/cli.js.map +1 -1
  4. package/dist/{client-CwVcmymi.js → client-B-ww-PQ7.js} +304 -48
  5. package/dist/client-B-ww-PQ7.js.map +1 -0
  6. package/dist/{client-4eabQtYJ.d.ts → client-Do6IBIhI.d.ts} +35 -9
  7. package/dist/{defer-BaXWydb0.js → defer-JD2FK9mV.js} +5 -3
  8. package/dist/defer-JD2FK9mV.js.map +1 -0
  9. package/dist/{devtools-calls-DGW6nLZ2.js → devtools-calls-DCjuSkim.js} +3 -3
  10. package/dist/{devtools-calls-DGW6nLZ2.js.map → devtools-calls-DCjuSkim.js.map} +1 -1
  11. package/dist/{devtools-panel-Cq8LpsyW.js → devtools-panel-DLeWTPhU.js} +4 -4
  12. package/dist/{devtools-panel-Cq8LpsyW.js.map → devtools-panel-DLeWTPhU.js.map} +1 -1
  13. package/dist/{devtools-CMuj12yR.js → devtools-tuq7ATGN.js} +10 -7
  14. package/dist/devtools-tuq7ATGN.js.map +1 -0
  15. package/dist/{error-catalog-DakxjSgj.js → error-catalog-BBWB7w-E.js} +11 -4
  16. package/dist/error-catalog-BBWB7w-E.js.map +1 -0
  17. package/dist/{error-catalog-VxLbz-6p.js → error-catalog-CbmQqfat.js} +1 -1
  18. package/dist/{events-LgLdp1R7.js → events-BDVITj3P.js} +3 -5
  19. package/dist/events-BDVITj3P.js.map +1 -0
  20. package/dist/{features-DwMYKBIC.js → features-Cte5aj20.js} +8 -2
  21. package/dist/features-Cte5aj20.js.map +1 -0
  22. package/dist/{files-DXS8RAtZ.js → files-Bz0lAQzD.js} +2 -2
  23. package/dist/{files-DXS8RAtZ.js.map → files-Bz0lAQzD.js.map} +1 -1
  24. package/dist/{html-Cf5uKhLs.js → html-BYuHDvxy.js} +10 -3
  25. package/dist/html-BYuHDvxy.js.map +1 -0
  26. package/dist/index.d.ts +71 -19
  27. package/dist/index.js +3 -3
  28. package/dist/{inspect-B5AoHh5O.js → inspect-fpaBJ5pm.js} +1247 -62
  29. package/dist/inspect-fpaBJ5pm.js.map +1 -0
  30. package/dist/{loader-CTeT6ie9.js → loader-DMxuZ6He.js} +14 -6
  31. package/dist/loader-DMxuZ6He.js.map +1 -0
  32. package/dist/{navigate-Bj73X4ZS.js → navigate-C5PjwYMh.js} +101 -20
  33. package/dist/navigate-C5PjwYMh.js.map +1 -0
  34. package/dist/{produce-CLABZ8k2.d.ts → produce-BDkCsGH7.d.ts} +3 -3
  35. package/dist/{rpc-kVB0Ujdx.js → rpc-DOdrekhP.js} +23 -13
  36. package/dist/rpc-DOdrekhP.js.map +1 -0
  37. package/dist/runtime/bundles.d.ts +1 -1
  38. package/dist/runtime/bundles.js +6 -2
  39. package/dist/runtime/bundles.js.map +1 -1
  40. package/dist/runtime/client.d.ts +4 -3
  41. package/dist/runtime/client.js +5 -5
  42. package/dist/runtime/devtools.d.ts +3 -1
  43. package/dist/runtime/devtools.js +1 -1
  44. package/dist/runtime/events.js +1 -1
  45. package/dist/runtime/hot.d.ts +1 -1
  46. package/dist/runtime/html.js +1 -1
  47. package/dist/runtime/loader.d.ts +2 -2
  48. package/dist/runtime/loader.js +2 -2
  49. package/dist/runtime/otel.d.ts +18 -0
  50. package/dist/runtime/otel.js +127 -0
  51. package/dist/runtime/otel.js.map +1 -0
  52. package/dist/runtime/server.d.ts +4 -3
  53. package/dist/runtime/server.js +5 -5
  54. package/dist/runtime/signals.d.ts +2 -2
  55. package/dist/runtime/signals.js +4 -1
  56. package/dist/runtime/signals.js.map +1 -1
  57. package/dist/runtime/static-loader.d.ts +2 -2
  58. package/dist/runtime/static-loader.js +1 -1
  59. package/dist/runtime/store.d.ts +2 -2
  60. package/dist/runtime/store.js +1 -1
  61. package/dist/runtime/testing.d.ts +2 -2
  62. package/dist/runtime/testing.js +2 -2
  63. package/dist/search-params-qGERTLi3.js +382 -0
  64. package/dist/search-params-qGERTLi3.js.map +1 -0
  65. package/dist/{serial-ribg9NAj.js → serial-B2AJ9VGx.js} +1 -1
  66. package/dist/{serial-ioa17MuY.js → serial-Cj6pDGOq.js} +6 -6
  67. package/dist/{serial-ioa17MuY.js.map → serial-Cj6pDGOq.js.map} +1 -1
  68. package/dist/{server-DesBZv5g.d.ts → server-2-LS_KFo.d.ts} +125 -9
  69. package/dist/{server-BUuf7XPZ.js → server-CRGZMWnK.js} +545 -236
  70. package/dist/server-CRGZMWnK.js.map +1 -0
  71. package/dist/{shared-CX_YacDm.js → shared-CUBWrbiM.js} +4 -4
  72. package/dist/{shared-CX_YacDm.js.map → shared-CUBWrbiM.js.map} +1 -1
  73. package/dist/sheets-B9Zr50mf.js +105 -0
  74. package/dist/sheets-B9Zr50mf.js.map +1 -0
  75. package/dist/{signals-7VVD9C_H.d.ts → signals-BgsJK-uT.d.ts} +16 -6
  76. package/dist/{static-loader-BM0-wdIc.js → static-loader-BDBtWsdg.js} +107 -19
  77. package/dist/static-loader-BDBtWsdg.js.map +1 -0
  78. package/dist/{static-loader-BSAyFqG0.d.ts → static-loader-CAFn6p0l.d.ts} +2 -2
  79. package/dist/{store-9_oa0HG1.d.ts → store-BwWg-Iei.d.ts} +79 -2
  80. package/dist/store-DNr24Z8L.js +950 -0
  81. package/dist/store-DNr24Z8L.js.map +1 -0
  82. package/dist/{stream-read-BTsYstJY.js → stream-read-CiLDH60b.js} +2 -2
  83. package/dist/{stream-read-BTsYstJY.js.map → stream-read-CiLDH60b.js.map} +1 -1
  84. package/dist/{stream-read-Dek3HnqO.js → stream-read-DVoregpA.js} +1 -1
  85. package/dist/trace-DT7RGRAV.d.ts +52 -0
  86. package/dist/trace-browser-C7MFMove.js +170 -0
  87. package/dist/trace-browser-C7MFMove.js.map +1 -0
  88. package/dist/trace-flag-Dy267snx.js +7 -0
  89. package/dist/trace-flag-Dy267snx.js.map +1 -0
  90. package/dist/{trusted-g_zUJbh2.js → trusted-Bmwg4_hf.js} +12 -5
  91. package/dist/trusted-Bmwg4_hf.js.map +1 -0
  92. package/dist/view-transitions-BpnVwtS4.js +141 -0
  93. package/dist/view-transitions-BpnVwtS4.js.map +1 -0
  94. package/dist/vite.d.ts +8 -1
  95. package/dist/vite.js +356 -46
  96. package/dist/vite.js.map +1 -1
  97. package/elements.d.ts +8 -0
  98. package/package.json +13 -1
  99. package/skills/brumate/SKILL.md +9 -5
  100. package/skills/brumate/references/errors.md +95 -14
  101. package/skills/brumate/references/events.md +27 -1
  102. package/skills/brumate/references/signals.md +4 -4
  103. package/skills/brumate/references/state.md +79 -4
  104. package/skills/brumate/references/syntax.md +58 -9
  105. package/dist/client-CwVcmymi.js.map +0 -1
  106. package/dist/defer-BaXWydb0.js.map +0 -1
  107. package/dist/devtools-CMuj12yR.js.map +0 -1
  108. package/dist/error-catalog-DakxjSgj.js.map +0 -1
  109. package/dist/events-LgLdp1R7.js.map +0 -1
  110. package/dist/features-DwMYKBIC.js.map +0 -1
  111. package/dist/html-Cf5uKhLs.js.map +0 -1
  112. package/dist/inspect-B5AoHh5O.js.map +0 -1
  113. package/dist/loader-CTeT6ie9.js.map +0 -1
  114. package/dist/navigate-Bj73X4ZS.js.map +0 -1
  115. package/dist/rpc-kVB0Ujdx.js.map +0 -1
  116. package/dist/search-params-Wg-0FsMj.js +0 -148
  117. package/dist/search-params-Wg-0FsMj.js.map +0 -1
  118. package/dist/server-BUuf7XPZ.js.map +0 -1
  119. package/dist/static-loader-BM0-wdIc.js.map +0 -1
  120. package/dist/store-Cy4EEyZ7.js +0 -439
  121. package/dist/store-Cy4EEyZ7.js.map +0 -1
  122. package/dist/trusted-g_zUJbh2.js.map +0 -1
@@ -1,11 +1,13 @@
1
- import { C as spread$1, T as textValue, b as ownValue, f as handlerEntry, g as isRaw, n as VOID_ELEMENTS, o as attributeText, p as insertValue, r as actionAttributes, s as bindEntry, v as onAttribute, y as onValue } from "./html-Cf5uKhLs.js";
2
- import { _ as HAS_TITLES, a as HAS_CHILDREN, c as HAS_FIELDS, d as HAS_LOADING, f as HAS_ROOT_WAIT, g as HAS_TEMPLATES, h as HAS_STORES, i as HAS_BRIDGES, l as HAS_LATE_MARKUP, n as HAS_BINDINGS, o as HAS_CLIENT_HTML, p as HAS_ROUTES, s as HAS_DYNAMIC, v as HAS_TRIES, y as HAS_WINDOWS } from "./features-DwMYKBIC.js";
3
- import { d as isStore, g as setBridgeLoader, m as sendStore, n as Store, o as findStored, p as sameData, s as isBridged } from "./store-Cy4EEyZ7.js";
4
- import { S as stateValues, _ as madeStores, a as FunctionReference, d as addEntryHandlers, f as gateValue, g as isSlotReference, h as isPropWrapper, i as ElementReference, m as isBinding, o as MemoError, p as isAsyncIterable, r as ChildrenReference, s as PARTS, t as Binding, u as SlotReference, v as mergeHandlers, w as useSerialEntry, x as parseId } from "./shared-CX_YacDm.js";
5
- import { r as writeParam, t as readParam } from "./search-params-Wg-0FsMj.js";
1
+ import { S as HAS_WINDOWS, _ as HAS_STORES, a as HAS_CHILDREN, b as HAS_TRIES, c as HAS_FIELDS, d as HAS_LOADING, f as HAS_MODULE_MEMOS, i as HAS_BRIDGES, l as HAS_LATE_MARKUP, m as HAS_ROUTES, n as HAS_BINDINGS, o as HAS_CLIENT_HTML, p as HAS_ROOT_WAIT, s as HAS_DYNAMIC, v as HAS_TEMPLATES, y as HAS_TITLES } from "./features-Cte5aj20.js";
2
+ import { C as spread$1, T as textValue, b as ownValue, f as handlerEntry, g as isRaw, n as VOID_ELEMENTS, o as attributeText, p as insertValue, r as actionAttributes, s as bindEntry, v as onAttribute, y as onValue } from "./html-BYuHDvxy.js";
3
+ import { S as setBridgeLoader, _ as onServer, b as sendStore, i as Store, l as findStored, m as isStore, n as HOLDS, u as isBridged, v as pendingOf, y as sameData } from "./store-DNr24Z8L.js";
4
+ import { S as stateValues, _ as madeStores, a as FunctionReference, d as addEntryHandlers, f as gateValue, g as isSlotReference, h as isPropWrapper, i as ElementReference, m as isBinding, o as MemoError, p as isAsyncIterable, r as ChildrenReference, s as PARTS, t as Binding, u as SlotReference, v as mergeHandlers, w as useSerialEntry, x as parseId } from "./shared-CUBWrbiM.js";
5
+ import { r as writeParam, t as readParam } from "./search-params-qGERTLi3.js";
6
6
  import { i as missingContext, n as ROUTE_KEY, t as NAVIGATION_KEY } from "./context-CU4Fpn5a.js";
7
- import { t as trustedHTML } from "./trusted-g_zUJbh2.js";
7
+ import { t as trustedHTML } from "./trusted-Bmwg4_hf.js";
8
8
  import { t as loadOnce } from "./skew-CwmX_GFI.js";
9
+ import { t as TRACE } from "./trace-flag-Dy267snx.js";
10
+ import { o as traceRequest, r as traceContext } from "./trace-browser-C7MFMove.js";
9
11
  import { n as navigate } from "./routes-D21FQyGF.js";
10
12
  //#region src/runtime/client/state.ts
11
13
  let options;
@@ -340,10 +342,6 @@ let nextId = -1;
340
342
  function resetIds() {
341
343
  nextId = -1;
342
344
  }
343
- /** Returns the instance of a scope by its ID. */
344
- function getScope(id) {
345
- return scopes.get(id);
346
- }
347
345
  function findRoot(scope) {
348
346
  let current = scope;
349
347
  while (current.p) current = current.p;
@@ -1142,7 +1140,7 @@ function get(scope, slot) {
1142
1140
  * reads it throws into the nearest `#try` around it, and the code that does not read it runs as
1143
1141
  * usual. A memo that computes again without a throw holds its value again.
1144
1142
  */
1145
- function hold$1(scope, slot, key, error) {
1143
+ function hold$2(scope, slot, key, error) {
1146
1144
  loadingSlots.delete(key);
1147
1145
  loads.delete(key);
1148
1146
  guesses?.map.delete(key);
@@ -1291,6 +1289,15 @@ function startLoading(scope, slot, key) {
1291
1289
  }
1292
1290
  }
1293
1291
  /**
1292
+ * Marks the slot of a store that can be pending, such as a debounced value of a module, as loading
1293
+ * or not. `$isPending` and `$resolve` read it as they read a memo.
1294
+ */
1295
+ function markPending(scope, slot, on) {
1296
+ const key = `${scope.id}:${slot}`;
1297
+ if (on) startLoading(scope, slot, key);
1298
+ else if (loadingSlots.delete(key)) trigger(scope, slot);
1299
+ }
1300
+ /**
1294
1301
  * Computes a memo of `$debounced` after its value stops changing for `ms`,
1295
1302
  * or one of `$throttled` at most once every `ms`, with the last value after
1296
1303
  * the wait. The memo is pending while it waits.
@@ -1347,7 +1354,7 @@ function asyncMemo(scope, slot, promise) {
1347
1354
  else trigger(scope, slot);
1348
1355
  }
1349
1356
  function failed(error) {
1350
- if (loads.get(key) === load) hold$1(scope, slot, key, error);
1357
+ if (loads.get(key) === load) hold$2(scope, slot, key, error);
1351
1358
  }
1352
1359
  promise.then((value) => {
1353
1360
  if (!isAsyncIterable(value)) {
@@ -1514,7 +1521,7 @@ function memo(scope, slot, compute) {
1514
1521
  memoKey = outer;
1515
1522
  }
1516
1523
  if (threw) {
1517
- hold$1(scope, slot, key, value);
1524
+ hold$2(scope, slot, key, value);
1518
1525
  return;
1519
1526
  }
1520
1527
  if (isThenable(value) || isAsyncIterable(value)) {
@@ -1821,18 +1828,7 @@ function effect(scope, name, callback, client) {
1821
1828
  cleanup = callback();
1822
1829
  } catch (error) {
1823
1830
  if (error instanceof NotReady) {
1824
- const token = {};
1825
- skipped.set(key, token);
1826
- scope.cleanups.set(name, noop$1);
1827
- function again() {
1828
- if (skipped.get(key) === token && scopes.get(scope.id) === scope) effect(scope, name, callback);
1829
- }
1830
- error.source.then(() => Promise.allSettled(loadingUpdates).then(again), (reason) => {
1831
- if (skipped.get(key) === token) {
1832
- skipped.delete(key);
1833
- fail(scope, reason);
1834
- }
1835
- });
1831
+ skipEffect(scope, name, error, () => effect(scope, name, callback));
1836
1832
  return;
1837
1833
  }
1838
1834
  fail(scope, error);
@@ -1840,16 +1836,70 @@ function effect(scope, name, callback, client) {
1840
1836
  origin = outer;
1841
1837
  if (!client) runningEffects--;
1842
1838
  }
1843
- let stored = typeof cleanup === "function" ? cleanup : noop$1;
1844
- if (DEV) {
1845
- devtools()?.effect?.(scope, name, "run", performance.now() - start);
1846
- const own = stored;
1847
- stored = () => {
1848
- devtools()?.effect?.(scope, name, "cleanup", 0);
1849
- own();
1850
- };
1839
+ scope.cleanups.set(name, reportCleanup(scope, name, toCleanup(cleanup), start, true));
1840
+ }
1841
+ /**
1842
+ * The cleanup of a run as one function, for a value that the callback returned: a function, or
1843
+ * an object with `[Symbol.asyncDispose]` or `[Symbol.dispose]`. Any other value is no cleanup.
1844
+ */
1845
+ function toCleanup(value) {
1846
+ if (typeof value === "function") return value;
1847
+ if (typeof value === "object" && value !== null) {
1848
+ const dispose = value[Symbol.asyncDispose] ?? value[Symbol.dispose];
1849
+ if (typeof dispose === "function") return () => dispose.call(value);
1850
+ }
1851
+ }
1852
+ /**
1853
+ * The function that a scope stores for a run. With `catches`, a promise that a cleanup returns,
1854
+ * which fails, goes to `#try`. An async effect awaits the cleanup and sends its failure itself.
1855
+ * In development, each way that a cleanup runs reports it: the next run, a removed scope, a hidden
1856
+ * `#offscreen` body, or a page that navigation leaves.
1857
+ */
1858
+ function reportCleanup(scope, name, cleanup, start, catches) {
1859
+ if (DEV) devtools()?.effect?.(scope, name, "run", performance.now() - start);
1860
+ else if (!cleanup) return noop$1;
1861
+ return () => {
1862
+ if (DEV) devtools()?.effect?.(scope, name, "cleanup", 0);
1863
+ const result = cleanup?.();
1864
+ if (catches && result instanceof Promise) result.catch((error) => fail(scope, error));
1865
+ return result;
1866
+ };
1867
+ }
1868
+ /**
1869
+ * A run that reads a value that is still loading is skipped. It runs again when the value arrives,
1870
+ * unless a change ran it first. The cleanup of the run before has already run.
1871
+ */
1872
+ function skipEffect(scope, name, error, rerun) {
1873
+ const key = `${scope.id}:${name}`;
1874
+ const token = {};
1875
+ skipped.set(key, token);
1876
+ scope.cleanups.set(name, noop$1);
1877
+ function again() {
1878
+ if (skipped.get(key) === token && scopes.get(scope.id) === scope) rerun();
1879
+ }
1880
+ error.source.then(() => Promise.allSettled(loadingUpdates).then(again), (reason) => {
1881
+ if (skipped.get(key) === token) {
1882
+ skipped.delete(key);
1883
+ fail(scope, reason);
1884
+ }
1885
+ });
1886
+ }
1887
+ /**
1888
+ * Calls the callback of an async effect, as `effect` does. Only its synchronous part, up to the
1889
+ * first `await`, counts as running, so a write there does not run the effect again.
1890
+ */
1891
+ function enterEffect(scope, name, callback, client) {
1892
+ const key = `${scope.id}:${name}`;
1893
+ skipped.delete(key);
1894
+ const outer = origin;
1895
+ origin = key;
1896
+ if (!client) runningEffects++;
1897
+ try {
1898
+ return Promise.resolve(callback());
1899
+ } finally {
1900
+ origin = outer;
1901
+ if (!client) runningEffects--;
1851
1902
  }
1852
- scope.cleanups.set(name, stored);
1853
1903
  }
1854
1904
  function noop$1() {}
1855
1905
  //#endregion
@@ -1926,9 +1976,19 @@ function findStore(scope, read) {
1926
1976
  * value that changed since the server render is written now. The scope stops reading when it goes.
1927
1977
  */
1928
1978
  function subscribeSlot(scope, slot, found, repair, write) {
1979
+ const holds = found[HOLDS] === true;
1980
+ const read = () => {
1981
+ if (!holds) return found.get();
1982
+ try {
1983
+ return found.get();
1984
+ } catch (error) {
1985
+ return new MemoError(error);
1986
+ }
1987
+ };
1929
1988
  const listener = (value) => {
1930
- sendContext(() => writeSlot(scope, slot, value));
1989
+ sendContext(() => writeSlot(scope, slot, holds ? read() : value));
1931
1990
  };
1991
+ if (HAS_MODULE_MEMOS && repair && holds) found.s?.(scope.s[slot]);
1932
1992
  let bridged = false;
1933
1993
  let stop;
1934
1994
  if (HAS_BRIDGES && repair && isBridged(found)) {
@@ -1936,8 +1996,18 @@ function subscribeSlot(scope, slot, found, repair, write) {
1936
1996
  stop = found.subscribe(listener, scope.s[slot]);
1937
1997
  } else stop = found.subscribe(listener);
1938
1998
  (scope.stops ??= []).push(stop);
1999
+ const waits = pendingOf(found);
2000
+ if (waits) {
2001
+ const listener = (on) => sendContext(() => markPending(scope, slot, on));
2002
+ waits.q.add(listener);
2003
+ scope.stops.push(() => waits.q.delete(listener));
2004
+ if (waits.n) listener(true);
2005
+ }
1939
2006
  if (write) (scope.b ??= {})[slot] = (value) => found.set(value);
1940
- if (repair && !bridged && !sameData(found.get(), scope.s[slot])) sendContext(() => writeSlot(scope, slot, found.get()));
2007
+ if (repair && !bridged) {
2008
+ const current = read();
2009
+ if (!sameData(current, scope.s[slot])) sendContext(() => writeSlot(scope, slot, current));
2010
+ }
1941
2011
  }
1942
2012
  /** Links a read of `$store` that a scope resumed with. */
1943
2013
  function linkRead(scope, read) {
@@ -2081,6 +2151,84 @@ function resetGuesses() {
2081
2151
  if (source && scopes.has(scope.id) && !Object.is(scope.s[slot], source[0].s[source[1]])) set(scope, slot, source[0].s[source[1]]);
2082
2152
  }
2083
2153
  }
2154
+ /** The stores of `$optimistic` at the top level of a module that hold a guess. */
2155
+ const held$1 = /* @__PURE__ */ new Set();
2156
+ /** The guesses that already put the stores of modules back, with the calls of the page. */
2157
+ const linked = /* @__PURE__ */ new WeakSet();
2158
+ /**
2159
+ * The store of `$optimistic(source)` at the top level of a module: it follows the store `source`,
2160
+ * and an exported function writes a guess with `set`. The guess goes back to the source when the
2161
+ * source changes, or when every server call of the page finishes. On the server a write is
2162
+ * dropped, as the server holds no guess.
2163
+ */
2164
+ function optimisticStore(source) {
2165
+ const out = new Store(void 0);
2166
+ let count = 0;
2167
+ let guessed = false;
2168
+ let stop;
2169
+ function follow() {
2170
+ if (!stop) {
2171
+ out.v = source.get();
2172
+ stop = source.subscribe((value) => {
2173
+ reset(value);
2174
+ });
2175
+ }
2176
+ }
2177
+ function unfollow() {
2178
+ if (count === 0 && !guessed) {
2179
+ stop?.();
2180
+ stop = void 0;
2181
+ }
2182
+ }
2183
+ function reset(value) {
2184
+ guessed = false;
2185
+ held$1.delete(back);
2186
+ sendStore(out, value);
2187
+ unfollow();
2188
+ }
2189
+ function back() {
2190
+ if (guessed) reset(source.get());
2191
+ }
2192
+ return {
2193
+ get() {
2194
+ return guessed || count > 0 ? out.v : source.get();
2195
+ },
2196
+ set(value) {
2197
+ if (onServer()) return;
2198
+ follow();
2199
+ guessed = true;
2200
+ held$1.add(back);
2201
+ const all = guesses ?? setGuesses({
2202
+ map: /* @__PURE__ */ new Map(),
2203
+ same: sameSource,
2204
+ reset: resetGuesses
2205
+ });
2206
+ if (!linked.has(all)) {
2207
+ linked.add(all);
2208
+ const before = all.reset;
2209
+ all.reset = () => {
2210
+ before();
2211
+ for (const undo of held$1) undo();
2212
+ };
2213
+ }
2214
+ sendStore(out, value);
2215
+ },
2216
+ subscribe(listener) {
2217
+ const off = out.subscribe(listener);
2218
+ count++;
2219
+ follow();
2220
+ let done = false;
2221
+ return () => {
2222
+ if (!done) {
2223
+ done = true;
2224
+ off();
2225
+ count--;
2226
+ unfollow();
2227
+ }
2228
+ };
2229
+ }
2230
+ };
2231
+ }
2084
2232
  //#endregion
2085
2233
  //#region src/runtime/client/handlers.ts
2086
2234
  /** The modifiers that the wrappers of `brumate/events` put on a handler. */
@@ -2180,7 +2328,7 @@ function fieldValue(element, typed) {
2180
2328
  * `b-b` anchor, or from the nearest element around it that has one, which
2181
2329
  * the compiler checks is in the same scope.
2182
2330
  */
2183
- function handle(element, entry, event, typed) {
2331
+ function handle(element, entry, event, typed, trace) {
2184
2332
  const [ref, owner, encoded] = entry.split("@");
2185
2333
  const bound = encoded ? JSON.parse(decodeURIComponent(encoded)) : [];
2186
2334
  const anchor = owner ?? element.closest("[b-b]")?.getAttribute("b-b")?.split(":")[0];
@@ -2207,10 +2355,14 @@ function handle(element, entry, event, typed) {
2207
2355
  children,
2208
2356
  code
2209
2357
  ]).then(([handler]) => handler);
2358
+ if (TRACE && trace) {
2359
+ trace.waits ||= !modules.has(ref.split("#")[0]) || !!children || !!code;
2360
+ loaded.then(() => trace.ready(), (error) => trace.ready(true, error));
2361
+ }
2210
2362
  const started = lastHandler.then(() => loaded).then((handler) => {
2211
- if (!DEV) return { value: pass(() => handler(scope, ...args)) };
2363
+ if (!DEV) return { value: TRACE && trace ? trace.run(() => pass(() => handler(scope, ...args))) : pass(() => handler(scope, ...args)) };
2212
2364
  const ready = performance.now();
2213
- const value = pass(() => handler(scope, ...args));
2365
+ const value = TRACE && trace ? trace.run(() => pass(() => handler(scope, ...args))) : pass(() => handler(scope, ...args));
2214
2366
  devtools()?.handled?.({
2215
2367
  ref,
2216
2368
  element,
@@ -2225,8 +2377,17 @@ function handle(element, entry, event, typed) {
2225
2377
  lastHandler = started.catch(() => {});
2226
2378
  return started.then((result) => result.value).catch((error) => {
2227
2379
  fail(scope, error);
2380
+ if (TRACE) trace?.fail(error);
2228
2381
  });
2229
2382
  }
2383
+ /** The span of a call of a server function. It has no argument, result or query string. */
2384
+ function traceCall(id, parent) {
2385
+ const route = `${rpcPrefix}/${id}`;
2386
+ return traceRequest("brumate.fetch", id, route, {
2387
+ "http.method": "POST",
2388
+ "http.route": route
2389
+ }, parent);
2390
+ }
2230
2391
  /** Renders the attributes of a form or button that posts to a server function. */
2231
2392
  function action(name, id, method, result) {
2232
2393
  return actionAttributes(rpcPrefix, name, id, method, result, build);
@@ -2236,12 +2397,14 @@ function action(name, id, method, result) {
2236
2397
  * call loads, so the core holds only this.
2237
2398
  */
2238
2399
  function submitAction(form, submitter) {
2239
- import("./rpc-kVB0Ujdx.js").then((module) => module.sendAction(form, submitter));
2400
+ const trace = TRACE ? traceCall(form.getAttribute("b-action")) : void 0;
2401
+ import("./rpc-DOdrekhP.js").then((module) => module.sendAction(form, submitter, trace));
2240
2402
  }
2241
2403
  /** Calls a server function. */
2242
2404
  async function rpc(id, args) {
2243
2405
  const signal = memoSignal();
2244
- return track(import("./rpc-kVB0Ujdx.js").then((module) => module.call(rpcPrefix, id, args, signal)));
2406
+ const trace = TRACE ? traceCall(id, traceContext()) : void 0;
2407
+ return track(import("./rpc-DOdrekhP.js").then((module) => module.call(rpcPrefix, id, args, signal, trace)));
2245
2408
  }
2246
2409
  /** A function prop rendered on the client calls the parent's exported handler. */
2247
2410
  function handlerProp(value, ref, scope, bound = [], modifiers) {
@@ -3702,7 +3865,7 @@ function drop(at) {
3702
3865
  * nothing waits, otherwise when the waits end. A block that asks again for the key that it
3703
3866
  * holds keeps waiting, and another key drops the held body.
3704
3867
  */
3705
- function hold(at, key, render, show) {
3868
+ function hold$1(at, key, render, show) {
3706
3869
  const held = holds.get(at);
3707
3870
  if (held && Object.is(held[0], key)) {
3708
3871
  held[2] = false;
@@ -3734,7 +3897,7 @@ function swap(scope, kinds, start, key, render, mark) {
3734
3897
  for (const child of scope.children ?? []) if (!old.has(child)) made.push(child);
3735
3898
  return out;
3736
3899
  }
3737
- hold(start, key, renderNew, (out) => {
3900
+ hold$1(start, key, renderNew, (out) => {
3738
3901
  for (const child of Array.from(scope.children ?? [])) if (kinds.includes(child.k) && !made.includes(child)) destroy(child);
3739
3902
  const end = rangeEnd(start);
3740
3903
  removeBlock(scope, [], start, end);
@@ -4029,7 +4192,7 @@ function fill(scope, anchor, render, kinds = [], holderKind, holderAnchor) {
4029
4192
  if (!start || start.data.split(":").length > 2) return;
4030
4193
  if (HAS_ROOT_WAIT) {
4031
4194
  const body = inPlace(scope, render, holderKind, holderAnchor);
4032
- hold(start, 1, () => body(scope), (out) => {
4195
+ hold$1(start, 1, () => body(scope), (out) => {
4033
4196
  start.data += ":1";
4034
4197
  const end = rangeEnd(start);
4035
4198
  removeBlock(scope, kinds, start, end);
@@ -4058,7 +4221,7 @@ function offscreen(scope, anchor, value, render, kind, holderKind, holderAnchor)
4058
4221
  if (state === "-1") {
4059
4222
  if (HAS_ROOT_WAIT) {
4060
4223
  const body = inPlace(scope, render, holderKind, holderAnchor);
4061
- hold(start, 1, () => body(scope), (out) => insertHTML(end, out));
4224
+ hold$1(start, 1, () => body(scope), (out) => insertHTML(end, out));
4062
4225
  return;
4063
4226
  }
4064
4227
  insertHTML(end, inPlace(scope, render, holderKind, holderAnchor)(scope));
@@ -4299,7 +4462,7 @@ function list(scope, anchor, items, key, given, assign, givenFallback, fallbackK
4299
4462
  if (count === 0 && !(park && park.total > 0)) {
4300
4463
  if (previous.size === 0 && others) return;
4301
4464
  if (HAS_ROOT_WAIT) {
4302
- hold(start, 0, () => fallback ? fallback(scope) : "", (out) => {
4465
+ hold$1(start, 0, () => fallback ? fallback(scope) : "", (out) => {
4303
4466
  removeBlock(scope, [], start, end);
4304
4467
  insertHTML(end, out);
4305
4468
  });
@@ -4587,6 +4750,99 @@ function addStyle(id, css) {
4587
4750
  return "";
4588
4751
  }
4589
4752
  //#endregion
4753
+ //#region src/runtime/client/async-effect.ts
4754
+ const runs = /* @__PURE__ */ new WeakMap();
4755
+ /**
4756
+ * Runs an async effect, or a `$client` callback when `client` is set. One run goes at a time: a
4757
+ * change while it is busy makes one run after it, and after its cleanup, has settled.
4758
+ */
4759
+ function asyncEffect(scope, name, callback, client) {
4760
+ if (hiding?.paused(scope, name)) return;
4761
+ let byName = runs.get(scope);
4762
+ if (!byName) {
4763
+ byName = /* @__PURE__ */ new Map();
4764
+ runs.set(scope, byName);
4765
+ }
4766
+ let run = byName.get(name);
4767
+ if (!run) {
4768
+ run = { callback };
4769
+ byName.set(name, run);
4770
+ }
4771
+ run.callback = callback;
4772
+ run.client = client;
4773
+ if (run.busy) {
4774
+ run.again = true;
4775
+ return;
4776
+ }
4777
+ scope.cleanups ??= /* @__PURE__ */ new Map();
4778
+ run.busy = true;
4779
+ const own = run;
4780
+ const token = { gone: false };
4781
+ scope.cleanups.set(name, () => stop(scope, name, own, token));
4782
+ hold(scope, name, run, execute(scope, name, run, token));
4783
+ }
4784
+ /** Marks the run as busy until its work settles, and starts the run that waited. */
4785
+ function hold(scope, name, run, work) {
4786
+ run.busy = true;
4787
+ work.then(() => {
4788
+ run.busy = false;
4789
+ if (run.again) {
4790
+ run.again = false;
4791
+ if (scopes.get(scope.id) === scope) asyncEffect(scope, name, run.callback, run.client);
4792
+ }
4793
+ });
4794
+ }
4795
+ /**
4796
+ * The cleanup that the scope calls when a body hides, a scope goes or a page is left. It never
4797
+ * waits. A run that is pending cleans up when it settles, and an idle one cleans up at once.
4798
+ */
4799
+ function stop(scope, name, run, token) {
4800
+ token.gone = true;
4801
+ const cleanup = run.cleanup;
4802
+ if (!run.busy && cleanup) {
4803
+ run.cleanup = void 0;
4804
+ hold(scope, name, run, clean(scope, cleanup));
4805
+ }
4806
+ }
4807
+ /** Runs a cleanup and waits for it. A failure goes to `#try`. */
4808
+ async function clean(scope, cleanup) {
4809
+ try {
4810
+ await cleanup();
4811
+ } catch (error) {
4812
+ fail(scope, error);
4813
+ }
4814
+ }
4815
+ async function execute(scope, name, run, token) {
4816
+ const before = run.cleanup;
4817
+ if (before) {
4818
+ run.cleanup = void 0;
4819
+ await clean(scope, before);
4820
+ run.again = false;
4821
+ }
4822
+ if (token.gone) return;
4823
+ const start = DEV ? performance.now() : 0;
4824
+ let value;
4825
+ if (DEV) devtools()?.effect?.(scope, name, "pending", 0);
4826
+ try {
4827
+ value = await enterEffect(scope, name, run.callback, run.client);
4828
+ } catch (error) {
4829
+ if (error instanceof NotReady) {
4830
+ if (DEV) devtools()?.effect?.(scope, name, "skip", 0);
4831
+ skipEffect(scope, name, error, () => asyncEffect(scope, name, run.callback, run.client));
4832
+ return;
4833
+ }
4834
+ if (DEV) devtools()?.effect?.(scope, name, "run", performance.now() - start);
4835
+ fail(scope, error);
4836
+ return;
4837
+ }
4838
+ const stored = reportCleanup(scope, name, toCleanup(value), start);
4839
+ if (token.gone) {
4840
+ await clean(scope, stored);
4841
+ return;
4842
+ }
4843
+ run.cleanup = stored;
4844
+ }
4845
+ //#endregion
4590
4846
  //#region src/runtime/client/search.ts
4591
4847
  /** The signals of the page that follow a parameter, by scope and slot. */
4592
4848
  const bound = /* @__PURE__ */ new Map();
@@ -4739,6 +4995,6 @@ const loader = {
4739
4995
  };
4740
4996
  function noop() {}
4741
4997
  //#endregion
4742
- export { setSlots as $, unreadMemo as $t, reveal as A, guess as At, prop as B, binding as Bt, fillAttrs as C, removeRoot as Ct, fillValue as D, rpc as Dt, fillSpread as E, handlerProp as Et, content as F, setGlobal as Ft, dynamicNodes as G, get as Gt, component as H, cells as Ht, portalTo as I, storeUpdate as It, memoNow as J, pend as Jt, elementAt as K, isBound as Kt, restRef as L, toStore as Lt, wait as M, consumeContext as Mt, attr as N, consumeStore as Nt, keepValue as O, spread as Ot, attrs as P, provideValue as Pt, setItem as Q, timed as Qt, text as R, updateRoute as Rt, countLoads as S, skew as Sn, remount as St, fillSettled as T, handle as Tt, componentNodes as U, effect as Ut, spreadProps as V, bindings as Vt, dynamic as W, gate as Wt, readMemo as X, resolve as Xt, place as Y, pending as Yt, renderMemo as Z, set as Zt, rekey as _, DEVTOOLS as _n, dispose as _t, addPortal as a, templateCall as an, keep as at, after as b, rpcPrefix as bn, leavePage as bt, setVar as c, createScope as cn, markBlock as ct, windowList as d, makeId as dn, setAttr as dt, update as en, appendText as et, windowStart as f, removeScope as fn, setAttrText as ft, offscreen as g, loadModule as gn, template as gt, held as h, nameComment as hn, setSpread as ht, addHead as i, insert as in, fillList as it, started as j, track as jt, loading as k, submitAction as kt, list as l, descendants as ln, nodes as lt, fill as m, sink as mn, setOn as mt, paramEffect as n, fail as nn, clone as nt, addStyle as o, title as on, keepText as ot, branch as p, setOwner as pn, setContent as pt, foreignNodes as q, memo as qt, searchParam as r, children as rn, fillBranch as rt, deferInBrowser as s, afterInsert as sn, listNodes as st, loader as t, updated as tn, branchNodes as tt, toList as u, getScope as un, putText as ut, reset as v, build as vn, forget as vt, fillPend as w, action as wt, attempt as x, scopes as xn, leaveRoutes as xt, retag as y, hooks as yn, init as yt, writeText as z, asyncMemo as zt };
4998
+ export { setItem as $, set as $t, loading as A, submitAction as At, writeText as B, updateRoute as Bt, countLoads as C, skew as Cn, remount as Ct, fillSpread as D, handlerProp as Dt, fillSettled as E, handle as Et, attrs as F, consumeStore as Ft, dynamic as G, effect as Gt, spreadProps as H, binding as Ht, content as I, provideValue as It, foreignNodes as J, isBound as Jt, dynamicNodes as K, gate as Kt, portalTo as L, setGlobal as Lt, started as M, optimisticStore as Mt, wait as N, track as Nt, fillValue as O, rpc as Ot, attr as P, consumeContext as Pt, renderMemo as Q, resolve as Qt, restRef as R, storeUpdate as Rt, attempt as S, scopes as Sn, leaveRoutes as St, fillPend as T, action as Tt, component as U, bindings as Ut, prop as V, asyncMemo as Vt, componentNodes as W, cells as Wt, place as X, pend as Xt, memoNow as Y, memo as Yt, readMemo as Z, pending as Zt, offscreen as _, loadModule as _n, template as _t, addHead as a, children as an, fillList as at, retag as b, hooks as bn, init as bt, deferInBrowser as c, title as cn, listNodes as ct, toList as d, descendants as dn, putText as dt, timed as en, setSlots as et, windowList as f, makeId as fn, setAttr as ft, held as g, nameComment as gn, setSpread as gt, fill as h, sink as hn, setOn as ht, asyncEffect as i, fail as in, fillBranch as it, reveal as j, guess as jt, keepValue as k, spread as kt, setVar as l, afterInsert as ln, markBlock as lt, branch as m, setOwner as mn, setContent as mt, paramEffect as n, update as nn, branchNodes as nt, addPortal as o, insert as on, keep as ot, windowStart as p, removeScope as pn, setAttrText as pt, elementAt as q, get as qt, searchParam as r, updated as rn, clone as rt, addStyle as s, templateCall as sn, keepText as st, loader as t, unreadMemo as tn, appendText as tt, list as u, createScope as un, nodes as ut, rekey as v, DEVTOOLS as vn, dispose as vt, fillAttrs as w, removeRoot as wt, after as x, rpcPrefix as xn, leavePage as xt, reset as y, build as yn, forget as yt, text as z, toStore as zt };
4743
4999
 
4744
- //# sourceMappingURL=client-CwVcmymi.js.map
5000
+ //# sourceMappingURL=client-B-ww-PQ7.js.map