swr
swr copied to clipboard
Make sure mutate invalidates concurrent requests
X-ref: https://github.com/nandorojo/swr-react-native/issues/18
We need to make sure that mutate()
invalidates concurrent requests and deduplicates them. It’ll be similar to this test case, but without a target value (only revalidates): https://github.com/vercel/swr/blob/d45b05dd3c2fc2e0627bd916f1a346fc3e1b1e5d/test/use-swr-local-mutation.test.tsx#L361-L384
It turns to be introduced in #1498 which I think should be the correct behavior, that mutate()
will not be deduplicated by default because it was triggered explicitly by the user. So if calling two mutate()
s in a row:
mutate()
mutate()
It's expected to have 2 revalidation requests started.
However requests fired with useSWR(key, fetcher)
should be deduplicated, if we do mutate()
. This is working as expected.
I think the solution here is to have a way to manually revalidate with deduplication enabled. We'll have to come up with a new option for that...