Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svelte 5: Unnecessary ownership_invalid_mutation warning #11848

Closed
CrendKing opened this issue May 31, 2024 · 1 comment
Closed

Svelte 5: Unnecessary ownership_invalid_mutation warning #11848

CrendKing opened this issue May 31, 2024 · 1 comment

Comments

@CrendKing
Copy link

CrendKing commented May 31, 2024

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

  1. 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?
  2. Why is this pattern bad? What is the harm here?
  3. 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:

  1. I don't know a way to create Svelte 5 template, so npm create vite@latest my-svelte-project -- --template svelte.
  2. Manually upgrade dependencies in package.json to Svelte 5.
  3. head here and copy the code.
  4. npm run dev
  5. Open web console.
  6. Change the text box value to any other number.

Logs

No response

System Info

@sveltejs/[email protected]
@tsconfig/[email protected]
[email protected]
[email protected]
[email protected]

Microsoft Edge 125.0.2535.79
Firefox 126.0.1

Severity

annoyance

@dummdidumm
Copy link
Member

This was fixed by #11812 which was supposed to be released already, but it seems the CI fucked up. Investigating that, but closing this issue in the meantime.

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants