Skip to content

Commit e87bf77

Browse files
committed
guarantee we only query the DOM once
1 parent a1e61cf commit e87bf77

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

packages/kit/src/runtime/client/utils.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ export function is_external_url(url, base, hash_routing) {
323323
return false;
324324
}
325325

326-
/** @type {Set<string>} */
327-
const seen = new Set();
326+
/** @type {Set<string> | null} */
327+
let seen = null;
328328

329329
/**
330330
* Used for server-side resolution, to replicate Vite's CSS loading behaviour in production.
@@ -341,11 +341,11 @@ export function load_css(deps) {
341341
);
342342
const csp_nonce = csp_nonce_meta?.nonce || csp_nonce_meta?.getAttribute('nonce');
343343

344-
if (seen.size === 0) {
345-
document.querySelectorAll('link[rel="stylesheet"]').forEach((link) => {
346-
seen.add(/** @type {HTMLLinkElement} */ (link).href);
347-
});
348-
}
344+
seen ??= new Set(
345+
Array.from(document.querySelectorAll('link[rel="stylesheet"]')).map((link) => {
346+
return /** @type {HTMLLinkElement} */ (link).href;
347+
})
348+
);
349349

350350
for (const dep of deps) {
351351
const href = new URL(dep, document.baseURI).href;

0 commit comments

Comments
 (0)