-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SWRV returns wrong cached data before first fetch while using key watcher function. #208
Comments
your computed property is returning |
The fetcher used is just an example, and might actually be some API calls instead. So it might not be that simple to actually know whether the data returned is some cached stall data for the correct key or not, without explicitly adding the key to the return value of all fetchers... |
@peter50216 you make a good point on the difference here, and are describing the behavior that we do not clear |
I think it would be better to add an option for that since it would be a breaking change if we change the default, and from that linked react issue people sometimes do want the sticky behavior. I'll try to prepare a PR. |
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. |
Closing from inactivity |
I've also ran into this issue. I understand why would people want to use a "sticky" value. There are however cases when this is not desirable. I need to distinguish whether Unlike SWR that supports both cases (even though the "sticky" case with an add-on hook), SWRV only supports one case - the "sticky" case, not the " Are there any strong opinions on how this new option should be named? Does |
Alternatively, we can provide a new return value, a This is functionally equivalent to the const { data, isSticky } = useSWRV(...)
const nonStickyData = computed(() => isSticky.value ? undefined : data.value) More often this would not be needed, one would just want to distinguish when the I believe this design is better than the @darrenjennings Before I spend time with a PR, what are your preferences re these two alternatives? Re the name of the return value / option? Any ideas? |
Better yet, we could have a new return value named That way users can show a spinner when either:
|
Update: Just came accross https://swr.vercel.app/docs/advanced/understanding#return-previous-data-for-better-ux. SWR now has the config option and it is called |
* feat(return) add isLoading return value (#208) * feat(return) unset isLoading in cases not covered by tests (#208) --------- Co-authored-by: Adam DeHaven <[email protected]>
CodeSandbox:
https://codesandbox.io/s/swrv-first-fetch-key-ip6ox?file=/src/App.vue
Click on the
add
button and see thatcheck
turnsfalse
.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.The text was updated successfully, but these errors were encountered: