mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
fix(middleware): revert devtools extension connector with try-catch (#724)
* fix(middleware): revert devtools extension connector with try-catch * add a test case Co-authored-by: Devansh Jethmalani <devanshj@users.noreply.github.com>
This commit is contained in:
parent
cb99a36c59
commit
5b3b963181
@ -87,16 +87,20 @@ export const devtools =
|
||||
? { name: options }
|
||||
: options
|
||||
|
||||
if (typeof window === 'undefined') {
|
||||
return fn(set, get, api)
|
||||
let extensionConnector
|
||||
try {
|
||||
extensionConnector =
|
||||
(window as any).__REDUX_DEVTOOLS_EXTENSION__ ||
|
||||
(window as any).top.__REDUX_DEVTOOLS_EXTENSION__
|
||||
} catch {
|
||||
// ignored
|
||||
}
|
||||
|
||||
const extensionConnector =
|
||||
(window as any).__REDUX_DEVTOOLS_EXTENSION__ ||
|
||||
(window as any).top.__REDUX_DEVTOOLS_EXTENSION__
|
||||
|
||||
if (!extensionConnector) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
if (
|
||||
process.env.NODE_ENV === 'development' &&
|
||||
typeof window !== 'undefined'
|
||||
) {
|
||||
console.warn(
|
||||
'[zustand devtools middleware] Please install/enable Redux devtools extension'
|
||||
)
|
||||
|
||||
@ -483,6 +483,17 @@ it('works in non-browser env', () => {
|
||||
global.window = originalWindow
|
||||
})
|
||||
|
||||
it('works in react native env', () => {
|
||||
const originalWindow = global.window
|
||||
global.window = {} as any
|
||||
|
||||
expect(() => {
|
||||
create(devtools(() => ({ count: 0 })))
|
||||
}).not.toThrow()
|
||||
|
||||
global.window = originalWindow
|
||||
})
|
||||
|
||||
it('preserves isRecording after setting from devtools', () => {
|
||||
const api = create(devtools(() => ({ count: 0 })))
|
||||
;(extensionSubscriber as (message: any) => void)({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user