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: reset toast countdown on a same-id duration-only swap (#8117)

[._.]/ Adam Eivy8a6aef5aa95a
diff --git a/client/src/components/ui/Toast.jsx b/client/src/components/ui/Toast.jsx
index 36ad1ac573..e0aaa8ad61 100644
--- a/client/src/components/ui/Toast.jsx
+++ b/client/src/components/ui/Toast.jsx
@@ -270,18 +270,22 @@ 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 content swap
- // (a loading→success toast) the same way the collapse-reset effect above
- // does — comparing `t.content`/`t.type` by reference, which only change
- // when `add()` actually ran — and restarts the countdown from the NEW
- // duration rather than treating the swap as a re-render of the old one.
+ // 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.
const remainingRef = useRef(t.duration);
- const prevIdentityRef = useRef([t.content, t.type]);
+ const prevIdentityRef = useRef([t.content, t.type, t.duration]);
useEffect(() => {
- const [prevContent, prevType] = prevIdentityRef.current;
- const isNewArm = prevContent !== t.content || prevType !== t.type;
- prevIdentityRef.current = [t.content, t.type];
+ 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];
if (t.duration === Infinity) return undefined;
if (isNewArm) remainingRef.current = t.duration;
diff --git a/client/src/components/ui/Toast.test.jsx b/client/src/components/ui/Toast.test.jsx
index 24c74e6c7b..acbfe972f2 100644
--- a/client/src/components/ui/Toast.test.jsx
+++ b/client/src/components/ui/Toast.test.jsx
@@ -397,6 +397,23 @@ describe('finite toasts pause their dismiss timer while held', () => {
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
+ // its stale Infinity value, and `setTimeout(fn, Infinity)` clamps to 0 in
+ // JS — the toast would have dismissed on the very next tick instead of
+ // honouring the new duration.
+ act(() => { toast('Reconnecting to the agent...', { id: 'agent-status', duration: Infinity }); });
+ advance(50000); // never dismisses on its own while Infinity
+
+ act(() => { toast('Reconnecting to the agent...', { id: 'agent-status', duration: 5000 }); });
+
+ advance(4999);
+ expect(screen.getByRole('status')).toBeVisible();
+ advance(1);
+ expect(screen.queryByRole('status')).toBeNull();
+ });
+
it('restarts the countdown from the new duration on a same-id content swap (loading → success)', () => {
act(() => { toast.loading('Applying fix...', { id: 'apply-fix' }); });
advance(50000); // loading is Infinity — never dismisses on its own