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

Multiple revalidates triggered for same cache key on focus #28

Open
Jackman3005 opened this issue Dec 22, 2022 · 2 comments
Open

Multiple revalidates triggered for same cache key on focus #28

Jackman3005 opened this issue Dec 22, 2022 · 2 comments

Comments

@Jackman3005
Copy link

We have a screen with a few layers of nested components. Some of these components make their own calls to useSWRNative to get data that is needed, but they are all using the same cache key. Normally this is totally fine as SWR will load the data once and then share it with all components that requested it.

useSWRNative triggers a revalidate on a focus event if enough time has passed since the previous focus event. This logic appears to be flawed since the lastFocusedAt ref is per hook, not per cache key.

This results in many requests being made when we focus a screen that makes use of multiple useSWRNative calls with the same cache key. (one call for each usage of the hook).

Note: I pulled in the changes in this PR and found that the issue is resolved when using useSWR (instead of useSWRNative) but having the still having this library used in the middleware to revalidate on focus events.

@nandorojo
Copy link
Owner

Interesting, so does the middleware approach solve this?

@Jackman3005
Copy link
Author

From what I tested at that time, using useSWR hook (not useSWRNative) in combination with the swr-react-native middleware in the PR mentioned above we were not getting multiple calls for the same cache key on refocus of the screen.

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