diff --git a/.changeset/stale-loops-love.md b/.changeset/stale-loops-love.md
new file mode 100644
index 0000000000..d36392cca3
--- /dev/null
+++ b/.changeset/stale-loops-love.md
@@ -0,0 +1,5 @@
+---
+'svelte': patch
+---
+
+fix: resolve boundary in correct batch when hydrating
diff --git a/packages/svelte/src/internal/client/dom/blocks/boundary.js b/packages/svelte/src/internal/client/dom/blocks/boundary.js
index b38a3131ca..8046f1e222 100644
--- a/packages/svelte/src/internal/client/dom/blocks/boundary.js
+++ b/packages/svelte/src/internal/client/dom/blocks/boundary.js
@@ -218,8 +218,6 @@ export class Boundary {
this.is_pending = true;
this.#pending_effect = branch(() => pending(this.#anchor));
- var batch = /** @type {Batch} */ (current_batch);
-
queue_micro_task(() => {
var fragment = (this.#offscreen_fragment = document.createDocumentFragment());
var anchor = create_text();
@@ -238,14 +236,12 @@ export class Boundary {
this.#pending_effect = null;
});
- this.#resolve(batch);
+ this.#resolve(/** @type {Batch} */ (current_batch));
}
});
}
#render() {
- var batch = /** @type {Batch} */ (current_batch);
-
try {
this.is_pending = this.has_pending_snippet();
this.#pending_count = 0;
@@ -262,7 +258,7 @@ export class Boundary {
const pending = /** @type {(anchor: Node) => void} */ (this.#props.pending);
this.#pending_effect = branch(() => pending(this.#anchor));
} else {
- this.#resolve(batch);
+ this.#resolve(/** @type {Batch} */ (current_batch));
}
} catch (error) {
this.error(error);
diff --git a/packages/svelte/tests/runtime-runes/samples/effect-in-pending-boundary/Child.svelte b/packages/svelte/tests/runtime-runes/samples/effect-in-pending-boundary/Child.svelte
new file mode 100644
index 0000000000..0f18e43e56
--- /dev/null
+++ b/packages/svelte/tests/runtime-runes/samples/effect-in-pending-boundary/Child.svelte
@@ -0,0 +1,5 @@
+
diff --git a/packages/svelte/tests/runtime-runes/samples/effect-in-pending-boundary/_config.js b/packages/svelte/tests/runtime-runes/samples/effect-in-pending-boundary/_config.js
new file mode 100644
index 0000000000..21575231ee
--- /dev/null
+++ b/packages/svelte/tests/runtime-runes/samples/effect-in-pending-boundary/_config.js
@@ -0,0 +1,7 @@
+import { test } from '../../test';
+
+export default test({
+ async test({ assert, logs }) {
+ assert.deepEqual(logs, ['hello from child']);
+ }
+});
diff --git a/packages/svelte/tests/runtime-runes/samples/effect-in-pending-boundary/main.svelte b/packages/svelte/tests/runtime-runes/samples/effect-in-pending-boundary/main.svelte
new file mode 100644
index 0000000000..c4c0ef23ab
--- /dev/null
+++ b/packages/svelte/tests/runtime-runes/samples/effect-in-pending-boundary/main.svelte
@@ -0,0 +1,11 @@
+
+
+
+
+
+ {#snippet pending()}
+ Loading...
+ {/snippet}
+