Skip to content

Commit cd8a93b

Browse files
committed
map context instances using createContext as key
1 parent 2210db9 commit cd8a93b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/components/Context.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createContext, version as ReactVersion } from 'react'
1+
import { createContext } from 'react'
22
import type { Context } from 'react'
33
import type { Action, AnyAction, Store } from 'redux'
44
import type { Subscription } from '../utils/Subscription'
@@ -15,17 +15,20 @@ export interface ReactReduxContextValue<
1515
noopCheck: CheckFrequency
1616
}
1717

18-
const ContextKey = Symbol.for(`react-redux-context-${ReactVersion}`)
19-
const gT = globalThis as { [ContextKey]?: Context<ReactReduxContextValue> }
18+
const ContextKey = Symbol.for(`react-redux-context`)
19+
const gT = globalThis as {
20+
[ContextKey]?: Map<typeof createContext, Context<ReactReduxContextValue>>
21+
}
2022

2123
function getContext() {
22-
let realContext = gT[ContextKey]
24+
const contextMap = (gT[ContextKey] ??= new Map())
25+
let realContext = contextMap.get(createContext)
2326
if (!realContext) {
2427
realContext = createContext<ReactReduxContextValue>(null as any)
2528
if (process.env.NODE_ENV !== 'production') {
2629
realContext.displayName = 'ReactRedux'
2730
}
28-
gT[ContextKey] = realContext
31+
contextMap.set(createContext, realContext)
2932
}
3033
return realContext
3134
}

0 commit comments

Comments
 (0)