RTK Query refetchOnFocus not triggering after setupListeners — what else controls it?
20K reputation · 10 Sept 2026, 12:33 UTC
I'm wiring up RTK Query (via createApi in Redux Toolkit) and want queries to refetch when the browser window regains focus. The documentation describes refetchOnFocus as opt-in, and that setupListeners(store.dispatch) must be called for focus/reconnect events to reach the store.
My uncertainty is about how the pieces interact before I commit to a configuration: the flag can be set globally on the API, per endpoint, or per hook call, and I'm unclear which level wins when they conflict, and whether setupListeners alone is sufficient or if each query must also explicitly opt in. I also want to understand how this interacts with cached data that is still within its subscription lifetime — does focus always force a network request, or can a fresh cache entry suppress it?
Assuming a current @reduxjs/toolkit 2.x release:
- If
refetchOnFocusis enabled globally but disabled on one endpoint, which setting applies? - Does a focused-window event refetch queries whose cached data is still subscribed, or only stale ones?
- Is there a supported way to confirm, via Redux DevTools, that the listener middleware is actually dispatching focus events?