Skip to content
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

Alert .toast() breaks Svelte components #503

Closed
MerlinB opened this issue Aug 18, 2021 · 1 comment
Closed

Alert .toast() breaks Svelte components #503

MerlinB opened this issue Aug 18, 2021 · 1 comment
Assignees
Labels
bug Things that aren't working right in the library.

Comments

@MerlinB
Copy link

MerlinB commented Aug 18, 2021

This happens because the alert gets moved out of its position in the DOM leading to TypeError: Cannot read property 'removeChild' of null in Svelte when the parent component is destroyed. See sveltejs/svelte#6037.

@MerlinB MerlinB added the bug Things that aren't working right in the library. label Aug 18, 2021
@claviska
Copy link
Member

This is by design and described in the docs:

To display an alert as a toast notification, or "toast", create the alert and call its toast() method. This will move the alert out of its position in the DOM and into the toast stack where it will be shown. Once dismissed, it will be removed from the DOM completely.

Moving the element is necessary to ensure "toast elements" render properly in the toast stack. Without this, the library would be responsible for messy positioning logic and susceptible to z-indexing conflicts (depending on the location of the alert in the DOM). Furthermore, consumers wouldn't be able to customize the toast stack with CSS since there wouldn't be a container in which the alerts collectively stack.

If you're using any framework that expects DOM elements to persist, you should create the alert outside of the app container and call toast() on them there. There's an example of creating toasts imperatively that appends them to document.body in case that helps.

As for the Svelte error — I'm sure they have their reasons for emitting an error instead of failing gracefully when a node no longer exists, but if you expect it to work as-is it would need to be mitigated in Svelte.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Things that aren't working right in the library.
Projects
None yet
Development

No branches or pull requests

2 participants