Skip to content

Commit 7e98e1c

Browse files
committed
fix: do not attempt to use global for context sharing
1 parent 20b653f commit 7e98e1c

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/react/QueryClientProvider.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import React from 'react'
22

33
import { QueryClient } from '../core'
44

5-
interface GlobalOrWindow {
6-
ReactQueryClientContext?: React.Context<QueryClient | undefined>
5+
declare global {
6+
interface Window {
7+
ReactQueryClientContext?: React.Context<QueryClient | undefined>
8+
}
79
}
810

911
const defaultContext = React.createContext<QueryClient | undefined>(undefined)
@@ -16,15 +18,12 @@ const defaultContext = React.createContext<QueryClient | undefined>(undefined)
1618
// of module scoping.
1719
function getQueryClientContext() {
1820
// @ts-ignore (for global)
19-
if (typeof global !== 'undefined' || typeof window !== 'undefined') {
20-
// @ts-ignore (for global)
21-
const thisContext = (global || window) as GlobalOrWindow
22-
23-
if (!thisContext.ReactQueryClientContext) {
24-
thisContext.ReactQueryClientContext = defaultContext
21+
if (typeof window !== 'undefined') {
22+
if (!window.ReactQueryClientContext) {
23+
window.ReactQueryClientContext = defaultContext
2524
}
2625

27-
return thisContext.ReactQueryClientContext
26+
return window.ReactQueryClientContext
2827
}
2928

3029
return defaultContext

0 commit comments

Comments
 (0)