From 60eaa92b0bdd576d8ad791a8ed7ad56bcb1575db Mon Sep 17 00:00:00 2001
From: Simon H <5968653+dummdidumm@users.noreply.github.com>
Date: Tue, 26 May 2026 18:16:27 +0200
Subject: [PATCH] fix: resume outro-ed branches if they were kept around
(#18291)
If a branch is removed from the visible dom, it may be kept around
because a subsequent batch will intro it again. If we don't resume the
effects it will stay inert and therefore not react to updates anymore
---
.changeset/sad-shoes-help.md | 5 ++
.../internal/client/dom/blocks/branches.js | 2 +
.../samples/async-branch-reintro/_config.js | 58 +++++++++++++++++++
.../samples/async-branch-reintro/main.svelte | 23 ++++++++
4 files changed, 88 insertions(+)
create mode 100644 .changeset/sad-shoes-help.md
create mode 100644 packages/svelte/tests/runtime-runes/samples/async-branch-reintro/_config.js
create mode 100644 packages/svelte/tests/runtime-runes/samples/async-branch-reintro/main.svelte
diff --git a/.changeset/sad-shoes-help.md b/.changeset/sad-shoes-help.md
new file mode 100644
index 0000000000..76db87ba95
--- /dev/null
+++ b/.changeset/sad-shoes-help.md
@@ -0,0 +1,5 @@
+---
+'svelte': patch
+---
+
+fix: resume outro-ed branches if they were kept around
diff --git a/packages/svelte/src/internal/client/dom/blocks/branches.js b/packages/svelte/src/internal/client/dom/blocks/branches.js
index 33c34f58bb..141b914537 100644
--- a/packages/svelte/src/internal/client/dom/blocks/branches.js
+++ b/packages/svelte/src/internal/client/dom/blocks/branches.js
@@ -90,6 +90,8 @@ export class BranchManager {
var offscreen = this.#offscreen.get(key);
if (offscreen) {
+ // effect could have been outro'ed before through a prior batch — resume if necessary
+ resume_effect(offscreen.effect);
this.#onscreen.set(key, offscreen.effect);
this.#offscreen.delete(key);
diff --git a/packages/svelte/tests/runtime-runes/samples/async-branch-reintro/_config.js b/packages/svelte/tests/runtime-runes/samples/async-branch-reintro/_config.js
new file mode 100644
index 0000000000..928db008e6
--- /dev/null
+++ b/packages/svelte/tests/runtime-runes/samples/async-branch-reintro/_config.js
@@ -0,0 +1,58 @@
+import { tick } from 'svelte';
+import { test } from '../../test';
+
+export default test({
+ async test({ assert, target }) {
+ await tick();
+ const [inc_count, inc_both, shift] = target.querySelectorAll('button');
+
+ inc_both.click();
+ await tick();
+ inc_count.click();
+ await tick();
+ assert.htmlEqual(
+ target.innerHTML,
+ `
+
+
+
+ 0
+ 0
+
+ `
+ );
+
+ shift.click();
+ await tick();
+ shift.click();
+ await tick();
+ assert.htmlEqual(
+ target.innerHTML,
+ `
+
+
+
+ 1
+ 2
+
+ `
+ );
+
+ const button = /** @type {HTMLButtonElement} */ (target.querySelector('button:last-child'));
+ button.click();
+ await tick();
+ shift.click();
+ await tick();
+ assert.htmlEqual(
+ target.innerHTML,
+ `
+
+
+
+ 2
+ 2
+
+ `
+ );
+ }
+});
diff --git a/packages/svelte/tests/runtime-runes/samples/async-branch-reintro/main.svelte b/packages/svelte/tests/runtime-runes/samples/async-branch-reintro/main.svelte
new file mode 100644
index 0000000000..92b7669fa9
--- /dev/null
+++ b/packages/svelte/tests/runtime-runes/samples/async-branch-reintro/main.svelte
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+{await push(other)}
+{#if count % 2 === 0}
+ {await push(count)}
+
+{/if}