File tree Expand file tree Collapse file tree 1 file changed +15
-10
lines changed
packages/svelte/src/internal/client/dom Expand file tree Collapse file tree 1 file changed +15
-10
lines changed Original file line number Diff line number Diff line change 1+ import { queue_micro_task } from './task' ;
2+
13/**
24 * @param {Node } anchor
35 * @param {{ hash: string, code: string } } css
46 */
57export function append_styles ( anchor , css ) {
6- var root = anchor . getRootNode ( ) ;
8+ // Use `queue_micro_task` to ensure `anchor` is in the DOM, otherwise getRootNode() will yield wrong results
9+ queue_micro_task ( ( ) => {
10+ var root = anchor . getRootNode ( ) ;
711
8- var target = /** @type {ShadowRoot } */ ( root ) . host
9- ? /** @type {ShadowRoot } */ ( root )
10- : /** @type {Document } */ ( root ) . head ?? /** @type {Document } */ ( root . ownerDocument ) . head ;
12+ var target = /** @type {ShadowRoot } */ ( root ) . host
13+ ? /** @type {ShadowRoot } */ ( root )
14+ : /** @type {Document } */ ( root ) . head ?? /** @type {Document } */ ( root . ownerDocument ) . head ;
1115
12- if ( ! target . querySelector ( '#' + css . hash ) ) {
13- const style = document . createElement ( 'style' ) ;
14- style . id = css . hash ;
15- style . textContent = css . code ;
16+ if ( ! target . querySelector ( '#' + css . hash ) ) {
17+ const style = document . createElement ( 'style' ) ;
18+ style . id = css . hash ;
19+ style . textContent = css . code ;
1620
17- target . appendChild ( style ) ;
18- }
21+ target . appendChild ( style ) ;
22+ }
23+ } ) ;
1924}
You can’t perform that action at this time.
0 commit comments