SWRV returns wrong cached data before first fetch while using key watcher function.
See original GitHub issueCodeSandbox:
https://codesandbox.io/s/swrv-first-fetch-key-ip6ox?file=/src/App.vue
Click on the add
button and see that check
turns false
.
I’d assume that the data returned by useSWRV is either undefined (no cache and data not yet available), or some cached data for that key (That is, check to be always true
). Not some cached data for some older value of the key.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10
Top Results From Across the Web
Keep previous result while revalidating · Issue #192 · vercel/swr
My case is a search field, and after I've gotten my first data , I'd really like the returned data to stick until...
Read more >Data fetching and caching with SWR and Vue.js
Let's implement a caching pattern called stale-while-revalidate, or SWR, with Vue.
Read more >SWR not pulling from cache - Stack Overflow
SWR is a strategy to first return the data from cache (stale), then send the fetch request (revalidate), and finally come with the ......
Read more >Data Fetching using Vue Hooks | Darren Jennings
A SWR caching strategy would allow users to see stale data first while fetching, giving an eventually consistent UI. stale-while-revalidate data ...
Read more >How to fix SWR to work correctly with initialData or fallbackData
I've been using the awesome data fetching library SWR (the same the ... the requests in the background, wait for the data and...
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
Better yet, we could have a new return value named
isLoading
that would betrue
when there’s a request ongoing and thedata
is eitherundefined
or does not correspond to the currentkey
.That way users can show a spinner when either:
data
isundefined
, when showing cacheddata
for the previouskey
is better than the spinner.isLoading
is true, when showing cacheddata
for the previouskey
is undesirable.Hello @pbowyer! I had a vested interest in this library when I was employed at Kong, which included battle testing new features and guiding the api. I have a different job now but otherwise have no qualms with this library and would use it again if I build any vue apps! Happy to continue maintaining it until a community member steps up to do it.