mirror of https://github.com/sveltejs/svelte
fix: keep fallback value after spread update not setting that prop (#9717)
fixes #9716pull/9721/head
parent
65fa717ccd
commit
4a8f0bc7e7
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: keep fallback value after spread update not setting that prop
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
const { propA, propB = "fallback" } = $props();
|
||||
</script>
|
||||
|
||||
<p>{propA} {propB}</p>
|
@ -0,0 +1,55 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
// Tests that fallback values are kept as long as the prop is not defined in the case of a spread
|
||||
export default test({
|
||||
accessors: false, // so that propA actually becomes $.prop and not $.prop_source
|
||||
html: `
|
||||
<button>change propA</button>
|
||||
<button>change propB</button>
|
||||
<p>true fallback</p>
|
||||
`,
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [propA, propB] = target.querySelectorAll('button');
|
||||
|
||||
await propA.click();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>change propA</button>
|
||||
<button>change propB</button>
|
||||
<p>false fallback</p>
|
||||
`
|
||||
);
|
||||
|
||||
await propB.click();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>change propA</button>
|
||||
<button>change propB</button>
|
||||
<p>false defined</p>
|
||||
`
|
||||
);
|
||||
|
||||
await propA.click();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>change propA</button>
|
||||
<button>change propB</button>
|
||||
<p>true defined</p>
|
||||
`
|
||||
);
|
||||
|
||||
await propB.click();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>change propA</button>
|
||||
<button>change propB</button>
|
||||
<p>true</p>
|
||||
`
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,12 @@
|
||||
<script>
|
||||
import Component from './Component.svelte';
|
||||
|
||||
let props = $state({
|
||||
propA: true,
|
||||
propB: undefined
|
||||
});
|
||||
</script>
|
||||
|
||||
<button on:click={() => {props.propA = !props.propA}}>change propA</button>
|
||||
<button on:click={() => {props.propB = props.propB ? undefined : 'defined'}}>change propB</button>
|
||||
<Component {...props}/>
|
Loading…
Reference in new issue