Skip to content

Commit bbb89b6

Browse files
committed
Add 'skipPollOnFocusLost' flag to query hooks
The query hooks in 'buildHooks.ts' and 'apiState.ts' files now include the 'skipPollOnFocusLost' flag.
1 parent 2fe5915 commit bbb89b6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

packages/toolkit/src/query/core/apiState.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ export type SubscriptionOptions = {
8383
* How frequently to automatically re-fetch data (in milliseconds). Defaults to `0` (off).
8484
*/
8585
pollingInterval?: number
86+
/**
87+
* Defaults to 'false'. This setting allows you to control whether RTK Query will continue polling if the window is not focused.
88+
*
89+
* If pollingInterval is not set or set to 0, this **will not be evaluated** until pollingInterval is greater than 0.
90+
*/
91+
skipPollOnFocusLost?: boolean
8692
/**
8793
* Defaults to `false`. This setting allows you to control whether RTK Query will try to refetch all subscribed queries after regaining a network connection.
8894
*

packages/toolkit/src/query/react/buildHooks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
672672
refetchOnMountOrArgChange,
673673
skip = false,
674674
pollingInterval = 0,
675+
skipPollOnFocusLost = false,
675676
} = {}
676677
) => {
677678
const { initiate } = api.endpoints[name] as ApiEndpointQuery<
@@ -715,6 +716,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
715716
refetchOnReconnect,
716717
refetchOnFocus,
717718
pollingInterval,
719+
skipPollOnFocusLost,
718720
})
719721

720722
const lastRenderHadSubscription = useRef(false)
@@ -815,6 +817,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
815817
refetchOnReconnect,
816818
refetchOnFocus,
817819
pollingInterval = 0,
820+
skipPollOnFocusLost = false,
818821
} = {}) => {
819822
const { initiate } = api.endpoints[name] as ApiEndpointQuery<
820823
QueryDefinition<any, any, any, any, any>,
@@ -829,6 +832,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
829832
refetchOnReconnect,
830833
refetchOnFocus,
831834
pollingInterval,
835+
skipPollOnFocusLost,
832836
})
833837

834838
usePossiblyImmediateEffect(() => {

0 commit comments

Comments
 (0)