mirror of https://github.com/sveltejs/svelte
When `#traverse_effect_tree` runs, it can execute block effects, which in turn can create effects which are scheduled, which means `queued_root_effects` is now filled again. We didn't take that into account and assumed that in `#commit` we would have no queued root effects. As a result another batch could wrongfully run with the queued root effects of the main batch. That in turn can mean that `skipped_effects` is different on the other batch, leading to some branches not getting traversed into. As a result part of the tree is marked clean while further below batches are still not marked clean. That then breaks reactivity as soon as you schedule an effect in this still-not-clean sub tree, as it will not bubble all the way up to the root, since it comes across a not-clean branch, assuming something was already scheduled. The fix is simple: Stash the queued root effects before rebasing branches. Fixes #17118batch-queued-root-effects-fix
parent
e238e6611e
commit
e3fa620ec9
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: avoid other batches running with queued root effects of main batch
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
<script>
|
||||||
|
let open = $state(false);
|
||||||
|
let menuOptionsEl = $state(null);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => open = !open}>
|
||||||
|
toggle
|
||||||
|
|
||||||
|
{#if open}
|
||||||
|
<!-- bind:this uses effect, which is scheduled, causing queued_root_effects to be filled again -->
|
||||||
|
<span bind:this={menuOptionsEl}>
|
||||||
|
A
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
@ -0,0 +1 @@
|
|||||||
|
B
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [fork, commit, toggle] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
fork.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>fork</button>
|
||||||
|
<button>commit</button>
|
||||||
|
<button>toggle</button>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
toggle.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>fork</button>
|
||||||
|
<button>commit</button>
|
||||||
|
<button>toggle <span>A</span></button>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
toggle.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>fork</button>
|
||||||
|
<button>commit</button>
|
||||||
|
<button>toggle</button>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
toggle.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>fork</button>
|
||||||
|
<button>commit</button>
|
||||||
|
<button>toggle <span>A</span></button>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
commit.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>fork</button>
|
||||||
|
<button>commit</button>
|
||||||
|
B
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { fork } from 'svelte';
|
||||||
|
import A from './A.svelte';
|
||||||
|
import B from './B.svelte';
|
||||||
|
|
||||||
|
let open = $state(true);
|
||||||
|
let f;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<button onclick={() => {
|
||||||
|
f = fork(() => {
|
||||||
|
open = !open;
|
||||||
|
})
|
||||||
|
}}>fork</button>
|
||||||
|
<button onclick={() => {
|
||||||
|
f.commit()
|
||||||
|
}}>commit</button>
|
||||||
|
|
||||||
|
{#if open}
|
||||||
|
<A />
|
||||||
|
{:else}
|
||||||
|
<B />
|
||||||
|
{/if}
|
||||||
Loading…
Reference in new issue