revalidateOnMount is broken on useSWRInfinite
See original GitHub issueBug report
Description / Observed Behavior
useSWRInfinite
is not revalidating on mount when prop is set in config
Expected Behavior
It should revalidate on mount
Repro Steps / Code Example
mounting/unmounting has no effect on the data reendered on the page. note how it works with a useEffect
call to mutate()
Additional Context
SWR version. 0.4.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:5 (1 by maintainers)
Top Results From Across the Web
API
SWR is a React Hooks library for data fetching. SWR first returns the data from cache (stale), then sends the fetch request (revalidate),...
Read more >swr: Versions
In this release, useSWR , useSWRInfinite and useSWRImmutable will return an extra ... fix: useSWRInfinite revalidates with revalidateOnMount by @koba04 in ...
Read more >Renovate Bot Package Diff
If it's not mounted yet and it should revalidate on mount, revalidate. ... + // We have to several type castings here because...
Read more >reactjs - SWR not pulling from cache
Depending on your use cases, you probably want these options off too: revalidateOnMount; revalidateOnFocus; revalidateOnReconnect. As the other ...
Read more >React Hooks library for remote data fetching
This PR adds a new useSWRInfinite API for infinite loading, ... fix: useSWRInfinite revalidates with revalidateOnMount by @koba04 in ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sorry I probably should have explained my codesandbox a little bit better. each mount/unmount increments a counter by 1. this counter is passed as prop to a component that gets mounted/unmounted. this component calls
useSWRInfinite
and provides a fetcher function that depends on this counter… so in theory, each mount/unmount cycle should make the fetcher function print 2 more numbers than the previous cycle.however the number never changes on each mount/unmount, it’s always 0 as it’s the first value returned by the fetcher. when it’s mounted, if you click “revalidate”, it calls
mutate
which will run the fetcher again and print the true values. so you just have to click mount/unmount a few times and then revalidate to see the issue.if you enable the
useEffect
checkbox, you will see that a simplemutate()
call on mount works the way thatrevalidateOnMount
should.Confirmed that this is fixed in the latest version: https://codesandbox.io/s/quizzical-agnesi-fzjkw?file=/src/Component.js. One thing to keep in mind is
dedupingInterval
can also make a difference here.