MCPcopy
hub / github.com/sveltejs/svelte / append_styles

Function append_styles

packages/svelte/src/internal/client/dom/css.js:10–33  ·  view source on GitHub ↗
(anchor, css)

Source from the content-addressed store, hash-verified

8 * @param {{ hash: string, code: string }} css
9 */
10export function append_styles(anchor, css) {
11 // Use `queue_micro_task` to ensure `anchor` is in the DOM, otherwise getRootNode() will yield wrong results
12 effect(() => {
13 var root = anchor.getRootNode();
14
15 var target = /** @type {ShadowRoot} */ (root).host
16 ? /** @type {ShadowRoot} */ (root)
17 : /** @type {Document} */ (root).head ?? /** @type {Document} */ (root.ownerDocument).head;
18
19 // Always querying the DOM is roughly the same perf as additionally checking for presence in a map first assuming
20 // that you'll get cache hits half of the time, so we just always query the dom for simplicity and code savings.
21 if (!target.querySelector('#' + css.hash)) {
22 const style = create_element('style');
23 style.id = css.hash;
24 style.textContent = css.code;
25
26 target.appendChild(style);
27
28 if (DEV) {
29 register_style(css.hash, style);
30 }
31 }
32 });
33}

Callers

nothing calls this directly

Calls 3

effectFunction · 0.90
create_elementFunction · 0.90
register_styleFunction · 0.90

Tested by

no test coverage detected