diff --git a/.changeset/eleven-moons-smash.md b/.changeset/eleven-moons-smash.md new file mode 100644 index 000000000000..d37d55d9fed1 --- /dev/null +++ b/.changeset/eleven-moons-smash.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: don't deactivate other batches diff --git a/packages/svelte/src/internal/client/reactivity/batch.js b/packages/svelte/src/internal/client/reactivity/batch.js index 57aa185a31db..84308ef3ed61 100644 --- a/packages/svelte/src/internal/client/reactivity/batch.js +++ b/packages/svelte/src/internal/client/reactivity/batch.js @@ -299,6 +299,10 @@ export class Batch { } deactivate() { + // If we're not the current batch, don't deactivate, + // else we could create zombie batches that are never flushed + if (current_batch !== this) return; + current_batch = null; batch_values = null; } diff --git a/packages/svelte/tests/runtime-runes/samples/async-batch-timing/Component.svelte b/packages/svelte/tests/runtime-runes/samples/async-batch-timing/Component.svelte new file mode 100644 index 000000000000..275860ad9c94 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/async-batch-timing/Component.svelte @@ -0,0 +1,14 @@ + + +
{ref_exists}
+ diff --git a/packages/svelte/tests/runtime-runes/samples/async-batch-timing/_config.js b/packages/svelte/tests/runtime-runes/samples/async-batch-timing/_config.js new file mode 100644 index 000000000000..1da4fdc0bda5 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/async-batch-timing/_config.js @@ -0,0 +1,23 @@ +import { tick } from 'svelte'; +import { test } from '../../test'; + +// This test regresses against batches deactivating other batches than themselves +export default test({ + async test({ assert, target }) { + await tick(); // settle initial await + + const button = target.querySelector('button'); + + button?.click(); + await tick(); + assert.htmlEqual( + target.innerHTML, + ` +true
+ + + ` + ); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/async-batch-timing/main.svelte b/packages/svelte/tests/runtime-runes/samples/async-batch-timing/main.svelte new file mode 100644 index 000000000000..8b582f41d079 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/async-batch-timing/main.svelte @@ -0,0 +1,15 @@ + + +