Skip to content

Commit 05c3efa

Browse files
committed
fix: wrap props in deriveds more conservatively in legacy mode
1 parent 5497b3d commit 05c3efa

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

.changeset/odd-jobs-taste.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: wrap props in deriveds more conservatively in legacy mode

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,8 +1263,9 @@ const common_visitors = {
12631263
},
12641264
CallExpression(node, context) {
12651265
if (
1266-
context.state.expression?.type === 'ExpressionTag' ||
1267-
(context.state.expression?.type === 'SpreadAttribute' && !is_known_safe_call(node, context))
1266+
(context.state.expression?.type === 'ExpressionTag' ||
1267+
context.state.expression?.type === 'SpreadAttribute') &&
1268+
!is_known_safe_call(node, context)
12681269
) {
12691270
context.state.expression.metadata.contains_call_expression = true;
12701271
}

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -719,11 +719,10 @@ function serialize_inline_component(node, component_name, context) {
719719
const should_wrap_in_derived =
720720
Array.isArray(attribute.value) &&
721721
attribute.value.some((n) => {
722-
return (
723-
n.type === 'ExpressionTag' &&
724-
n.expression.type !== 'Identifier' &&
725-
n.expression.type !== 'MemberExpression'
726-
);
722+
if (n.type !== 'ExpressionTag') return false;
723+
return context.state.analysis.runes
724+
? n.metadata.contains_call_expression
725+
: n.expression.type !== 'Identifier';
727726
});
728727

729728
if (should_wrap_in_derived) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<svelte:options accessors={false} />
2+
3+
<script>
4+
export let x;
5+
6+
$: console.log('x', x);
7+
</script>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
test({ assert, logs, target }) {
6+
assert.deepEqual(logs, ['x', 42]);
7+
8+
const btn = target.querySelector('button');
9+
flushSync(() => btn?.click());
10+
11+
assert.deepEqual(logs, ['x', 42]);
12+
}
13+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
import Child from './Child.svelte';
3+
4+
let object = { x: 42 };
5+
</script>
6+
7+
<button on:click={() => object = { x: 42 }}>update</button>
8+
9+
<Child x={object.x} />

0 commit comments

Comments
 (0)