Skip to content

Sonner loses state after portaling to a top layer <dialog> #534

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

Closed
mkrause opened this issue Jan 9, 2025 · 1 comment
Closed

Sonner loses state after portaling to a top layer <dialog> #534

mkrause opened this issue Jan 9, 2025 · 1 comment

Comments

@mkrause
Copy link

mkrause commented Jan 9, 2025

I'm trying to use sonner in an app that uses HTML <dialog> elements for modals. Due to the issues described here, in order to make this work with toast notifications, I need to use createPortal() to render the <Toaster/> inside the <dialog>. However, if I do this, any toasts that are already open get reset. The "re-portaling" from one location in the DOM to another makes it lose its component state.

Would it be possible to allow Toaster to be a controlled component? That is, allow toasts and setToasts to be passed in as props. That way, I can maintain this state in the parent component which does not get remounted and therefore the <Toaster/> element can be freely moved around.

@emilkowalski
Copy link
Owner

Rendering something while the dialog is still open seems like an anti-pattern. The dialog blocks interaction with outside elements for a reason. I think the best solution here would be to render the toasts after the dialog is closed.

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

No branches or pull requests

2 participants