Dynamically imported components gets their css delayed
See original GitHub issueDescribe the bug
When dynamically importing components like: await import('my-component.svelte').default
the component gets server side rendered, but the css gets imported async with a preload helper, thus the code flickers until the css is loaded.
To Reproduce I have a repro repo here with two links to a [slug] page where the component gets chosen depending on the slug (blue or red counter): https://github.com/rinti/svelte-kit-dynamic-import As you can see when building and starting production server, the html gets correctly rendered, but the css flickers.
Expected behavior The relevant css should be inlined in <link> tags
The output of npx envinfo --system --npmPackages svelte,@sveltejs/kit,vite --binaries --browsers
System:
OS: macOS 11.1
CPU: (8) x64 Apple M1
Memory: 20.92 MB / 8.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 12.22.1 - ~/.volta/tools/image/node/12.22.1/bin/node
npm: 6.14.12 - ~/.volta/tools/image/node/12.22.1/bin/npm
Browsers:
Firefox Developer Edition: 88.0
Safari: 14.0.2
npmPackages:
@sveltejs/kit: next => 1.0.0-next.71
svelte: ^3.29.0 => 3.37.0
vite: ^2.1.0 => 2.1.5
Using node adapter
Severity I don’t know how common my use case is, but for my use case it’s pretty severe.
This might be a duplicate of #962, if so you can close this issue.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:12 (4 by maintainers)
As of v360, this problem is now fixed it seems! Thanks a lot Rich 😃
I can confirm this is still happening, for me both in dev and production.
All the css related to a dynamically imported component is imported via a preload-helper, which causes some styles to appear only when js loads. It’s very easy to reproduce by disabling the js on the page, in which preload-helper won’t run and the css won’t get loaded, even though the component appears just fine.
I can work around this by not using the
<style>
block in dynamically imported components and putting the styles in a global stylesheet, but it would be nice to have this fixed 😃