Skip to content

setContext fails in child component after await in script tag #16629

@martme

Description

@martme

Describe the bug

Components using setContext cause application to crash if rendered after an await in the component script tag.
The issue is seemingly not present when running dev server, only in production builds.

Reproduction

https://svelte.dev/playground/59116dbb8f1e484b8aefd3b0ebd303eb?version=latest

Logs

Error
Svelte error: set_context_after_init
`setContext` must be called when a component first initializes, not in a subsequent effect or after an `await` expression
https://svelte.dev/e/set_context_after_init

System Info

System:
    OS: macOS 15.6
    CPU: (8) arm64 Apple M1 Pro
    Memory: 79.70 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
    npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm
    pnpm: 10.9.0 - ~/.nvm/versions/node/v22.14.0/bin/pnpm
  Browsers:
    Chrome: 139.0.7258.128
    Safari: 18.6
  npmPackages:
    svelte: ^5.0.0 => 5.38.1

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions