You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Although I admit that there isn't much reason to create an effect like that, this is quite a simplified example, and I sometimes need to reset the state of the local storage under a certain condition, and that condition along with localStore["token" === ""] can be combined with other conditions with && or ||.
And I think it can sometimes be easy to overlook an effect like that?
I didn't expect that this could cause infinite loop or "too much recursion" as createSignal and createStore from solid-js don't seem to have this problem.
But could this be something that is good to fix? Just to make it behaves the same as createStore or createSignal from solid-js, which doesn't causes infinite loop whe updating it inside an effect like that
The text was updated successfully, but these errors were encountered:
Signals shouldn't be synchronized in effects, and reading from a signal you are writing to is especially bad as it can lead to infinite loops, as you saw.
The general solution to ensuring that signals have certain values is to:
create a custom setter callback that corrects the value before writing to the signal:
I use
createLocalStorage
from@solid-primitives/storage
and encountertoo much recursion
error in browser when I did the following:Although I admit that there isn't much reason to create an effect like that, this is quite a simplified example, and I sometimes need to reset the state of the local storage under a certain condition, and that condition along with
localStore["token" === ""]
can be combined with other conditions with&&
or||
.And I think it can sometimes be easy to overlook an effect like that?
I didn't expect that this could cause infinite loop or "too much recursion" as
createSignal
andcreateStore
fromsolid-js
don't seem to have this problem.This could probably be fixed in user's code by creating a guard like:
But could this be something that is good to fix? Just to make it behaves the same as
createStore
orcreateSignal
fromsolid-js
, which doesn't causes infinite loop whe updating it inside an effect like thatThe text was updated successfully, but these errors were encountered: