-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Per below, there's a reasonable use case for some kind of global polling control mechanism. Not sure exactly what it should cover atm, but seems useful.
Discussed in #5033
Originally posted by ChristianAyala July 21, 2025
Question
Is there a way to pause all polling intervals, and re-enable at some point later?
The Scenario
My team uses RTK Query in a Reach Native app and it generally works very well. Lots of our queries use various pollingInterval
durations to periodically keep data up-to-date. However, we are looking for a way to "pause" all of these intervals, due to some issues we're seeing where iOS will force-quit the app in the background (mostly these Watchdog errors).
If I add a simple logging middleware, I can see when a polling API triggers:
const apiLoggerMiddleware: Middleware = () => next => action => {
// Simple logger to show when an API fires, and its corresponding name
if (action.type.startsWith('api/execute')) {
console.log('API Request:', action?.type, action?.meta?.arg?.endpointName);
}
return next(action);
};
When I close the app (swipe up to the home screen and have it enter the background state), the polling continues. This has caused two potential issues:
- High background battery usage, relative to other apps
- iOS eventually kills the app entirely due to it being "active" for over 30 seconds in the background.
Attempted solutions
- Use AppState.currentState in conjunction with the above middleware to abort any request that is attempted while the app is in the background. This caused the internal query cache to eventually go away, which also got rid of any cached session info, thus logging out the user.
- Use
setupListeners
to let the library know when the app is not in focus anymore (see example here: RTK Query: refetchOnFocus is not working for me in a ReactNative app #3652). While that does force a fresh query on focus, it does not suspend the polling while the app is NOT in focus. - Use the abort function on the baseQuery api object to abort requests prior to executing them (again with AppState). This caused the queries to return errors, thus falling back to our error state UI, causing a negative experience.
I have avoided using skip
/ skipToken
, because that's done per subscription (i.e. at the component level), rather than at a level that applies app-wide.
Any suggestions here would be great, this would be really useful for anyone using this with React Native in particular.