Skip to content

Svelte 5: Unnecessary ownership_invalid_mutation warning #11848

Closed as not planned
@CrendKing

Description

@CrendKing

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/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

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