Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: flush a goal progress value set while the previous update is still in flight (#3520)
[._.]/ Adam Eivydc1949cc8d26
diff --git a/client/src/components/goals/ProgressSlider.jsx b/client/src/components/goals/ProgressSlider.jsxindex 94df2fdf7f..b474a05294 100644--- a/client/src/components/goals/ProgressSlider.jsx+++ b/client/src/components/goals/ProgressSlider.jsx@@ -6,7 +6,6 @@ export default function ProgressSlider({ goal, onCommit }) {const stored = goal.progress ?? 0;const [draft, setDraft] = useState(stored);const [dragging, setDragging] = useState(false);- const [saving, setSaving] = useState(false);// Per-goal so the label/input pairing stays unique if two panels ever co-exist.const sliderId = `goal-progress-${goal.id}`;@@ -23,32 +22,56 @@ export default function ProgressSlider({ goal, onCommit }) {if (!dragging) setDraft(stored);}, [stored, dragging]);- const commit = async () => {- setDragging(false);- // Re-entrancy guard: touch devices fire touchend AND a synthesized mouseup, and- // a blur can follow both — none of them should re-send an in-flight percentage.- if (saving || draft === stored) return;- setSaving(true);+ // In-flight bookkeeping lives in refs, not state: a touch release fires touchend+ // AND a synthesized mouseup in the same task, so a state flag would still read+ // stale in the second handler and send the same percentage twice.+ const inFlight = useRef(null);+ const queued = useRef(null);++ const send = async (value) => {+ inFlight.current = value;let saved = false;try {// Only an explicit `false` means "the server never took this" — a handler// that returns nothing keeps the pre-#3520 optimistic behavior.- saved = (await onCommit(draft)) !== false;+ saved = (await onCommit(value)) !== false;} catch {// Deliberately swallowed — `request()` already toasted the failure, so this- // stays a single-layer error UI. `try/finally` rather than `.catch()`: a- // handler that throws before returning a promise would otherwise latch- // `saving` on and freeze the slider on an unsaved value.- } finally {- setSaving(false);+ // stays a single-layer error UI. `try` rather than `.catch()`: a handler that+ // throws before returning a promise would otherwise latch `inFlight` on and+ // freeze the slider on an unsaved value.+ }+ inFlight.current = null;+ const next = queued.current;+ queued.current = null;+ // A percentage the user set while this one was in flight supersedes it, whether+ // it succeeded or not — dropping it would leave the slider showing a value that+ // was never sent, which is the same lie this issue is about.+ if (next !== null && next !== value) {+ send(next);+ return;}// The reset is the fix: without it the panel keeps advertising a percentage the// database rejected until the user closes and re-opens it. Read through the ref- // rather than this closure's `stored` so a value that arrived while the request- // was in flight isn't undone by a rollback to the pre-commit snapshot.+ // rather than a render closure so a value that arrived while the request was in+ // flight isn't undone by a rollback to the pre-commit snapshot.if (!saved) setDraft(lastStored.current);};+ const commit = () => {+ setDragging(false);+ // What the server already has, or is about to: re-releasing on that percentage+ // (touchend + mouseup, a blur right after, a key release that changed nothing)+ // must not re-send it.+ const settled = queued.current ?? inFlight.current ?? stored;+ if (draft === settled) return;+ if (inFlight.current !== null) {+ queued.current = draft;+ return;+ }+ send(draft);+ };+return (<div><div className="flex items-center justify-between mb-1.5">diff --git a/client/src/components/goals/ProgressSlider.test.jsx b/client/src/components/goals/ProgressSlider.test.jsxindex a97bf50569..3e15f518e0 100644--- a/client/src/components/goals/ProgressSlider.test.jsx+++ b/client/src/components/goals/ProgressSlider.test.jsx@@ -114,19 +114,80 @@ describe('ProgressSlider commit', () => {expect(screen.getByText('85%')).toBeTruthy();});- it('ignores a second release while the first commit is still in flight', async () => {+ it('sends one request when a touch release also fires a synthesized mouseup', async () => {+ let release;+ const onCommit = vi.fn(() => new Promise((resolve) => { release = resolve; }));+ const { slider } = renderSlider(onCommit);++ drag(slider, 85);+ // Both events land in the same task, with no re-render in between — a `useState`+ // in-flight flag would still read stale in the second handler and double-send.+ await act(async () => {+ fireEvent.touchEnd(slider);+ fireEvent.mouseUp(slider);+ });++ expect(onCommit).toHaveBeenCalledTimes(1);++ await act(async () => { release(true); });+ expect(onCommit).toHaveBeenCalledTimes(1);+ });++ // Dropping the second value would leave the slider showing a percentage that was+ // never sent — the same lie as the bug this issue is about.+ it('sends a value set while a commit is in flight once that commit resolves', async () => {let release;const onCommit = vi.fn(() => new Promise((resolve) => { release = resolve; }));const { slider } = renderSlider(onCommit);drag(slider, 85);- // Touch devices fire touchend and a synthesized mouseup for one release.- await act(async () => { fireEvent.touchEnd(slider); });await act(async () => { fireEvent.mouseUp(slider); });+ expect(onCommit).toHaveBeenCalledTimes(1);+ // Second interaction lands before the first request is answered.+ drag(slider, 90);+ await act(async () => { fireEvent.mouseUp(slider); });expect(onCommit).toHaveBeenCalledTimes(1);await act(async () => { release(true); });++ expect(onCommit).toHaveBeenNthCalledWith(1, 85);+ expect(onCommit).toHaveBeenNthCalledWith(2, 90);+ expect(screen.getByText('90%')).toBeTruthy();+ });++ // The queued value replaces the failed one instead of being rolled back over.+ it('sends a value queued behind a commit that fails', async () => {+ let release;+ const onCommit = vi.fn(() => new Promise((resolve) => { release = resolve; }));+ const { slider } = renderSlider(onCommit);++ drag(slider, 85);+ await act(async () => { fireEvent.mouseUp(slider); });+ drag(slider, 90);+ await act(async () => { fireEvent.mouseUp(slider); });++ await act(async () => { release(false); });++ expect(onCommit).toHaveBeenCalledTimes(2);+ expect(onCommit).toHaveBeenNthCalledWith(2, 90);+ expect(screen.getByText('90%')).toBeTruthy();+ });++ it('does not re-send a release that lands on the percentage already in flight', async () => {+ let release;+ const onCommit = vi.fn(() => new Promise((resolve) => { release = resolve; }));+ const { slider } = renderSlider(onCommit);++ drag(slider, 85);+ await act(async () => { fireEvent.mouseUp(slider); });+ drag(slider, 90);+ drag(slider, 85);+ await act(async () => { fireEvent.mouseUp(slider); });++ await act(async () => { release(true); });++ expect(onCommit).toHaveBeenCalledTimes(1);});// Arrow/Home/End move a range input without ever firing mouseup.