Skip to content

Commit a7a4778

Browse files
authored
fix: ensure StyleDirective and ClassDirective are marked as dynamic (#13205)
If we don't, the corresponding runtime code would never be created if in a static sub tree. Fixes #13193
1 parent 0b25e2b commit a7a4778

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

.changeset/twenty-toes-attack.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure StyleDirective and ClassDirective are marked as dynamic
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
/** @import { AST } from '#compiler' */
22
/** @import { Context } from '../types' */
33

4+
import { mark_subtree_dynamic } from './shared/fragment.js';
5+
46
/**
57
* @param {AST.ClassDirective} node
68
* @param {Context} context
79
*/
810
export function ClassDirective(node, context) {
11+
mark_subtree_dynamic(context.path);
912
context.next({ ...context.state, expression: node.metadata.expression });
1013
}

packages/svelte/src/compiler/phases/2-analyze/visitors/StyleDirective.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export function StyleDirective(node, context) {
1313
e.style_directive_invalid_modifier(node);
1414
}
1515

16+
mark_subtree_dynamic(context.path);
17+
1618
if (node.value === true) {
1719
// get the binding for node.name and change the binding to state
1820
let binding = context.state.scope.get(node.name);
@@ -22,8 +24,6 @@ export function StyleDirective(node, context) {
2224
node.metadata.expression.has_state = true;
2325
}
2426
}
25-
26-
mark_subtree_dynamic(context.path);
2727
} else {
2828
context.next();
2929

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `<div><p class="foo" style="color: red;">This text should be red with a class of foo</p></div>`,
5+
6+
async test({ assert, target }) {
7+
const p = target.querySelector('p');
8+
9+
assert.equal(p?.className, `foo`);
10+
assert.equal(p?.style.color, `red`);
11+
}
12+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
<p style:color="red" class:foo={true}>This text should be red with a class of foo</p>
3+
</div>

0 commit comments

Comments
 (0)