@martintrojer/mu 0.4.2 → 0.4.3

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.
package/dist/cli.js CHANGED
@@ -13995,7 +13995,8 @@ var init_workspaces2 = __esm({
13995
13995
 
13996
13996
  // src/cli/tui/state.ts
13997
13997
  import { useEffect as useEffect9, useRef as useRef7, useState as useState17 } from "react";
13998
- function useDashboardSnapshot(db, workstream, tickMs, enabled, refreshNonce = 0, loaders = DEFAULT_LOADERS) {
13998
+ function useDashboardSnapshot(db, workstream, tickMs, enabled, refreshNonce = 0, loaders = DEFAULT_LOADERS, options = {}) {
13999
+ const publishNoopSlowTicks = options.publishNoopSlowTicks === true;
13999
14000
  const [data, setData] = useState17({
14000
14001
  data: null,
14001
14002
  error: null
@@ -14005,11 +14006,15 @@ function useDashboardSnapshot(db, workstream, tickMs, enabled, refreshNonce = 0,
14005
14006
  const [slowTickNonce, setSlowTickNonce] = useState17(0);
14006
14007
  const latestFastRef = useRef7(null);
14007
14008
  const slowRef = useRef7(null);
14009
+ const publishedKeyRef = useRef7("");
14010
+ const errorRef = useRef7(null);
14008
14011
  const lastWsRef = useRef7(workstream);
14009
14012
  if (shouldDiscardForWorkstream(lastWsRef.current, workstream)) {
14010
14013
  lastWsRef.current = workstream;
14011
14014
  slowRef.current = null;
14012
14015
  latestFastRef.current = null;
14016
+ publishedKeyRef.current = "";
14017
+ errorRef.current = null;
14013
14018
  setData({ data: null, error: null });
14014
14019
  setLastTickMs(0);
14015
14020
  }
@@ -14019,7 +14024,6 @@ function useDashboardSnapshot(db, workstream, tickMs, enabled, refreshNonce = 0,
14019
14024
  let cancelled = false;
14020
14025
  const tick = async () => {
14021
14026
  if (cancelled) return;
14022
- setFastTickNonce((n) => n + 1);
14023
14027
  const t0 = performance.now();
14024
14028
  try {
14025
14029
  const fast = await loaders.fast(db, workstream, FAST_OPTS);
@@ -14027,12 +14031,13 @@ function useDashboardSnapshot(db, workstream, tickMs, enabled, refreshNonce = 0,
14027
14031
  latestFastRef.current = fast;
14028
14032
  const fresh = mergeSnapshotFastSlow(fast, slowRef.current);
14029
14033
  const dur = performance.now() - t0;
14030
- setLastTickMs(dur);
14031
- publishSnapshot(fresh, setData);
14034
+ if (publishSnapshot(fresh, setData, publishedKeyRef, errorRef)) {
14035
+ setLastTickMs(dur);
14036
+ setFastTickNonce((n) => n + 1);
14037
+ }
14032
14038
  } catch (err) {
14033
14039
  if (cancelled) return;
14034
- const msg = String(err);
14035
- setData((prev) => prev.error === msg ? prev : { ...prev, error: msg });
14040
+ publishError(String(err), setData, errorRef);
14036
14041
  }
14037
14042
  };
14038
14043
  void tick();
@@ -14048,7 +14053,6 @@ function useDashboardSnapshot(db, workstream, tickMs, enabled, refreshNonce = 0,
14048
14053
  let cancelled = false;
14049
14054
  const slowTick = async () => {
14050
14055
  if (cancelled) return;
14051
- setSlowTickNonce((n) => n + 1);
14052
14056
  try {
14053
14057
  const slow = await loaders.slow(
14054
14058
  db,
@@ -14059,11 +14063,13 @@ function useDashboardSnapshot(db, workstream, tickMs, enabled, refreshNonce = 0,
14059
14063
  if (cancelled) return;
14060
14064
  slowRef.current = slow;
14061
14065
  const fast = latestFastRef.current;
14062
- if (fast !== null) publishSnapshot(mergeSnapshotFastSlow(fast, slow), setData);
14066
+ const changed = fast !== null && publishSnapshot(mergeSnapshotFastSlow(fast, slow), setData, publishedKeyRef, errorRef);
14067
+ if (changed || fast !== null && publishNoopSlowTicks) {
14068
+ setSlowTickNonce((n) => n + 1);
14069
+ }
14063
14070
  } catch (err) {
14064
14071
  if (cancelled) return;
14065
- const msg = String(err);
14066
- setData((prev) => prev.error === msg ? prev : { ...prev, error: msg });
14072
+ publishError(String(err), setData, errorRef);
14067
14073
  }
14068
14074
  };
14069
14075
  void slowTick();
@@ -14072,19 +14078,24 @@ function useDashboardSnapshot(db, workstream, tickMs, enabled, refreshNonce = 0,
14072
14078
  cancelled = true;
14073
14079
  clearInterval(id);
14074
14080
  };
14075
- }, [db, workstream, enabled, refreshNonce, loaders]);
14081
+ }, [db, workstream, enabled, refreshNonce, loaders, publishNoopSlowTicks]);
14076
14082
  return { data: data.data, fastTickNonce, slowTickNonce, lastTickMs, error: data.error };
14077
14083
  }
14078
14084
  function shouldDiscardForWorkstream(prev, next) {
14079
14085
  return prev !== next;
14080
14086
  }
14081
- function publishSnapshot(fresh, writeData) {
14087
+ function publishSnapshot(fresh, writeData, publishedKeyRef, errorRef) {
14082
14088
  const freshKey = snapshotKeyString(fresh);
14083
- writeData((prev) => {
14084
- const prevKey = prev.data === null ? "" : snapshotKeyString(prev.data);
14085
- if (prev.error === null && prevKey === freshKey) return prev;
14086
- return { data: fresh, error: null };
14087
- });
14089
+ if (errorRef.current === null && publishedKeyRef.current === freshKey) return false;
14090
+ publishedKeyRef.current = freshKey;
14091
+ errorRef.current = null;
14092
+ writeData(() => ({ data: fresh, error: null }));
14093
+ return true;
14094
+ }
14095
+ function publishError(message, writeData, errorRef) {
14096
+ if (errorRef.current === message) return;
14097
+ errorRef.current = message;
14098
+ writeData((prev) => ({ ...prev, error: message }));
14088
14099
  }
14089
14100
  function clampTick(ms) {
14090
14101
  return Math.max(TICK_FLOOR_MS, Math.min(TICK_CEILING_MS, ms));
@@ -14166,8 +14177,7 @@ var init_state2 = __esm({
14166
14177
  slow: loadWorkstreamSnapshotSlow
14167
14178
  };
14168
14179
  FAST_OPTS = {
14169
- eventLimit: 200,
14170
- withAllTasks: true
14180
+ eventLimit: 200
14171
14181
  };
14172
14182
  SLOW_OPTS = {
14173
14183
  withDirty: true,
@@ -14592,7 +14602,9 @@ function App({ db, workstreams, initialActive = 0 }) {
14592
14602
  }, []);
14593
14603
  const safeActive = Math.max(0, Math.min(activeWs, workstreams.length - 1));
14594
14604
  const workstream = workstreams[safeActive] ?? "";
14595
- const snap = useDashboardSnapshot(db, workstream, tickMs, true, refreshNonce);
14605
+ const snap = useDashboardSnapshot(db, workstream, tickMs, true, refreshNonce, void 0, {
14606
+ publishNoopSlowTicks: popup === 0 || popup === 1 || popup === 5
14607
+ });
14596
14608
  const parkedSet = useMemo9(() => {
14597
14609
  void snap.slowTickNonce;
14598
14610
  const set = /* @__PURE__ */ new Set();