-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
onMount not called with dynamic import #5534
Comments
This is related to the rollup configuration. In the repo, the rollup configuration create two entries, and svelte is bundled twice. The dynamic-import import the secondary entry and not the composant. When updating |
Hi j3rem1e, thank you for having a look. Do you mean to update the rollup config to have just one bundle? That's not wanted because I have a set of components in one bundle shared via CDN among standalone apps. |
You can't bundle multiple svelte runtimes. |
Why? I expected it's more about the component API which is exported by the component bundle than about the way it's imported or bundled in an app. |
A svelte runtimes has global states like render-callbacks, dirty components, and lifecycle loop (flush) for example. Multiple runtimes can't share this states and you see this kind of bugs. I own myself severals applications which use like you "independants" compiled bundle. However svelte should be configured as a singleton in order to work. I don't know how to do that with rollup but with webpack there is a concept of "external" dependency which allow to share a runtime between entry points. |
OK, thanks for explanation. I actually use the external dependencies with rollup but not sure if I can share a runtime.. gonna look deeper. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Closing since this is a bundler issue and the question seems to be answered |
Finally have a solution.. building svelte/internal as a separate module and treating |
Describe the bug
If the parent component is imported statically or the loading is omitted (the slot content doesn't change), it's OK.
All three case are demonstrated in the app in the repo bellow.
To Reproduce
https://github.com/jindrahm/svelte-component-dynamic-import
Expected behavior
onMount should be called right after the component is mounted regardless the way it's imported or whether it's render later or not.
Information about your Svelte project:
Severity
I would say 2 out of 3. It's no blocker but it increases my project size because I cannot share the components using dynamic imports. I have to bundle them in every module to work this bug around.
The text was updated successfully, but these errors were encountered: