mirror of https://github.com/sveltejs/svelte
fix: avoid disconnecting deriveds that are still active (#13292)
* fix: ensure the if block condition is wrapped in a derived * add test * tidy * fix key block * fix key block test * alternative approach * changeset * Update packages/svelte/src/internal/client/runtime.js Co-authored-by: Rich Harris <rich.harris@vercel.com> --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/13293/head
parent
9d1394fb9d
commit
09527fd190
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: avoid disconnecting deriveds that are still active
|
@ -0,0 +1,19 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target }) {
|
||||
await Promise.resolve();
|
||||
|
||||
let [btn1] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => {
|
||||
btn1?.click();
|
||||
});
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`false\ntrue\n<button>Toggle</button>\nfirst:\nfalse\n<br>\nsecond:\ntrue`
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,21 @@
|
||||
<script>
|
||||
let first = $state(true)
|
||||
let second = $state(false)
|
||||
let derivedSecond = $derived(second)
|
||||
|
||||
queueMicrotask(() => {
|
||||
first = false
|
||||
});
|
||||
</script>
|
||||
|
||||
{first} {second}
|
||||
|
||||
<button onclick={() => {
|
||||
second = true
|
||||
}}>Toggle</button>
|
||||
|
||||
{#if first || derivedSecond}
|
||||
first: {first}
|
||||
<br />
|
||||
second: {derivedSecond}
|
||||
{/if}
|
Loading…
Reference in new issue