fix: resolve the fallback of an each block in the enclosing scope

each-fallback-scope
Nic 9 hours ago
parent ce89035ecb
commit fd1bf6c7a3

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: resolve the fallback of an each block in the enclosing scope

@ -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(),

@ -0,0 +1,14 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
html: '<button>outer</button>',
test({ assert, target }) {
const button = target.querySelector('button');
flushSync(() => {
button?.click();
});
assert.htmlEqual(target.innerHTML, '<button>changed</button>');
}
});

@ -0,0 +1,10 @@
<script>
let items = $state([]);
let item = $state('outer');
</script>
{#each items as item}
<p>{item}</p>
{:else}
<button onclick={() => (item = 'changed')}>{item}</button>
{/each}
Loading…
Cancel
Save