mirror of https://github.com/sveltejs/svelte
fix: don't eagerly execute deriveds on resume (#16150)
* Add failing test * Add {@const} test case * Fix the bug * Add yet another test case * Better fix * Changeset * simplify * this appears to be unnecessary --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/16157/head
parent
113a3daab2
commit
92ea58bee6
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: don't eagerly execute deriveds on resume
|
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
let { value } = $props()
|
||||
|
||||
const text = $derived(value.toString())
|
||||
|
||||
$effect(() => console.log(text))
|
||||
</script>
|
@ -0,0 +1,17 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target, logs }) {
|
||||
const [btn1, btn2] = target.querySelectorAll('button');
|
||||
const [div] = target.querySelectorAll('div');
|
||||
|
||||
flushSync(() => btn1?.click());
|
||||
assert.htmlEqual(div.innerHTML, '123 123');
|
||||
assert.equal(div.inert, true);
|
||||
|
||||
flushSync(() => btn2?.click());
|
||||
assert.htmlEqual(div.innerHTML, '');
|
||||
assert.deepEqual(logs, ['123']);
|
||||
}
|
||||
});
|
@ -0,0 +1,23 @@
|
||||
<script>
|
||||
import Component from './Component.svelte';
|
||||
|
||||
let outer = $state(true);
|
||||
let inner = $state(123);
|
||||
|
||||
function outro() {
|
||||
return { duration: 100 };
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if outer}
|
||||
<div out:outro>
|
||||
{#if inner}
|
||||
{@const text = inner.toString()}
|
||||
{text} {inner.toString()}
|
||||
<Component value={inner} />
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<button onclick={() => { outer = false; inner = undefined; }}>Set both to falsy</button>
|
||||
<button onclick={() => { outer = true }}>Set outer to truthy</button>
|
Loading…
Reference in new issue