Skip to content

fix: toast hidden behind modals due to stacking context#14

Open
ssantss wants to merge 2 commits intohiaaryan:mainfrom
ssantss:fix/toast-z-index-portal
Open

fix: toast hidden behind modals due to stacking context#14
ssantss wants to merge 2 commits intohiaaryan:mainfrom
ssantss:fix/toast-z-index-portal

Conversation

@ssantss
Copy link
Copy Markdown

@ssantss ssantss commented Feb 16, 2026

Problem

Toasts render inline in the DOM tree wherever <Toaster /> is placed.
When a modal or overlay with a higher z-index is open, toasts appear behind it
because of CSS stacking context limitations — no matter how high the z-index is.

Solution

  • Use createPortal from react-dom to render toast viewports directly into document.body
  • Add SSR guard (mounted state) to prevent document.body access during server-side rendering (Next.js, Remix, etc.)
  • Bump viewport z-index from 50 to 9999 (industry standard for notifications)

This is the same approach used by sonner, react-hot-toast, and react-toastify.

Files changed

  • src/toast.tsx — portal + SSR guard
  • src/styles.css — z-index 50 → 9999

@varseb
Copy link
Copy Markdown

varseb commented Feb 18, 2026

Having same issue when integrating with react-modal-sheet. Toaster shows behind the modals.

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.

2 participants