fix: always mark props as stateful

pull/16504/head
7nik 1 month ago
parent d0ebd42986
commit 2d4a29694a

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: always mark props as stateful

@ -93,7 +93,10 @@ export function Identifier(node, context) {
context.state.expression.references.add(binding); context.state.expression.references.add(binding);
context.state.expression.has_state ||= context.state.expression.has_state ||=
binding.kind !== 'static' && binding.kind !== 'static' &&
!binding.is_function() && (binding.kind === 'prop' ||
binding.kind === 'bindable_prop' ||
binding.kind === 'rest_prop' ||
!binding.is_function()) &&
!context.state.scope.evaluate(node).is_known; !context.state.scope.evaluate(node).is_known;
} }

@ -0,0 +1,15 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
mode: ['client'],
test({ assert, target }) {
const btn = target.querySelector('button');
assert.htmlEqual(target.innerHTML, `<button>inc</button> Inner: 0 Inner: 0`);
btn?.click();
flushSync();
assert.htmlEqual(target.innerHTML, `<button>inc</button> Inner: 1 Inner: 1`);
}
});

@ -0,0 +1,4 @@
<script>
let { getter } = $props()
</script>
Inner: {getter()}

@ -0,0 +1,14 @@
<script>
import Wrapper1 from "./wrapper.svelte"
import Wrapper2 from "./wrapper2.svelte"
let count = $state(0);
let getter = $derived.by(() => {
const copy = count;
return () => copy;
});
</script>
<button onclick={() => count++}>inc</button>
<Wrapper1 {getter}/>
<Wrapper2 {getter}/>

@ -0,0 +1,7 @@
<script >
import Inner from "./inner.svelte";
const { getter = () => -1} = $props();
</script>
<Inner {getter} />

@ -0,0 +1,7 @@
<script >
import Inner from "./inner.svelte";
const { getter = $bindable(() => -1)} = $props();
</script>
<Inner {getter} />
Loading…
Cancel
Save