Skip to content

Commit

Permalink
[v5] Remove Devtools warning (#2466)
Browse files Browse the repository at this point in the history
* chore: remove devtools extension warning

* docs: add devtools link to readme

* chore: remove unused test

* chrome: remove unused tests

* chore: remove unused test

* Revert "chore: remove unused test"

This reverts commit 0fa2a75.

* update test name
  • Loading branch information
charkour committed Apr 16, 2024
1 parent 36d4734 commit fe47d3e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 22 deletions.
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ const useGrumpyStore = create(redux(reducer, initialState))
## Redux devtools
Install the [Redux DevTools Chrome extension](https://chromewebstore.google.com/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd) to use the devtools middleware.
```jsx
import { devtools } from 'zustand/middleware'

Expand Down
7 changes: 1 addition & 6 deletions src/middleware/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ const devtoolsImpl: DevtoolsImpl =
}

if (!extensionConnector) {
if (import.meta.env?.MODE !== 'production' && enabled) {
console.warn(
'[zustand devtools middleware] Please install/enable Redux devtools extension',
)
}
return fn(set, get, api)
}

Expand Down Expand Up @@ -269,7 +264,7 @@ const devtoolsImpl: DevtoolsImpl =
if (Object.keys(action.state as S).length !== 1) {
console.error(
`
[zustand devtools middleware] Unsupported __setState action format.
[zustand devtools middleware] Unsupported __setState action format.
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
`,
Expand Down
17 changes: 1 addition & 16 deletions tests/devtools.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,10 @@ describe('If there is no extension installed...', () => {
}).not.toThrow()
})

it('does not warn if not enabled', async () => {
it('does not warn', async () => {
createStore(devtools(() => ({ count: 0 })))
expect(console.warn).not.toBeCalled()
})

it('[DEV-ONLY] warns if enabled in dev mode', async () => {
createStore(devtools(() => ({ count: 0 }), { enabled: true }))
expect(console.warn).toBeCalled()
})

it.skip('[PRD-ONLY] does not warn if not in dev env', async () => {
createStore(devtools(() => ({ count: 0 })))
expect(console.warn).not.toBeCalled()
})

it.skip('[PRD-ONLY] does not warn if not in dev env even if enabled', async () => {
createStore(devtools(() => ({ count: 0 }), { enabled: true }))
expect(console.warn).not.toBeCalled()
})
})

describe('When state changes...', () => {
Expand Down

0 comments on commit fe47d3e

Please sign in to comment.