solidjs / solid

A declarative, efficient, and flexible JavaScript library for building user interfaces.
https://solidjs.com
MIT License
32.24k stars 920 forks source link

on() not triggered when using a mutable store item as a dependency #1833

Open chvelkov opened 1 year ago

chvelkov commented 1 year ago

Describe the bug

Here's an example:

Your Example Website or App

https://playground.solidjs.com/anonymous/64e29718-38db-4df4-afeb-4445b799d170

Steps to Reproduce the Bug or Issue

Press Increment

Expected behavior

When pressing the button I'd expect that both counters update, however the one using on() isn't working.

Screenshots or Videos

No response

Platform

Additional context

No response

ryansolid commented 1 year ago

Yeah this is akin to setting a value at an index in createStore whereas the way you generally do this is spread in a new array. https://playground.solidjs.com/anonymous/6ea855b3-1f2d-4dc6-a9c0-e413b6258e64

It notifies things that listen to the index but not everything. The thing is that something that would change the length probably should trigger the parent.. we use length actually as a trick for this as iteration depends on it which means it works in all cases other than on which doesn't iterate. And since on is a blanket reactive wrapper (ie can return anything not just the thing that is accessed) there isn't really a way to address this on the on side.

The fact that produce is also impacted suggests this is something we should consider changing if feasible. Thanks for bringing this to my attention. I never use on or mutable interfaces so this wasn't in my direct thinking.

I guess this is our version of Svelte's

array.push(1);
array = array;