Replies: 1 comment
-
I have the same issue. I write my own debounce logic for this.
Hope it helps! |
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
Uh oh!
There was an error while loading. Please reload this page.
-
I'm implementing a dynamic web form that calls a debounced
update()
after the user has changed an element in the form. After each successful update I callmutate()
so that SWR updates thedata
object.The problem with this is that if there are multiple
update()
calls (the user is going through the form quickly) SWR will update thedata
object with stale data for fields the user has changed after theupdate()
call was made but before its associatedmutate()
resolves and SWR modifies the cache.For example say there's a form for a
Proposal
data type. The Proposal has fieldstitle
&category
.Timeline for Race Condition
What needs to happen instead
Maybe there could also be a debounce so maybe SWR waits for a brief period to see if any additional
mutate()
calls come in before updating the cache with the data from the latest mutate call.My current solution
Essentially I'm going to remove these mutate calls. When the form sees that it's not being changed anymore call
mutate()
from my component so it only is called once. However, it would be nice is SWR handled multiplemutate()
calls for me.Beta Was this translation helpful? Give feedback.
All reactions