Skip to content

Commit dc06ea9

Browse files
authored
fix: style directive not reactive in {#each} loop (#7140)
1 parent 815bc7e commit dc06ea9

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/compiler/compile/render_dom/wrappers/Element/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export default class ElementWrapper extends Wrapper {
199199
}
200200

201201
// add directive and handler dependencies
202-
[node.animation, node.outro, ...node.actions, ...node.classes].forEach(directive => {
202+
[node.animation, node.outro, ...node.actions, ...node.classes, ...node.styles].forEach(directive => {
203203
if (directive && directive.expression) {
204204
block.add_dependencies(directive.expression.dependencies);
205205
}
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
export default {
22
html: `
33
<p style="color: red;"></p>
4+
<p style="color: red;"></p>
45
`,
56

67
test({ assert, component, target, window }) {
7-
const p = target.querySelector('p');
8+
const [p1, p2] = target.querySelectorAll('p');
89

9-
let styles = window.getComputedStyle(p);
10-
assert.equal(styles.color, 'red');
10+
assert.equal(window.getComputedStyle(p1).color, 'red');
11+
assert.equal(window.getComputedStyle(p2).color, 'red');
1112

1213
component.color = 'blue';
13-
assert.htmlEqual(target.innerHTML, '<p style="color: blue;"></p>');
14+
assert.htmlEqual(
15+
target.innerHTML,
16+
`
17+
<p style="color: blue;"></p>
18+
<p style="color: blue;"></p>
19+
`
20+
);
1421

15-
styles = window.getComputedStyle(p);
16-
assert.equal(styles.color, 'blue');
22+
assert.equal(window.getComputedStyle(p1).color, 'blue');
23+
assert.equal(window.getComputedStyle(p2).color, 'blue');
1724
}
1825
};

test/runtime/samples/inline-style-directive-shorthand/main.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
</script>
44

55
<p style:color />
6+
7+
{#each [1] as _}
8+
<p style:color />
9+
{/each}

0 commit comments

Comments
 (0)