Skip to content

[toast] Fix remaining timer calculation in ToastStore - #5261

Merged
sai6855 merged 3 commits into
mui:masterfrom
sai6855:timer-fix
Jul 20, 2026
Merged

sai6855 merged 3 commits into
mui:masterfrom
sai6855:timer-fix

Conversation

@sai6855

@sai6855 sai6855 commented Jul 17, 2026

Copy link
Copy Markdown
Member

@pkg-pr-new

pkg-pr-new Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

commit: 916f12a

Comment thread packages/react/src/toast/store.ts
@sai6855 sai6855 added the type: bug It doesn't behave as expected. label Jul 17, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+4B(0.00%) 🔺+2B(0.00%)

Details of bundle changes

Performance

Total duration: 1,350.47 ms +67.00 ms(+5.2%) | Renders: 78 (+0) | Paint: 2,109.96 ms +103.07 ms(+5.1%)

Test Duration Renders
Scroll Area mount (300 instances) 106.12 ms 🔺+22.47 ms(+26.9%) 3 (+0)
Menu open (500 items) 77.74 ms 🔺+13.07 ms(+20.2%) 12 (+0)

12 tests within noise — details

Metric alarms

Test Metric Change
Scroll Area mount (300 instances) bench:paint 🔺 +22.16 ms

Check out the code infra dashboard for more information about this PR.

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.


@netlify

netlify Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 916f12a
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a5a28a84ef46e0008a37486
😎 Deploy Preview https://deploy-preview-5261--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@sai6855
sai6855 marked this pull request as ready for review July 17, 2026 13:05
Copilot AI review requested due to automatic review settings July 17, 2026 13:05
@sai6855
sai6855 requested a review from jjenzz as a code owner July 17, 2026 13:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the toast auto-dismiss timer bookkeeping so that paused/resumed timers correctly accumulate elapsed “active” time across multiple hover/focus pause cycles.

Changes:

  • Adjust remaining-time calculation in ToastStore.pauseTimers() to use timer.remaining rather than the original timer.delay.
  • Add a regression test covering multiple pause/resume cycles and ensuring the toast still dismisses after the configured timeout.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/react/src/toast/store.ts Fixes remaining-time calculation when pausing timers so time spent active is accumulated correctly across pauses.
packages/react/src/toast/store.test.ts Adds test coverage for accumulated active time across repeated hover/pause cycles.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 360 to 364
if (timer.timeout) {
timer.timeout.clear();
const elapsed = Date.now() - timer.start;
const remaining = timer.delay - elapsed;
const remaining = timer.remaining - elapsed;
timer.remaining = remaining > 0 ? remaining : 0;
@sai6855
sai6855 marked this pull request as draft July 17, 2026 13:13
@sai6855
sai6855 marked this pull request as ready for review July 17, 2026 13:24
@sai6855
sai6855 merged commit f6920f9 into mui:master Jul 20, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants