Skip to content

Mutating array within $state rune breaks reactivity in certain cases #10118

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

Closed
biwecka opened this issue Jan 8, 2024 · 0 comments · Fixed by #10121
Closed

Mutating array within $state rune breaks reactivity in certain cases #10118

biwecka opened this issue Jan 8, 2024 · 0 comments · Fixed by #10121

Comments

@biwecka
Copy link

biwecka commented Jan 8, 2024

Describe the bug

Given the following state variable let arr = $state<string[]>([]). When mutating it with arr.push("...") and arr.splice(i, 1) reactivity breaks after adding at least two items to the array and then removing all of them. Afterwards adding an item again does not update the UI.

Reproduction

This REPL contains an example of the potential bug and two alternatives to mutating the array which work as expected. The working alternatives both reassign the value of the array. That's why I'm unsure if the reactivity breaking when only using splice might actually be the the expected behavior.

Logs

No response

System Info

System:
    OS: Linux 6.1 NixOS 23.11 (Tapir) 23.11 (Tapir)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    Memory: 12.13 GB / 15.27 GB
    Container: Yes
    Shell: 5.9 - /run/current-system/sw/bin/zsh
  Binaries:
    Node: 20.9.0 - /etc/profiles/per-user/biwecka/bin/node
    npm: 10.1.0 - /etc/profiles/per-user/biwecka/bin/npm
  npmPackages:
    svelte: ^5.0.0-next.1 => 5.0.0-next.28

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

Successfully merging a pull request may close this issue.

1 participant