mutate in useSWRInfinite is broken when passing data and revalidate true
See original GitHub issueBug report
Description / Observed Behavior
When using useSWRInfinite
, if we call the bound mutate
function and we pass the data argument, the data is not updated or revalidated.
Expected Behavior
I expect useSWRInfinite
to both update the cache and re-fetch data from source.
Repro Steps / Code Example
Notice how mutate(data)
doesn’t update the cache or revalidate the data but mutate(data, false)
does update the cache. mutate()
revalidates with no issues.
Additional Context
SWR version. 0.4.0
I guess this is because the mutate
function for useSWRInfinite
is not updating the cached pages with the data
parameter before calling useSWR
mutate. When the infinite fetcher adapter runs, this is equal: config.compare(originalData[i], pageData)
. mutate
from useSWR
will just update the global cache key for the infinite list, not the individual pages as this code would assume
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:11 (1 by maintainers)
for workaround you can do:
the first one mutates the cache, the second triggers revalidation.
forgot to save my sandbox before sharing. it should be okay now