question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SWRV returns wrong cached data before first fetch while using key watcher function.

See original GitHub issue

CodeSandbox: 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:closed
  • Created 2 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
ivoscommented, Apr 24, 2022

Better yet, we could have a new return value named isLoading that would be true when there’s a request ongoing and the data is either undefined or does not correspond to the current key.

That way users can show a spinner when either:

  1. data is undefined, when showing cached data for the previous key is better than the spinner.
  2. isLoading is true, when showing cached data for the previous key is undesirable.
1reaction
darrenjenningscommented, Jul 26, 2021

Is this because you’ve replaced using it with another library, found it wasn’t needed in practice, moved away from Vue or something else…? I am about to start using it (or something similar) to deduplicate requests, so would be great to hear why before I start.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found