Skip to content

Commit 4ae5a9b

Browse files
committed
Polling skipPollOnFocusLost behavior changed to skip if any subscription has the setting and tests changed to better reflect this behavior and intent
1 parent e676ee8 commit 4ae5a9b

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

packages/toolkit/src/query/core/buildMiddleware/polling.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ export const buildPollingHandler: InternalHandlerBuilder = ({
135135
subscribers[key].pollingInterval!,
136136
lowestPollingInterval
137137
)
138-
skipPollOnFocusLost = subscribers[key].skipPollOnFocusLost
138+
skipPollOnFocusLost =
139+
subscribers[key].skipPollOnFocusLost || skipPollOnFocusLost
139140
}
140141
}
141142

packages/toolkit/src/query/tests/polling.test.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ describe('polling tests', () => {
157157
storeRef.store.dispatch(api.util.resetApiState())
158158
})
159159

160-
it('respects skipPollOnFocusLost of the most recent mounted subscription', async () => {
160+
it('respects skipPollOnFocusLost if at least one subscription has it', async () => {
161161
storeRef.store.dispatch(
162162
getPosts.initiate(3, {
163163
subscriptionOptions: {
@@ -169,7 +169,7 @@ describe('polling tests', () => {
169169
)
170170

171171
await delay(50)
172-
const callsWithSkip = mockBaseQuery.mock.calls.length
172+
const callsWithoutSkip = mockBaseQuery.mock.calls.length
173173

174174
storeRef.store.dispatch(
175175
getPosts.initiate(3, {
@@ -178,13 +178,23 @@ describe('polling tests', () => {
178178
})
179179
)
180180

181+
storeRef.store.dispatch(
182+
getPosts.initiate(3, {
183+
subscriptionOptions: {
184+
pollingInterval: 20,
185+
skipPollOnFocusLost: false,
186+
},
187+
subscribe: true,
188+
})
189+
)
190+
181191
storeRef.store.dispatch(api.internalActions?.onFocusLost())
182192

183193
await delay(50)
184-
const callsWithoutSkip = mockBaseQuery.mock.calls.length
194+
const callsWithSkip = mockBaseQuery.mock.calls.length
185195

186-
expect(callsWithSkip).toBeGreaterThan(2)
187-
expect(callsWithoutSkip).toBe(callsWithSkip + 1)
196+
expect(callsWithoutSkip).toBeGreaterThan(2)
197+
expect(callsWithSkip).toBe(callsWithoutSkip + 1)
188198
})
189199

190200
it('replaces skipPollOnFocusLost when the subscription options are updated', async () => {

0 commit comments

Comments
 (0)