Skip to content

Commit bd55f28

Browse files
fix: clean up injected styles to prevent background persisting after errors
1 parent f19b47f commit bd55f28

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

  • packages/repl/src/lib/workers/bundler

packages/repl/src/lib/workers/bundler/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,13 @@ async function get_bundle(
376376
}
377377
);
378378
// add the CSS via injecting a style tag
379+
const style_id = result.css.code.match(/\.svelte-([a-z0-9]+)/)?.[0]?.slice(1) ?? ('svelte-' + name.replace(/[^a-zA-Z0-9]/g, '_'));
379380
result.js.code +=
380381
'\n\n' +
381382
`
382383
import { styles as $$_styles } from '${VIRTUAL}/${STYLES}';
383384
const $$__style = document.createElement('style');
385+
$$__style.id = ${JSON.stringify(style_id)};
384386
$$__style.textContent = ${JSON.stringify(result.css.code)};
385387
document.head.append($$__style);
386388
$$_styles.push($$__style);

0 commit comments

Comments
 (0)