mirror of https://github.com/sveltejs/svelte
fix: ensure locally mutated bindable props persist with spreading props (#13190)
Fixes #13187. This ensures that we update the local fallback value in the case where the fallback is used so that we persist local changes to bindable props. Otherwise, any incoming changes from the outside will reset the incoming value back to the old fallback value. --------- Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>pull/13204/head
parent
25f67df911
commit
363f4a06c8
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: ensure locally mutated bindable props persist with spreading props
|
@ -0,0 +1,31 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
accessors: false,
|
||||
|
||||
test({ assert, target }) {
|
||||
const [btn1, btn2] = target.querySelectorAll('button');
|
||||
|
||||
btn1.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>set color</button> <button>set options</button> bar bar`
|
||||
);
|
||||
|
||||
btn2.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>set color</button> <button>set options</button> baz bar`
|
||||
);
|
||||
|
||||
btn1.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>set color</button> <button>set options</button> foo bar`
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
let { options = $bindable('foo') } = $props();
|
||||
|
||||
options = 'bar'
|
||||
</script>
|
||||
|
||||
{options}
|
@ -0,0 +1,24 @@
|
||||
<script >
|
||||
import Inner from "./inner.svelte";
|
||||
|
||||
let testProps = $state({
|
||||
color: "red"
|
||||
});
|
||||
</script>
|
||||
|
||||
<button onclick={() => {
|
||||
testProps = {
|
||||
color: "blue"
|
||||
};
|
||||
}}>set color</button>
|
||||
|
||||
<button onclick={() => {
|
||||
testProps = {
|
||||
color: "pink",
|
||||
options: 'baz'
|
||||
};
|
||||
}}>set options</button>
|
||||
|
||||
<Inner {...testProps} />
|
||||
|
||||
<Inner color={testProps.color} />
|
Loading…
Reference in new issue