Skip to content

Using a $derived value with setContext emits warning #16608

@Stadly

Description

@Stadly

Describe the bug

When putting a $derived inside setContext, a state_referenced_locally warning is shown. I think the warning is wrong.

let foo = $derived(...);

// Warning: This reference only captures the initial value of `foo`.
// Did you mean to reference it inside a closure instead?
setContext("derived-context", foo);

Reproduction

https://svelte.dev/playground/1cdbccb4b0be48aba01cd0d27e74aa35?version=5.38.1

Logs

System Info

System:
    OS: Linux 5.15 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (16) x64 Intel(R) Xeon(R) W-11955M CPU @ 2.60GHz
    Memory: 3.03 GB / 15.23 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 20.19.3 - /usr/local/bin/node
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 10.11.1 - /usr/local/bin/pnpm
  npmPackages:
    svelte: ^5.37.3 => 5.37.3

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions