-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
9d1394f
commit 09527fd
Showing
4 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: avoid disconnecting deriveds that are still active |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/svelte/tests/runtime-runes/samples/if-block-dependencies/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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` | ||
); | ||
} | ||
}); |
21 changes: 21 additions & 0 deletions
21
packages/svelte/tests/runtime-runes/samples/if-block-dependencies/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |