Skip to content
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

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

Open
shaylevi2 opened this issue Apr 14, 2023 · 4 comments

Comments

@shaylevi2
Copy link

shaylevi2 commented Apr 14, 2023

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.

@shaylevi2 shaylevi2 changed the title Race condition causes old "useSWRV" to set the isValidating of the new request. Race condition causes old "useSWRV" to set the isValidating of the new request (/key). Apr 14, 2023
@shaylevi2 shaylevi2 changed the title Race condition causes old "useSWRV" to set the isValidating of the new request (/key). Race condition causes old "useSWRV" to set the isValidating of the new request (/ key). Apr 14, 2023
@adamdehaven
Copy link
Member

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

@shaylevi2
Copy link
Author

shaylevi2 commented Apr 18, 2023

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

@shaylevi2
Copy link
Author

shaylevi2 commented May 26, 2023

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

@adamdehaven
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants