Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/react/src/toast/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,26 @@ describe('ToastStore', () => {

expect(selectors.toast(store.state, 'b')?.transitionStatus).not.toBe('ending');
});

it('accumulates active time across hover cycles so the toast still dismisses', () => {
vi.useFakeTimers();
const store = createStore([]);

store.addToast({ id: 'a', title: 'a', timeout: 100 });

vi.advanceTimersByTime(40);
store.pauseTimers();
expect(selectors.toast(store.state, 'a')?.transitionStatus).not.toBe('ending');

store.resumeTimers();
vi.advanceTimersByTime(40);
store.pauseTimers();
expect(selectors.toast(store.state, 'a')?.transitionStatus).not.toBe('ending');

store.resumeTimers();
vi.advanceTimersByTime(40);

expect(selectors.toast(store.state, 'a')?.transitionStatus).toBe('ending');
});
});
});
2 changes: 1 addition & 1 deletion packages/react/src/toast/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export class ToastStore extends ReactStore<State, {}, typeof selectors> {
if (timer.timeout) {
timer.timeout.clear();
const elapsed = Date.now() - timer.start;
const remaining = timer.delay - elapsed;
const remaining = timer.remaining - elapsed;

@sai6855 sai6855 Jul 17, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the toast never dismisses

timer.delay holds the entire duration, while timer.remaining holds the time left. pauseTimers was calculating the remaining time from timer.delay instead of timer.remaining, so repeated hover/leave cycles kept restoring almost the full duration.

Walkthrough (delay = 10s):

Step Action Elapsed this segment Correct remaining Buggy code gives
1 Enter after 1s, leave after 1s 1s 10 − 1 = 9s 10 − 1 = 9s ✓
2 Enter after 1s, leave after 1s 1s 9 − 1 = 8s 10 − 1 = 9s ✗

At step 2, the remaining time should be 10 − 1 − 1 = 8s, but the code calculated delay − elapsed = 10 − 1 = 9s, ignoring the 1 second already consumed in step 1. Every hover/leave cycle resets the remaining time toward the full duration, so the toast never expires.

Fix: On resume, sync timer.delay = timer.remaining so the next pause computes delay − elapsed against the actual remaining time.


timer.remaining = remaining > 0 ? remaining : 0;
Comment on lines 360 to 364
}
});
Expand Down
Loading