pull/18160/merge
sliang-code 2 days ago committed by GitHub
commit 43a32bfcbe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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
@ -248,6 +255,8 @@ function apply_selector(
from = 0,
to = relative_selectors.length
) {
if (is_inside_svelte_head(element)) return false;
if (from >= to) return false;
const selector_index = direction === FORWARD ? from : to - 1;

@ -207,6 +207,13 @@ const visitors = {
VariableDeclarator
};
/**
* @param {AST.RegularElement | AST.SvelteElement} node
*/
function is_inside_svelte_head(node) {
return node.metadata.path.some((ancestor) => ancestor.type === 'SvelteHead');
}
/**
* @param {AST.Script | null} script
* @param {ScopeRoot} root
@ -881,6 +888,12 @@ export function analyze_component(root, source, options) {
}
for (const node of analysis.elements) {
// Elements rendered through <svelte:head> are not style-scopable.
// Prevent css hash injection (class="s-...") on tags like <meta>, <link>, <script>.
if (is_inside_svelte_head(node)) {
node.metadata.scoped = false;
}
if (node.metadata.scoped && is_custom_element_node(node)) {
mark_subtree_dynamic(node.metadata.path);
}

@ -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,10 @@
<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>
</style>

@ -0,0 +1,21 @@
import { test } from '../../assert';
export default test({
test({ assert, window }) {
const head = window.document.head;
const meta = head.querySelector('meta[name="author"]');
const link = head.querySelector('link[rel="author"]');
const script = head.querySelector('script[type="application/ld+json"]');
assert.ok(meta);
assert.ok(link);
assert.ok(script);
if (!meta || !link || !script) return;
assert.equal(meta.getAttribute('class'), null);
assert.equal(link.getAttribute('class'), null);
assert.equal(script.getAttribute('class'), null);
}
});

@ -0,0 +1,19 @@
<svelte:head>
<meta name="author" content={author} />
<link rel="author" href={author_url} />
<script type="application/ld+json"></script>
</svelte:head>
<div class="credits">
Site by
<a href={author_url} target="_blank" rel="noopener noreferrer author" title={`Authored by ${author}`}>
<nobr>{author}</nobr>
</a>
</div>
<script>
let { author = 'Anonymous', author_url = 'https://example.com' } = $props();
</script>
<style>
</style>
Loading…
Cancel
Save