sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
78.73k stars 4.13k forks source link

`#each` may not update when passed `$derived` containing `$store` #13569

Open dummdidumm opened 2 hours ago

dummdidumm commented 2 hours ago

Describe the bug

When a $derived that subscribes to a $store is passed to an #each, the contents of the each block may not properly update. That's because our static analysis (which was added in #12808) doesn't recognize that the array is coarse-grained

Reproduction

playground link

(it works when you make each aware of the store: playground link)

Logs

No response

System Info

Svelte version: 5.0.0-next.264

Severity

annoyance

buhrmi commented 2 hours ago

Funnily, the reproduction link shows a working version.

Here is a non-working version: playground link

buhrmi commented 1 hour ago

And here is the same version, but with the incItem function changed to replace the item in the array, instead of updating it in-place: playground link

replacing the item in the store array triggers reactivity in the each block. updating in-place does not.