Skip to content

$effect not re-run after mutating nested state #15866

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

Open
jacekalms opened this issue May 6, 2025 · 0 comments
Open

$effect not re-run after mutating nested state #15866

jacekalms opened this issue May 6, 2025 · 0 comments

Comments

@jacekalms
Copy link

Describe the bug

Reproduction

Consider the following code. It prints 1 to the console, followed by 10 – as expected.

let state = $state({ value: 1 });

$effect(() => {
  console.log(state.value);

  if (state.value == 1) {
    state = { value: 10 };
  }
});

Now wire up these actions to buttons A and B. Click either of them.

// Button A
function set100() {
  state.value = 100;
}

// Button B
function replaceWith1000() {
  state = { value: 1000 };
}

Expected behavior

Clicking either button A or B should re-run the effect, hence printing either 100 or 1000 to the console.

Actual behavior

Clicking button A doesn’t re-run the effect. Only clicking button B does.

Further info

Reproduction

Still works in 5.23.2:
https://svelte.dev/playground/9feb1af4faa04465ac1cc7da439fe69e?version=5.23.2

Broken in 5.24.0 and onwards:
https://svelte.dev/playground/9feb1af4faa04465ac1cc7da439fe69e?version=5.24.0

Logs

System Info

System:
    OS: macOS 15.3.2
    CPU: (10) arm64 Apple M1 Max
    Memory: 4.16 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.9.0 - /opt/homebrew/bin/node
    npm: 11.2.0 - /opt/homebrew/bin/npm
  Browsers:
    Brave Browser: 134.1.76.74
    Chrome: 135.0.7049.115
    Safari: 18.3.1
  npmPackages:
    svelte: ^5.0.0 => 5.28.2

Severity

annoyance

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

1 participant