fix: don't apply scoped CSS class to elements inside <svelte:head> (#18160)

skip elements inside head, they should not get hashes

---------

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
pull/18690/head
sliang-code 3 weeks ago committed by GitHub
parent 2ac7366391
commit 63b4c3652d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: never apply class hash to elements inside `<svelte:head>`

@ -122,6 +122,13 @@ const any_selector = {
*/
const seen = new Set();
/**
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement | Compiler.AST.RenderTag | Compiler.AST.Component | Compiler.AST.SvelteComponent | Compiler.AST.SvelteSelf} node
*/
function is_inside_svelte_head(node) {
return node.metadata.path.some((ancestor) => ancestor.type === 'SvelteHead');
}
/**
*
* @param {Compiler.AST.CSS.StyleSheet} stylesheet
@ -143,6 +150,9 @@ export function prune(stylesheet, elements) {
seen.clear();
if (
// Elements rendered through <svelte:head> are not style-scopable.
// Prevent css hash injection (class="s-...") on tags like <meta>, <link>, <script>.
!is_inside_svelte_head(element) &&
apply_selector(
selectors,
/** @type {Compiler.AST.CSS.Rule} */ (node.metadata.rule),

@ -0,0 +1 @@
<meta name="author" content="Re:Designed"> <link rel="author" href="https://example.com"> <script type="application/ld+json"></script>

@ -0,0 +1,11 @@
<svelte:head>
<meta name="author" content="Re:Designed" />
<link rel="author" href="https://example.com" />
<script type="application/ld+json"></script>
</svelte:head>
<div>dummy</div>
<style>
* { color: red }
</style>
Loading…
Cancel
Save