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

Infinite loop when component is created inside onMount #4315

Closed
ghost opened this issue Jan 24, 2020 · 3 comments
Closed

Infinite loop when component is created inside onMount #4315

ghost opened this issue Jan 24, 2020 · 3 comments

Comments

@ghost
Copy link

ghost commented Jan 24, 2020

Describe the bug

If a component is dynamically created inside an onMount handler, it triggers an infinite loop whereby onMount is called over and over until the app crashes.

Logs
Console will output Maximum call stack size exceeded.

To Reproduce
https://svelte.dev/repl/308f355e52e740b99834853a5edd6db8?version=3.17.3

Credit to @tivac for coming up with a repro.

Expected behavior
Component is created at target site without an infinite loop.

Severity
Seems pretty bad if you are looking to do this sort of thing.

Additional context

Spent a little bit debugging this and it looks like the component creation triggers a call to flush() which then calls the onMount because it hasn't been removed from the queue yet. The seen_callbacks set which is supposed to protect against recursion does nothing in this case because it is constantly reset to empty upon entry.

@ghost
Copy link
Author

ghost commented Jan 24, 2020

Actually, I have a fix for this.... lift the set declaration out of the function and call clear() at the end.

@Conduitry
Copy link
Member

I believe this is a duplicate of #3218.

@ghost
Copy link
Author

ghost commented Jan 24, 2020

Whoops, yes it is, I'll close this and update the PR accordingly.

@ghost ghost closed this as completed Jan 24, 2020
This issue was 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

1 participant