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

Mounting child component re-renders host component #3268

Closed
pielambr opened this issue Jul 19, 2019 · 2 comments
Closed

Mounting child component re-renders host component #3268

pielambr opened this issue Jul 19, 2019 · 2 comments

Comments

@pielambr
Copy link

Hi all,

To facilitate a Svelte router, I'm currently making a component that takes care of the lifecycle of it's child components.

https://svelte.dev/repl/0bd735145fd94540ac78b39eab3521aa?version=3.6.7

As you can see from the REPL, it seems that as soon as I bind the new view, the parent component gets recreated as well, resulting in an infinite loop.

Is this expected behaviour?

@creaven
Copy link

creaven commented Jul 19, 2019

If you add import { current_component } from 'svelte/internal' and console.log(current_component) in onMount callback you will see that it is called for Test component. onMount is called for current_component, see https://github.com/sveltejs/svelte/blob/master/src/runtime/internal/lifecycle.ts
Why doing such tricky implementation with new Test, instead of using <svelte:component this={Test}></svelte:component>, if component should be dynamic?

@Conduitry
Copy link
Member

Duplicate of #3218.

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

3 participants