-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Refetch should not happen if no active subscribers #1974
Conversation
Ha, timing ^^ What I said in the other thread pretty much applies here - "not fetching" in that case is not really an option, as that would leave stale data in the cache. In this case, the data would need to be removed from the cache, like it is in the case of cache invalidation. |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit f80108e:
|
I will adjust the PR tomorrow with the fixes, as per our discussion in the issue. |
@phryneas I changed the logic now and wrote a test for it. I considered placing the logic in Is it necessary to also include the same test for reconnect? They run the same function, so if the other tests for reconnect passes, and my new test passes, then it should be guaranteed to pass on reconnect too. |
packages/toolkit/src/query/core/buildMiddleware/windowEventHandling.ts
Outdated
Show resolved
Hide resolved
packages/toolkit/src/query/core/buildMiddleware/windowEventHandling.ts
Outdated
Show resolved
Hide resolved
@phryneas That should be the last changes. If there is anything else you'd like me to include, I'll be glad to. When we can we expect this to be published? The current logic (where the data is refetched) results in quite a high performance impact on both backend and frontend in our current project. I am sure however we could work around it for now by disabling refetching on our specific endpoints. |
I'l try tol take a look at it this evening or tomorrow. |
Looks good to me. Let's get this in. |
Fixes #1530
All logic that checks if there are active subscriptions in the code does a falsey check as well as a keys length check on the subscription sub state, except for the code that refetches valid queries.
Here is an example from the handleUnsubscribe function.
Here is another from invalidateTags.
This PR includes the same check to resolve this issue. See #1530 for more information.
Attempting a refetch for data that has no subscribers should remove it from the cache, similar to
invalidateTags
, because the data would become stale relative to other cache data which would be refetched on focus / reconnect.