From fd1bf6c7a3867c9c816feaa80dfcc7eccf3fd0b9 Mon Sep 17 00:00:00 2001 From: Nic <162764842+Nic-Polumeyv@users.noreply.github.com> Date: Wed, 9 Sep 2026 22:50:22 -0400 Subject: [PATCH] fix: resolve the fallback of an each block in the enclosing scope --- .changeset/each-fallback-scope.md | 5 +++++ packages/svelte/src/compiler/phases/scope.js | 2 +- .../samples/each-fallback-outer-scope/_config.js | 14 ++++++++++++++ .../samples/each-fallback-outer-scope/main.svelte | 10 ++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 .changeset/each-fallback-scope.md create mode 100644 packages/svelte/tests/runtime-runes/samples/each-fallback-outer-scope/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/each-fallback-outer-scope/main.svelte diff --git a/.changeset/each-fallback-scope.md b/.changeset/each-fallback-scope.md new file mode 100644 index 0000000000..5134fc462b --- /dev/null +++ b/.changeset/each-fallback-scope.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: resolve the fallback of an each block in the enclosing scope diff --git a/packages/svelte/src/compiler/phases/scope.js b/packages/svelte/src/compiler/phases/scope.js index e3560753b4..0d5c27b1e8 100644 --- a/packages/svelte/src/compiler/phases/scope.js +++ b/packages/svelte/src/compiler/phases/scope.js @@ -1278,7 +1278,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) { for (const child of node.body.nodes) { visit(child, { scope }); } - if (node.fallback) visit(node.fallback, { scope }); + if (node.fallback) visit(node.fallback); node.metadata = { expression: new ExpressionMetadata(), diff --git a/packages/svelte/tests/runtime-runes/samples/each-fallback-outer-scope/_config.js b/packages/svelte/tests/runtime-runes/samples/each-fallback-outer-scope/_config.js new file mode 100644 index 0000000000..8761693873 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/each-fallback-outer-scope/_config.js @@ -0,0 +1,14 @@ +import { flushSync } from 'svelte'; +import { test } from '../../test'; + +export default test({ + html: '', + + test({ assert, target }) { + const button = target.querySelector('button'); + flushSync(() => { + button?.click(); + }); + assert.htmlEqual(target.innerHTML, ''); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/each-fallback-outer-scope/main.svelte b/packages/svelte/tests/runtime-runes/samples/each-fallback-outer-scope/main.svelte new file mode 100644 index 0000000000..7ebb37e2f7 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/each-fallback-outer-scope/main.svelte @@ -0,0 +1,10 @@ + + +{#each items as item} +
{item}
+{:else} + +{/each}