Skip to content

Commit 0fac7b2

Browse files
committed
console.warn -> non-production console.error
1 parent a953c70 commit 0fac7b2

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

packages/query-core/src/__tests__/timeoutManager.test.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ describe('timeoutManager', () => {
2121
}
2222
}
2323

24+
let consoleErrorSpy: ReturnType<typeof vi.spyOn>
25+
2426
beforeEach(() => {
25-
vi.spyOn(console, 'warn')
27+
consoleErrorSpy = vi.spyOn(console, 'error')
2628
})
2729

2830
afterEach(() => {
@@ -82,23 +84,23 @@ describe('timeoutManager', () => {
8284
// 1. switching before making any calls does not warn
8385
const customProvider = createMockProvider()
8486
manager.setTimeoutProvider(customProvider)
85-
expect(console.warn).not.toHaveBeenCalled()
87+
expect(consoleErrorSpy).not.toHaveBeenCalled()
8688

8789
// Make a call. The next switch should warn
8890
manager.setTimeout(vi.fn(), 100)
8991

9092
// 2. switching after making a call should warn
9193
const customProvider2 = createMockProvider('custom2')
9294
manager.setTimeoutProvider(customProvider2)
93-
expect(console.warn).toHaveBeenCalledWith(
95+
expect(consoleErrorSpy).toHaveBeenCalledWith(
9496
'[timeoutManager]: Switching to custom2 provider after calls to custom provider might result in unexpected behavior.',
9597
)
9698

9799
// 3. Switching again with no intermediate calls should not warn
98-
vi.mocked(console.warn).mockClear()
100+
vi.mocked(consoleErrorSpy).mockClear()
99101
const customProvider3 = createMockProvider('custom3')
100102
manager.setTimeoutProvider(customProvider3)
101-
expect(console.warn).not.toHaveBeenCalled()
103+
expect(consoleErrorSpy).not.toHaveBeenCalled()
102104
})
103105
})
104106

packages/query-core/src/timeoutManager.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,35 @@ export class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
6868
return
6969
}
7070

71-
if (this.#providerCalled) {
72-
// After changing providers, `clearTimeout` will not work as expected for
73-
// timeouts from the previous provider.
74-
//
75-
// Since they may allocate the same timeout ID, clearTimeout may cancel an
76-
// arbitrary different timeout, or unexpected no-op.
77-
//
78-
// We could protect against this by mixing the timeout ID bits
79-
// deterministically with some per-provider bits.
80-
//
81-
// We could internally queue `setTimeout` calls to `TimeoutManager` until
82-
// some API call to set the initial provider.
83-
console.warn(
84-
`[timeoutManager]: Switching to ${provider.name} provider after calls to ${this.#provider.name} provider might result in unexpected behavior.`,
85-
)
71+
if (process.env.NODE_ENV !== 'production') {
72+
if (this.#providerCalled) {
73+
// After changing providers, `clearTimeout` will not work as expected for
74+
// timeouts from the previous provider.
75+
//
76+
// Since they may allocate the same timeout ID, clearTimeout may cancel an
77+
// arbitrary different timeout, or unexpected no-op.
78+
//
79+
// We could protect against this by mixing the timeout ID bits
80+
// deterministically with some per-provider bits.
81+
//
82+
// We could internally queue `setTimeout` calls to `TimeoutManager` until
83+
// some API call to set the initial provider.
84+
console.error(
85+
`[timeoutManager]: Switching to ${provider.name} provider after calls to ${this.#provider.name} provider might result in unexpected behavior.`,
86+
)
87+
}
8688
}
8789

8890
this.#provider = provider
89-
this.#providerCalled = false
91+
if (process.env.NODE_ENV !== 'production') {
92+
this.#providerCalled = false
93+
}
9094
}
9195

9296
setTimeout(callback: TimeoutCallback, delay: number): ManagedTimerId {
93-
this.#providerCalled = true
97+
if (process.env.NODE_ENV !== 'production') {
98+
this.#providerCalled = true
99+
}
94100
return providerIdToNumber(
95101
this.#provider,
96102
this.#provider.setTimeout(callback, delay),
@@ -102,7 +108,9 @@ export class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
102108
}
103109

104110
setInterval(callback: TimeoutCallback, delay: number): ManagedTimerId {
105-
this.#providerCalled = true
111+
if (process.env.NODE_ENV !== 'production') {
112+
this.#providerCalled = true
113+
}
106114
return providerIdToNumber(
107115
this.#provider,
108116
this.#provider.setInterval(callback, delay),

0 commit comments

Comments
 (0)