Skip to content

Commit da37c92

Browse files
authored
fix: support dynamic attributes containing call expressions (#9443)
Fixes #9403. We weren't taking into account the containment of call expressions logic before.
1 parent a6fdc47 commit da37c92

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

.changeset/lucky-schools-hang.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure dynamic attributes containing call expressions update

packages/svelte/src/compiler/phases/2-analyze/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ const common_visitors = {
762762
return false;
763763
}
764764

765-
return chunk.metadata.dynamic;
765+
return chunk.metadata.dynamic || chunk.metadata.contains_call_expression;
766766
});
767767

768768
if (is_event_attribute(node)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { test } from '../../test';
2+
import { flushSync } from 'svelte';
3+
4+
export default test({
5+
html: `<div style="background-color: red">Hello world</div><button>Make blue</button`,
6+
7+
async test({ assert, target, component }) {
8+
const [b1] = target.querySelectorAll('button');
9+
flushSync(() => {
10+
b1.click();
11+
});
12+
assert.htmlEqual(
13+
target.innerHTML,
14+
`<div style="background-color: blue">Hello world</div><button>Make blue</button`
15+
);
16+
}
17+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
let color = $state('red');
3+
4+
const getColor = () => color;
5+
</script>
6+
7+
<div style="background-color: {getColor()}">Hello world</div>
8+
9+
<button onclick={() => color = 'blue'}>Make blue</button>

0 commit comments

Comments
 (0)