-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(toast): prevent duplicate toasts when multiple providers are declared #5590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c648da1
803b906
a2705f6
72a4709
b6bf10d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,12 +3,15 @@ import React from "react"; | |||||
|
|
||||||
| export default function App() { | ||||||
| const [toastKey, setToastKey] = React.useState([]); | ||||||
| const [isBlogPage, setIsBlogPage] = React.useState(false); | ||||||
|
|
||||||
| React.useEffect(() => { | ||||||
| setIsBlogPage(window.location.pathname.startsWith("/blog")); | ||||||
| }, []); | ||||||
|
|
||||||
| return ( | ||||||
| <> | ||||||
| <div className="fixed z-[100]"> | ||||||
| <ToastProvider /> | ||||||
| </div> | ||||||
| <div className="fixed z-[100]">{isBlogPage && <ToastProvider />}</div> | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Delete the local ToastProvider; rely on the single global provider The fixed container plus a local provider is the root cause of duplicate regions. Remove this line and let the global provider handle the toast region. - <div className="fixed z-[100]">{isBlogPage && <ToastProvider />}</div>
+ {/* ToastProvider is provided globally at the app root */}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| <div className="flex flex-wrap gap-2"> | ||||||
| <Button | ||||||
| variant="flat" | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Route-based gating of ToastProvider undermines the fix; remove it and rely on the global provider
This keeps a second provider active on blog pages, so duplicate toasts will still occur there (after hydration). It also adds a client-only route check that creates an SSR/hydration timing window where the local provider flips on post-mount. The PR objective is to have a single global provider; this local provider should be removed entirely, not conditionally rendered.
Apply this diff to delete the route-coupled state/effect:
Run this script to verify there are no example-local providers left and that only one provider exists in the docs app shell:
🏁 Script executed:
Length of output: 3811
🏁 Script executed:
Length of output: 1711
Remove client-only route gating and render the provider unconditionally in the close example
The
isBlogPagestate + effect creates an SSR/hydration mismatch and prevents the example from always having a provider. Since MDX renders raw examples before the global provider anyway, the local<ToastProvider />must remain—but without the route check.• File: apps/docs/content/components/toast/close.raw.jsx
• Remove the
useState/useEffectforisBlogPage• Change the provider wrapper to always render
Apply this diff:
🤖 Prompt for AI Agents