Skip to content

Commit 3d05265

Browse files
committed
fix: place store setup inside async body
1 parent 942eaf0 commit 3d05265

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

.changeset/wise-schools-report.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 store setup inside async body

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,12 @@ export function client_component(analysis, options) {
358358
const push_args = [b.id('$$props'), b.literal(analysis.runes)];
359359
if (dev) push_args.push(b.id(analysis.name));
360360

361-
let component_block = b.block([
362-
store_init,
363-
...store_setup,
364-
...legacy_reactive_declarations,
365-
...group_binding_declarations
366-
]);
361+
let component_block = b.block([...legacy_reactive_declarations, ...group_binding_declarations]);
367362

368363
if (analysis.instance.has_await) {
369364
const body = b.block([
365+
store_init,
366+
...store_setup,
370367
...state.instance_level_snippets,
371368
.../** @type {ESTree.Statement[]} */ (instance.body),
372369
b.if(b.call('$.aborted'), b.return()),
@@ -379,6 +376,7 @@ export function client_component(analysis, options) {
379376
...state.instance_level_snippets,
380377
.../** @type {ESTree.Statement[]} */ (instance.body)
381378
);
379+
component_block.body.unshift(store_init, ...store_setup);
382380

383381
if (!analysis.runes && analysis.needs_context) {
384382
component_block.body.push(b.stmt(b.call('$.init', analysis.immutable ? b.true : undefined)));

0 commit comments

Comments
 (0)