Skip to content

Commit

Permalink
fix: style directive not reactive in {#each} loop (sveltejs#7140)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau authored and nevilm-lt committed Apr 21, 2022
1 parent ce04cf3 commit 967ccd1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/wrappers/Element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export default class ElementWrapper extends Wrapper {
}

// add directive and handler dependencies
[node.animation, node.outro, ...node.actions, ...node.classes].forEach(directive => {
[node.animation, node.outro, ...node.actions, ...node.classes, ...node.styles].forEach(directive => {
if (directive && directive.expression) {
block.add_dependencies(directive.expression.dependencies);
}
Expand Down
19 changes: 13 additions & 6 deletions test/runtime/samples/inline-style-directive-shorthand/_config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
export default {
html: `
<p style="color: red;"></p>
<p style="color: red;"></p>
`,

test({ assert, component, target, window }) {
const p = target.querySelector('p');
const [p1, p2] = target.querySelectorAll('p');

let styles = window.getComputedStyle(p);
assert.equal(styles.color, 'red');
assert.equal(window.getComputedStyle(p1).color, 'red');
assert.equal(window.getComputedStyle(p2).color, 'red');

component.color = 'blue';
assert.htmlEqual(target.innerHTML, '<p style="color: blue;"></p>');
assert.htmlEqual(
target.innerHTML,
`
<p style="color: blue;"></p>
<p style="color: blue;"></p>
`
);

styles = window.getComputedStyle(p);
assert.equal(styles.color, 'blue');
assert.equal(window.getComputedStyle(p1).color, 'blue');
assert.equal(window.getComputedStyle(p2).color, 'blue');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
</script>

<p style:color />

{#each [1] as _}
<p style:color />
{/each}

0 comments on commit 967ccd1

Please sign in to comment.