Skip to content

Stores cannot be used in async components #16440

@ottomated

Description

@ottomated

Describe the bug

If any stores are used in an async component, the $$cleanup function gets injected in a different function than it's called.

<script>
  import {writable} from 'svelte/store';
  const store = writable('world');
  await 'anything';
</script>

<h1>Hello {$store}!</h1>

$setup_stores gets called inside the async $body function, but $$cleanup goes in the actual component body.

Reproduction

reproduction

Logs

$$cleanup is not defined in <unknown> in __wrapper.svelte

System Info

svelte 5.36.8 in playground

Severity

blocking an upgrade

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions