Closed
Description
Describe the bug
I am a part of a project that uses Svelte 5 to create web components. We have emitCss
set to false
, and in production mode, web component styles are only inserted once (first time it mounts). Here's an overview of what happens:
- A page imports
my-web-component.js
<my-web-component>
is placed in the dom, its style tags are inserted in its shadow dom.<my-web-component>
is removed from the dom, together with the styles within it.<my-web-component>
is inserted in the dom again, but no style tags are inserted.
I was able to trace the discrepancy to these lines:
It appears that the runtime assumes the styles are still present, even though it has been removed.
All the best,
Lasse
Reproduction
- Clone https://github.com/lassebomh/svelte-5-styles-bug
- Run
pnpm run preview
- Press the button twice and notice the color change on the text.
It works fine with pnpm run dev
.
Logs
No response
System Info
System:
OS: Windows 11 10.0.22631
CPU: (16) x64 AMD Ryzen 9 6900HS with Radeon Graphics
Memory: 15.58 GB / 31.25 GB
Binaries:
Node: 20.12.2 - C:\Program Files\nodejs\node.EXE
npm: 10.5.2 - C:\Program Files\nodejs\npm.CMD
pnpm: 9.4.0 - C:\Program Files\nodejs\pnpm.CMD
Browsers:
Edge: Chromium (127.0.2651.74)
Internet Explorer: 11.0.22621.3527
Severity
annoyance