Skip to content

Commit 14642b8

Browse files
committed
fix: put expressions in effects unless known to be static
1 parent 7f473f6 commit 14642b8

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

.changeset/tender-apples-repair.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: put expressions in effects unless known to be static

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ export function Identifier(node, context) {
9090
if (binding) {
9191
if (context.state.expression) {
9292
context.state.expression.dependencies.add(binding);
93-
context.state.expression.has_state ||= binding.kind !== 'normal';
93+
context.state.expression.has_state ||=
94+
!binding.is_function() && !context.state.scope.evaluate(node).is_known;
9495
}
9596

9697
if (
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { flushSync } from '../../../../src/index-client';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
html: `<button>0</button>`,
6+
7+
test({ assert, target }) {
8+
const btn = target.querySelector('button');
9+
10+
flushSync(() => btn?.click());
11+
assert.htmlEqual(target.innerHTML, `<button>1</button>`);
12+
}
13+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
let count = $state(0);
3+
4+
let object = {
5+
toString() {
6+
return count;
7+
}
8+
};
9+
</script>
10+
11+
<button onclick={() => count += 1}>
12+
{object}
13+
</button>

0 commit comments

Comments
 (0)