Kong / swrv

Stale-while-revalidate data fetching for Vue

Home Page:https://docs-swrv.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Race condition causes old "useSWRV" to set the isValidating of the new request (/ key).

shaylevi2 opened this issue · comments

I believe this is related to #24

And is being caused by this line: https://github.com/Kong/swrv/blob/master/src/use-swrv.ts#L280

I would create a PR of removing this line, but the code is a bit complex and I'm not sure what else is influenced.

I'm not sure I fully understand the issue you're reporting. Would you mind providing reproduction examples or steps and more details?

SomeComponent.vue has a prop called id and has the following code in it:
const { data, error, isValidating } = useSWRV(() => '/api?id=' + props.id)

Now, if you change the id prop value passed to SomeComponent.vue while a fetch is active, it will trigger another fetch request (as expected) the problem is the isValidating of that new request will become false when the previous fetch call completes when it should obviously wait for the new call to complete (as these are different keys).

If you look at #26 you'll notice they've added a check to see they are not updating the "IsValidating" of a previous call, but they haven't done so in the problematic line I was referring to: https://github.com/Kong/swrv/blob/master/src/use-swrv.ts#L280

Did you get a chance to look into it? @adamdehaven

I think this could be resolved by utilizing dependent caching to invalidate the cache when the prop value changes.