subscribeKey
will re-fire multiple times despite the value not changing
#833
Unanswered
ericschmar
asked this question in
Bug report
Replies: 1 comment
-
Is it possible to reproduce the behavior without tab switch? I would like see the minimal setup. That said, I'm not sure if there's anything to do in Valtio core.
Yeah, if that's the common case, I think developing a new third-party library would make sense. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Finally found the issue in my app, and it turns out that the
subscribeKey
utility was firing upwards of 6-7 times when the value changed.To keep it simple, I have a state object with many properties, one of which is a
controlValue
used for handling Tabs from Mantine. It's a simple string, and is changed whenever a user clicks on a different tab.I had setup
subscribeKey
as follows:I noticed after installing the redux dev tools that the first tab (the default tab) would correctly call my api. Then on tab switch, the
subscribeKey
function would fire upwards of 6-7 times resulting in various components on the screen re-rendering and in the process making interacting with them impossible.I'm not sure the reason this happens as it's a simple string that is triggering these changes, not a complex object. It seems like whatever is checking to see if the value changed is the best place to start looking.
Additionally, this brings up a question of: Would it be valuable to add a config object to subscribing that allows for deduplication and throttling? It's a common usecase to use subscribing to an effect to trigger other things, and ensuring that things run once or don't get spammed would be important.
Beta Was this translation helpful? Give feedback.
All reactions