Skip to content

fix: keep toasts mounted when a modal opens or closes - #1623

Merged
stevenle merged 1 commit into
mainfrom
fix/toasts-persist-across-dialogs
Nov 20, 2026
Merged

stevenle merged 1 commit into
mainfrom
fix/toasts-persist-across-dialogs

Conversation

@stevenle

Copy link
Copy Markdown
Member

Problem

When a modal dialog opened, the toast notifications on screen disappeared and animated back in; the same happened again when the modal closed. Their auto-close timers also restarted each time.

The Toaster portaled its toasts into the overlay root: document.body, or the topmost open <dialog> so toasts stay above the modal and clickable. A portal that changes container unmounts and remounts its children, so every toast was remounted whenever a dialog opened or closed.

Fix

The toasts now render into one stable host element, and that element is moved between the body and the dialog rather than re-portaled. It uses moveBefore() where the browser supports it (which keeps running animations, focus and hover) and falls back to appendChild().

Testing

  • New unit test: the same toast element survives a dialog opening and closing, and ends up inside the dialog and back in the body.
  • Toast tests pass (5/5).
  • Not checked in a real browser.

🤖 Generated with Claude Code

The Toaster portaled into the topmost open dialog, and a portal that
changes container remounts its children, so every toast disappeared and
replayed its enter animation (and restarted its auto-close timer) each
time a dialog opened or closed. Render the toasts into one stable host
element and move that element between the body and the dialog instead.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@stevenle
stevenle marked this pull request as ready for review November 20, 2026 23:18
@stevenle
stevenle merged commit 26a826f into main Nov 20, 2026
1 check passed
@stevenle
stevenle deleted the fix/toasts-persist-across-dialogs branch November 20, 2026 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant