Open
Description
Describe the bug
In https://svelte.dev/tutorial/svelte/context-api:
// in a parent component
import { setContext } from 'svelte';
let context = $state({...});
setContext('my-context', context);
// in a child component
import { getContext } from 'svelte';
const context = getContext('my-context');
But in https://svelte.dev/docs/svelte/compiler-warnings#state_referenced_locally you write:
let count = $state(0);
// warning: state_referenced_locally
setContext('count', count);
I the tutorial tells me to do so; but the compiler says: don't?!
So what is right? Is there some kind of exception to setContext? Or is the tutorial wrong?
Reproduction
Just use the tutorial example.
Logs
System Info
System:
OS: Linux 6.14 Manjaro Linux
CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
Memory: 20.40 GB / 31.26 GB
Container: Yes
Shell: 4.0.2 - /usr/bin/fish
Binaries:
Node: 20.19.1 - /usr/bin/node
npm: 11.3.0 - /usr/bin/npm
bun: 1.2.1 - ~/.bun/bin/bun
Browsers:
Brave Browser: 136.1.78.97
Chromium: 136.0.7103.92
Severity
annoyance