Skip to content

[toast] Prevent duplicate onClose calls for ending toasts#4280

Merged
atomiks merged 3 commits intomui:masterfrom
chuganzy:toast-on-close
Mar 11, 2026
Merged

[toast] Prevent duplicate onClose calls for ending toasts#4280
atomiks merged 3 commits intomui:masterfrom
chuganzy:toast-on-close

Conversation

@chuganzy
Copy link
Contributor

@chuganzy chuganzy commented Mar 6, 2026

This PR fixes an issue where onClose could be triggered multiple times when a toast is already in the ending state as pointed out here.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 6, 2026

commit: bf74137

@mui-bot
Copy link

mui-bot commented Mar 6, 2026

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+10B(0.00%) ▼-7B(0.00%)

Details of bundle changes


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

@netlify
Copy link

netlify bot commented Mar 6, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 8f3cc2e
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69b114dde1aeb6000808194a
😎 Deploy Preview https://deploy-preview-4280--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@zannager zannager added the component: toast Changes related to the toast component. label Mar 6, 2026
@atomiks
Copy link
Contributor

atomiks commented Mar 9, 2026

Codex Review

Overview

This patch now updates toast state before running onClose, and it extends the regression test so a toast can call close() from inside onClose without double-firing. The branch stays narrowly focused on the toast close path and the new test coverage matches the bug being fixed.

Findings (None)

No blocking issues found in this patch.

Confidence: 5/5

High confidence based on the full branch diff, the narrow implementation surface, and focused verification of the shared toast-manager code path.

Notes

  • Re-ran pnpm test:jsdom createToastManager --no-watch on the PR head.
  • Re-ran pnpm test:jsdom useToastManager --no-watch on the PR head.
  • The latest commit addresses the earlier re-entrant onClose concern by moving the callback after the state update and by strengthening the regression test to cover that sequence.

}
});

this.handleFocusManagement(toastId);
Copy link
Contributor Author

@chuganzy chuganzy Mar 10, 2026

Choose a reason for hiding this comment

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

This function is the only one with a side effect, so I moved it below to keep the order unchanged.
The execution order remains onClosefocus update (onFocus / onBlur).

Although this depends on the state internally, it only looks up the next (or prev) active toast, so I believe changing the position should not cause any issues.

@atomiks atomiks merged commit e90b027 into mui:master Mar 11, 2026
22 checks passed
@chuganzy chuganzy deleted the toast-on-close branch March 11, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: toast Changes related to the toast component.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants