Skip to content

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

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

atomiks merged 3 commits into
mui:masterfrom
chuganzy:toast-on-close

Conversation

@chuganzy

@chuganzy chuganzy commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

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

pkg-pr-new Bot commented Mar 6, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@4280
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4280
    

commit: bf74137

@mui-bot

mui-bot commented Mar 6, 2026 •

Copy link
Copy Markdown

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

netlify Bot commented Mar 6, 2026 •

Copy link
Copy Markdown

✅ 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

atomiks commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

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);

@chuganzy chuganzy Mar 10, 2026 •

Copy link
Copy Markdown
Contributor Author

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 onClose → focus 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
6 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