Skip to content

Commit ca0a9db

Browse files
Stabilize login modal context during dev HMR (#991)
1 parent 8d47532 commit ca0a9db

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/contexts/LoginModalContext.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@ interface LoginModalContextValue {
1010
closeLoginModal: () => void
1111
}
1212

13-
const LoginModalContext = React.createContext<LoginModalContextValue | null>(
14-
null,
15-
)
13+
declare global {
14+
var __tanstackLoginModalContext:
15+
| React.Context<LoginModalContextValue | null>
16+
| undefined
17+
}
18+
19+
const LoginModalContext =
20+
import.meta.env.DEV && typeof window !== 'undefined'
21+
? (globalThis.__tanstackLoginModalContext ??=
22+
React.createContext<LoginModalContextValue | null>(null))
23+
: React.createContext<LoginModalContextValue | null>(null)
1624

1725
export function useLoginModal() {
1826
const context = React.useContext(LoginModalContext)

0 commit comments

Comments
 (0)