Closed Mali-2 closed 6 months ago
There are two false positives here:
getContext
should mean you're allowed to mutate the thing in the componentI am not sure what to make out of this. I think, I have the same problem and have a simpler example: REPL - see comment in Field.svelte
@dummdidumm do you mean that this error message is a bug or that I should find another way of solving this setup?
@kuechlerm yea I think he means it is a bug since he's agreeing that they're false positives. Curiously with your example if you move list
in Form.svelte like so:
<script context="module">
+ let list = $state([]);
</script>
<script>
import { setContext } from 'svelte';
let { children } = $props();
- let list = $state([]);
setContext('list', list);
</script>
{@render children()}
... then the error message disappears.
@dummdidumm The problem comes back currently with HMR, when code is changed on a running page.
I use getContext
to get reactive state and there is no warning until HMR reloads a file.
Please open a new issue with a minimum reproducible
Describe the bug
Hello : ) I believe the below generates a false positive in terms of state ownership and mutation. This occurs in svelte next.68 - it did Not occur in next.61 - When creating an external state 'creator' like this: ~ createMyState.svelte.ts
And using it like this with
setContext()
: ~ +page.svelte (Parent):~Child:
You get the following console error:
However, if the
createMyState()
function is written within the +page.svelte (Parent) directly - Not external - it works fine with no errors.Reproduction
https://github.com/Mali-2/state
Logs
System Info
Severity
blocking an upgrade