mirror of https://github.com/sveltejs/svelte
fix: avoid false-positive batch invariant error (#18246)
Thanks to https://github.com/sveltejs/svelte/issues/17940#issuecomment-4480016550 I was finally able to isolate and reproduce a false-positive invariant error. I had a hunch this could happen and this shows it. Essentially, you can end up in situations where two batches are scheduled to run in the same microtask queue flush, and if the first rebases the second the invariant will throw, which is wrong. We can avoid this by checking if a decrement is queued.pull/18248/head
parent
000c594e05
commit
d654db83ef
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: avoid false-positive batch invariant error
|
||||
@ -0,0 +1,16 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
// This test mainly checks that we don't run into the 'Batch has scheduled roots' invariant wrongly.
|
||||
// It is crafted such that two batches are scheduled to run in the same microtask, and the first
|
||||
// tries to rebase the second.
|
||||
async test({ assert, target }) {
|
||||
await tick();
|
||||
const [run] = target.querySelectorAll('button');
|
||||
|
||||
run.click();
|
||||
await tick();
|
||||
assert.htmlEqual(target.innerHTML, '<button>run</button> none none 0');
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
let selectedId = $state(1);
|
||||
let selectedOption = $derived(selectedId ? await selectedId : null);
|
||||
</script>
|
||||
|
||||
<button onclick={() => (selectedId = null)}>run</button>
|
||||
|
||||
{selectedId ?? "none"} {selectedOption ?? "none"} {$effect.pending()}
|
||||
Loading…
Reference in new issue