Skip to content

Commit 57fed6a

Browse files
authored
fix: place instance-level snippets inside async body (#16666)
* fix: place instance-level snippets inside async body * lint
1 parent e883cd0 commit 57fed6a

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

.changeset/cool-garlics-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: place instance-level snippets inside async body

packages/svelte/src/compiler/phases/3-transform/client/transform-client.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,20 +362,23 @@ export function client_component(analysis, options) {
362362
store_init,
363363
...store_setup,
364364
...legacy_reactive_declarations,
365-
...group_binding_declarations,
366-
...state.instance_level_snippets
365+
...group_binding_declarations
367366
]);
368367

369368
if (analysis.instance.has_await) {
370369
const body = b.block([
370+
...state.instance_level_snippets,
371371
.../** @type {ESTree.Statement[]} */ (instance.body),
372372
b.if(b.call('$.aborted'), b.return()),
373373
.../** @type {ESTree.Statement[]} */ (template.body)
374374
]);
375375

376376
component_block.body.push(b.stmt(b.call(`$.async_body`, b.arrow([], body, true))));
377377
} else {
378-
component_block.body.push(.../** @type {ESTree.Statement[]} */ (instance.body));
378+
component_block.body.push(
379+
...state.instance_level_snippets,
380+
.../** @type {ESTree.Statement[]} */ (instance.body)
381+
);
379382

380383
if (!analysis.runes && analysis.needs_context) {
381384
component_block.body.push(b.stmt(b.call('$.init', analysis.immutable ? b.true : undefined)));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { tick } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
async test({ assert, target }) {
6+
await tick();
7+
assert.htmlEqual(target.innerHTML, 'value');
8+
}
9+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
const value = await 'value';
3+
</script>
4+
5+
{#snippet valueSnippet()}
6+
{value}
7+
{/snippet}
8+
9+
{@render valueSnippet()}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import App from './app.svelte';
3+
</script>
4+
<svelte:boundary>
5+
{#snippet pending()}
6+
{/snippet}
7+
<App />
8+
</svelte:boundary>

0 commit comments

Comments
 (0)