Skip to content

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

fix: restart toast countdown on every same-id re-add, not just a visible change (#8117)

[._.]/ Adam Eivybec3ab6d5759
diff --git a/client/src/components/ui/Toast.jsx b/client/src/components/ui/Toast.jsx
index c8fe6443e2..7c5e9919a0 100644
--- a/client/src/components/ui/Toast.jsx
+++ b/client/src/components/ui/Toast.jsx
@@ -279,22 +279,24 @@ function ToastItem({ t, toastOptions }) {
//
// `remainingRef` is the ms left on the countdown; it survives across
// pause/resume because a ref, unlike state, doesn't trigger its own
- // re-render/effect cycle. `prevIdentityRef` detects a same-id swap that
- // needs a fresh countdown — content/type by reference (the same signal the
- // collapse-reset effect above uses, since they only change identity when
- // `add()` actually ran) PLUS `duration` itself: a swap that keeps identical
- // content/type but changes just the duration (e.g. an Infinity toast
- // re-added with a finite one) must still reset — otherwise `remainingRef`
- // keeps holding the stale duration, and if that was `Infinity`,
- // `setTimeout(fn, Infinity)` clamps to 0 and the toast would dismiss
- // almost immediately instead of honouring the new duration.
+ // re-render/effect cycle. `prevSeqRef` detects a same-id re-add that needs
+ // a fresh countdown — `t.seq` (assigned in `add()`) bumps on EVERY call for
+ // this id, including one whose content/type/duration are byte-identical to
+ // what's already showing, matching the old behaviour where `add()` armed a
+ // brand-new timer on every call regardless of whether anything visibly
+ // changed. Comparing `content`/`type`/`duration` by value instead would
+ // miss that case (nothing would look different to React) and also miss a
+ // swap that keeps identical content/type but changes just the duration —
+ // e.g. an Infinity toast re-added as finite — where `remainingRef` would
+ // otherwise keep holding `Infinity`; `setTimeout(fn, Infinity)` clamps to 0
+ // in JS, so that toast would dismiss almost immediately instead of
+ // honouring its new duration.
const remainingRef = useRef(t.duration);
- const prevIdentityRef = useRef([t.content, t.type, t.duration]);
+ const prevSeqRef = useRef(t.seq);
useEffect(() => {
- const [prevContent, prevType, prevDuration] = prevIdentityRef.current;
- const isNewArm = prevContent !== t.content || prevType !== t.type || prevDuration !== t.duration;
- prevIdentityRef.current = [t.content, t.type, t.duration];
+ const isNewArm = prevSeqRef.current !== t.seq;
+ prevSeqRef.current = t.seq;
if (t.duration === Infinity) return undefined;
if (isNewArm) remainingRef.current = t.duration;
@@ -306,7 +308,7 @@ function ToastItem({ t, toastOptions }) {
clearTimeout(timer);
remainingRef.current = Math.max(0, remainingRef.current - (Date.now() - start));
};
- }, [t.id, t.duration, t.content, t.type, held]);
+ }, [t.id, t.duration, t.seq, held]);
// Re-entering `add()` with the same id replaces the entry in place (a
// loading→success swap, a coalesced AI-status error picking up another
diff --git a/client/src/components/ui/Toast.test.jsx b/client/src/components/ui/Toast.test.jsx
index 913538567e..1e8a826cc6 100644
--- a/client/src/components/ui/Toast.test.jsx
+++ b/client/src/components/ui/Toast.test.jsx
@@ -397,6 +397,26 @@ describe('finite toasts pause their dismiss timer while held', () => {
expect(screen.queryByRole('status')).toBeNull();
});
+ it('restarts the countdown on a same-id re-add whose content, type, and duration are all unchanged', () => {
+ // Regression: `add()` used to arm a brand-new timer on EVERY call for an
+ // id, even one whose content/type/duration are byte-identical to what's
+ // already showing (a caller "refreshing" the same toast). Comparing
+ // content/type/duration by value can't see that call happened at all —
+ // nothing looks different — so the fix has to key off something that
+ // changes on every add(), not just on a visible difference.
+ act(() => { toast('Still syncing...', { id: 'sync-status', duration: 8000 }); });
+ advance(6000); // 2s left
+
+ act(() => { toast('Still syncing...', { id: 'sync-status', duration: 8000 }); });
+
+ // If the countdown hadn't restarted, this would already be dismissed at
+ // the old deadline (6000 + 2000 = 8000, i.e. right about now).
+ advance(6001);
+ expect(screen.getByRole('status')).toBeVisible();
+ advance(1999);
+ expect(screen.queryByRole('status')).toBeNull();
+ });
+
it('restarts the countdown when a same-id swap changes only the duration, not the content', () => {
// Regression: an Infinity→finite swap that keeps identical content/type
// must still reset the countdown. `remainingRef` was previously left at