Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eleven-moons-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: don't deactivate other batches
4 changes: 4 additions & 0 deletions packages/svelte/src/internal/client/reactivity/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script lang="ts">
let { ref } = $props();
let tick = $state(0);
let ref_exists = $state(true);
$effect(() => {
tick;
ref_exists = ref !== null;
});
</script>

<p>{ref_exists}</p>
<button onclick={() => tick++}>check</button>
Original file line number Diff line number Diff line change
@@ -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,
`
<div>div</div>
<p>true</p>
<button>check</button>
<p></p>
`
);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script>
import Component from "./Component.svelte";
let ref = $state(null);
let foo = $derived(await 1);
</script>

<div bind:this={ref}>div</div>

<Component {ref} />

{#if foo}
<p></p>
{/if}
Loading