mirror of https://github.com/sveltejs/svelte
fix: ensure computed props are wrapped in derived (#9835)
parent
d9c250a4bf
commit
e2dcdc2887
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: ensure computed props are wrapped in derived
|
@ -0,0 +1,10 @@
|
|||||||
|
<script>
|
||||||
|
import { log } from './log.js';
|
||||||
|
|
||||||
|
const {active} = $props();
|
||||||
|
$effect.pre(() => {
|
||||||
|
log.push('active changed', active)
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p>Item is {active ? 'active' : 'inactive'}</p>
|
@ -0,0 +1,19 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { log } from './log.js';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
before_test() {
|
||||||
|
log.length = 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
async test({ assert, target }) {
|
||||||
|
log.length = 0;
|
||||||
|
|
||||||
|
const input = /** @type {HTMLInputElement} */ (target.querySelector('input'));
|
||||||
|
input.value = '1';
|
||||||
|
flushSync(() => input.dispatchEvent(new window.Event('input')));
|
||||||
|
|
||||||
|
assert.deepEqual(log, ['active changed', false, 'active changed', true]);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,2 @@
|
|||||||
|
/** @type {any[]} */
|
||||||
|
export const log = [];
|
@ -0,0 +1,11 @@
|
|||||||
|
<script>
|
||||||
|
import Item from './Item.svelte';
|
||||||
|
let activeIndex = $state(0);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<input bind:value={activeIndex} type="number" min="0" max={4} />
|
||||||
|
<Item active={activeIndex == 0} />
|
||||||
|
<Item active={activeIndex == 1} />
|
||||||
|
<Item active={activeIndex == 2} />
|
||||||
|
<Item active={activeIndex == 3} />
|
||||||
|
<Item active={activeIndex == 4} />
|
Loading…
Reference in new issue