Closed as not planned
Description
Describe the bug
I'm experiencing the ownership_invalid_mutation
warning, where is says "src/Child.svelte mutated a value owned by src/App.svelte. This is strongly discouraged. Consider passing values to child components with bind:
, or use a callback instead".
The problem I noticed (after running the repro demo below) are
- The
obj
variable is declared in Shared.svelte.ts, and mutated in App.svelte. Why the warning says it is owned by App.svelte instead of Shared.svelte.ts? - Why is this pattern bad? What is the harm here?
- Even if it is bad, I can easily bypass the warning by changing
facade.obj = { a: 1 }
from App.svelte to
facade.obj.a = 1
which I think is exactly equivalent. Why is it suddenly OK now?
4. $state.snapshot()
currently doesn't seem to help in any way.
Reproduction
I managed to create a minimum demo, but strangely I can only reproduce the warning running locally.
Steps:
- I don't know a way to create Svelte 5 template, so
npm create vite@latest my-svelte-project -- --template svelte
. - Manually upgrade dependencies in package.json to Svelte 5.
- head here and copy the code.
npm run dev
- Open web console.
- Change the text box value to any other number.
Logs
No response
System Info
@sveltejs/vite-plugin-svelte@4.0.0-next.3
@tsconfig/svelte@5.0.4
svelte@5.0.0-next.144
svelte-check@3.8.0
vite@5.2.12
Microsoft Edge 125.0.2535.79
Firefox 126.0.1
Severity
annoyance
Metadata
Metadata
Assignees
Labels
No labels