173 Commits

Author SHA1 Message Date
thomas
d25a4d226f
docs and tests: filter out specific actions from being sent to Redux DevTools (#3252)
* feat:   filter out specific actions from being sent to Redux DevTools

* fix format issues

* refactor: rename actionBlacklist to actionsDenylist

* refactor: use redux devtools' type signature

* fix linter issue

* fix format issues

* refactor: update documentation

* refactor: format file

* Update src/middleware/devtools.ts

* fix: format issue

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
2025-10-31 13:19:11 +09:00
Daishi Kato
ab5a98b187
test: fix for node 24 (#3278) 2025-10-31 13:17:00 +09:00
Daishi Kato
feddc0c210
feat(middleare/persist): return storage promise from setState (#3206)
* feat(middleare/persist): return storage promise from setState

* refactor types (technically breaking)

* another breaking change in types

* make public types not breaking
2025-08-20 08:08:35 +09:00
Daishi Kato
2cc19881fa
fix(shallow): undefined value (#3205)
* add failing test

* check with .has
2025-08-20 07:52:06 +09:00
Wonsuk Choi
295bf970a3
test(*): add 'expect' with 'toBeInTheDocument' (#3162)
* test(*): add 'expect' with 'toBeInTheDocument'

* chore(eslint.config): enable 'vitest/expect-expect' rule
2025-06-29 11:49:16 +09:00
Noritaka Kobayashi
73b91d3700
refactor: remove unused import in example & fix typo in tests (#3161) 2025-06-28 22:44:50 +09:00
Wonsuk Choi
a6143e0f23
test(shallow): update 'shallow' and 'useShallow' imports to use 'zustand/shallow' (#3157) 2025-06-19 18:44:01 +09:00
clonemycode
9d58820318
chore: fix some typos in comment (#3139)
Signed-off-by: clonemycode <clonecode@aliyun.com>
2025-06-03 10:05:54 +09:00
Wonsuk Choi
a03acc3887
test(vanilla/subscribe): add test for covering fireImmediately option in 'subscribeWithSelector' (#3131) 2025-05-22 12:58:34 +09:00
Wonsuk Choi
ad32cdf7a0
test(vanilla/basic): add test for 'getInitialState' (#3130)
* test(vanilla/basic): add test for 'getInitialState'

* Update tests/vanilla/basic.test.ts

* Update tests/vanilla/basic.test.ts

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
2025-05-21 20:22:09 +09:00
Ali Mert Çakar
670b60e19a
feat(devtool): inferred action type (#2987)
* feat(devtools middleware) add automatic action name finding

* docs(readme) add inferActionName example

* feat: update readmes

* feat: update devtools middleware and tests

* feat: remove inferActionName

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
Co-authored-by: Danilo Britto <dbritto.dev@gmail.com>
2025-05-21 20:12:14 +09:00
Wonsuk Choi
6953c29dc5
test(vanilla/shallow): add test for pure iterable with different values returns false (#3129) 2025-05-21 11:41:09 +09:00
Hong-Kuan Wu
b4177b3172
feat: add devtools.cleanup() method (#3111)
* feat(devtools): add cleanup method

* docs(devtools): add cleanup section

* reduce lines

* test(devtools): test if the connection removed after cleanup

---------

Co-authored-by: daishi <daishi@axlight.com>
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
2025-05-21 09:49:59 +09:00
Danilo Britto
a56a3e4bde
feat(vanilla): update shallow compare function and tests (#3108)
* feat(vanilla): update shallow compare function and tests

* prefer Object.getPrototypeOf

* docs: update shallow docs

* feat: minor fixes

---------

Co-authored-by: daishi <daishi@axlight.com>
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
2025-05-21 09:46:37 +09:00
Wonsuk Choi
9a58ca9c95
chore(eslint): update to 'eslint-plugin-react-hooks@6.0.0-rc.1', remove 'eslint-plugin-react-compiler' (#3122) 2025-05-17 14:13:12 +09:00
Danilo Britto
9bae06922a
fix(persist): fix async migrate on persist middleware (#2877)
* fix(perist): add support for async migrate on persist middleware

* feat(vitest): rename vitest.config.ts to vitest.config.mts

* fix: fix minor issues

* fix: fix minor issues

* feat: minor changes

* feat: revert vitest changes

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
2024-12-04 22:06:36 +09:00
Andy Zhou
af7ff21190
fix(middleware): devtools type error #2700 (#2875)
* fix: add an inferred generic U to CreateStoreImpl

* fix: add inferred generic U variables to both Devtools and DevtoolsImpl

* test: add tests for issue #2700

* revert impl types

* code styling

---------

Co-authored-by: daishi <daishi@axlight.com>
2024-12-04 22:00:01 +09:00
Marcin Kulpa
5a8842fbc3
test: add jest-dom matchers and eslint plugin (#2850) 2024-11-13 11:06:56 +09:00
Marcin Kulpa
8b9c374565
test: use @vitest/eslint-plugin (#2845) 2024-11-10 10:27:01 +09:00
Marcin Kulpa
f689d78a31
test: incorporate eslint-plugin-testing-library and fix reported issues (#2844) 2024-11-09 09:46:15 +09:00
Marcin Kulpa
dcc4c098ab
test: use screen exposed by React Testing Library (#2832) 2024-11-04 13:17:52 +09:00
Daishi Kato
9525f9264d
fix(shallow): iterable-like insensitive keys order comparison (alternate implementation) (#2821)
* alternate implementation for shallow

* test with pure iterable

* refactor

* another refactor

---------

Co-authored-by: Danilo Britto <dbritto.dev@gmail.com>
2024-10-30 20:52:43 +09:00
Daishi Kato
259c19ff2d
fix(shallow): fallback map-like iterator comparison (#2795)
* add failing test

* add a fallback
2024-10-27 16:38:59 +09:00
Daishi Kato
88ee69f3e1
chore: enable isolatedDeclarations (#2738) 2024-09-15 11:13:40 +09:00
Christian van der Loo
d7345da7cf
Fix Immer type inference for setState (#2696)
* fix(immer): tweak type inference to base `setState` type off of store `setState` instead of `getState`

* fix(immer): instead, infer type directly from StoreApi<T>["setState"]

* fix(immer): instead of using `StoreApi`, extract from A2 the non-functional component of state

* docs: add comment describing why it is not derived from `A1`

* test: add example middleware that modifies getState w/o setState

* fix: add assertion for inner `set` and `get` types

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
2024-08-27 10:10:47 +09:00
Daishi Kato
e247220ece
v5 (#2138)
* prepare for the next major version

* [v5] breaking: drop default exports (#2238)

* fix: drop default exports for v5

* chore: remove default from cjs build

* refactor: export shallow in v5

* fix: remove `addModuleExport` option for cjs.

* [v5] breaking: drop deprecated features (#2235)

* fix: remove deprecated v4 features

* chore(build): remove context

* docs(typescript): remove deprecated equals api

* docs(persist): remove old persist api

* chore: run yarn prettier on typescript docs

* Discard changes to docs/guides/typescript.md

* Discard changes to docs/integrations/persisting-store-data.md

* Discard changes to tests/shallow.test.tsx

* Discard changes to tests/vanilla/subscribe.test.tsx

* [v5] breaking: make React 18 as minimal requirement (#2236)

* fix: update package.json to require react 18+

* chore: update github actions to test on react 18+

* chore: remove devtools-skip hack from actions

* chore(test): remove CI-SKIP from devtools tests

* [v5] breaking: make use-sync-external-store an optional peer dependency (#2237)

* chore: make use-sync-external-store optional peerDep

* fix: use correct versions in package.json

* [v5] breaking: require TypeScript 4.5 and update tests (#2257)

* breaking(types): TS requirement

* wip: latest only

* wip: latest only 2

* drop ts <4.4

* wip: do not skip lib checkes

* use latest node types

* drop ts 4.4

* [v5]: drop "module" condition  (#2270)

* Update package json in order to remove module

* Update rollup config in order to remove module config

* Update patch esm script

* Update package json to general exports and update node version (#2272)

* [v5]: drop UMD/SystemJS builds (#2287)

* Update rollup config in order to drop system js and umd builds

* Update packages

* Clean up files

* Update rollup config

* Update gh workflows

* Minor fixes

* Minor fixes

* Minor fixes

* Minor fixes

* Testing

* Minor changes

* Minor fixes

* remove `WithReact` type (#2300)

* 5.0.0-alpha.0

* [v5]: do not depend on use-sync-external-store (#2301)

* [v5]: do not depend on use-sync-external-store

* memo get(server)snapshot

* 5.0.0-alpha.1

* [v5]: refactor useMemoSelector (#2302)

* [v5]: refactor useMemoSelector

* add a test

* Revert "[v5]: refactor useMemoSelector"

This reverts commit b3c8b15586a270d12c335e566975021adf86c815.

* Revert "Revert "[v5]: refactor useMemoSelector""

This reverts commit 3c47301d23e18dffb7d72df36595f83570d15d08.

* [v5]: separate react entry point (#2303)

* 5.0.0-alpha.2

* 5.0.0-alpha.3

* refactor: Switch to Object.hasOwn (#2365)

* [v5] drop es5 (#2380)

* update yarn lock

* 5.0.0-alpha.4

* [v5]: follow React "standard" way with breaking behavioral change (#2395)

* [v5]: follow React "standard" way with breaking behavioral change

* add test

* 5.0.0-alpha.5

* [v5] Rewrite shallow to support iterables (#2427)

* [v5] fix rollup config for cjs (#2433)

* 5.0.0-alpha.6

* no production build test

* recover types that are dropped in #2462

* remove unused replacement

* [v5] Remove Devtools warning (#2466)

* 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 0fa2a75f4936d960f703bf19e8f3505962cd628e.

* update test name

* update pnpm lock

* fix merge main

* add migration guide

* fix typos

* 5.0.0-beta.0

* update migration doc

* fix merge main

* fix merge main (prettier)

* 5.0.0-beta.1

* fix(types)!: require complete state if `setState`'s `replace` flag is set (#2580)

* fix(types): require complete state if `setState`'s `replace` flag is set

* switch to variant 2

* fix type errors

* update setState types for devtools and immer

* make devtools setState non-generic

* add migration guide

* merge migration guides

* run prettier

* Update tests/middlewareTypes.test.tsx

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
Co-authored-by: daishi <daishi@axlight.com>

* 5.0.0-beta.2

* move v5 migration doc

* fix ci

* missing commmit

* remove unused rule exclusion

* comment about react compiler

* revert eslint config

---------

Co-authored-by: Charles Kornoelje <33156025+charkour@users.noreply.github.com>
Co-authored-by: Danilo Britto <dbritto.dev@gmail.com>
Co-authored-by: Ekin Dursun <ekindursun@gmail.com>
Co-authored-by: Simon Farshid <simon.farshid@outlook.com>
2024-08-16 09:41:00 +09:00
Daishi Kato
a00f3fa1ff
chore(deps): update dependencies (#2680) 2024-08-15 11:13:14 +09:00
Double Thinker
dad36416dc
fix(storage): avoid calling setItem with the state just retrieved (#2678) 2024-08-15 10:50:06 +09:00
Daishi Kato
66f3a029fb
chore: enable verbatimModuleSyntax in tsconfig (#2649) 2024-07-20 17:15:21 +09:00
Daishi Kato
d57072caf5
update vitest (#2462)
* update vitest

* use resolve

* patch for older ts

* for older ts

* hack with any

* for other builds

* wip: for umd

* Revert "wip: for umd"

This reverts commit a5c0d6beaa80cbbdcad7961b77d593effd6a83c8.

* wip: esm

* wip: system

* Revert "wip: system"

This reverts commit aa919631a94a5b321fa9f2ec6c26b826c37ca3b0.

* wip: umd

* wip: hack cjs

* system cannot be tested
2024-04-06 20:48:21 +09:00
Daishi Kato
c092d76260
chore(tests): suppress expected warnings (#2398) 2024-03-09 08:51:05 +09:00
Dominik Dorfmeister
740033cf31
feat: getInitialState (#2277)
* feat(react): implement getServerState by closing over the defaultState

serverState will be used by react on the first client render; this should avoid hydration mismatches when combined with the persist middleware, which can change the state between the SSR and the first CSR

* define getServerState in vanilla.ts

* feat: implement getServerResult in persist middleware

this avoids hydration errors when state is restored from e.g. localstorage synchronously

* feat: capture initialState for getServerState in react

this avoids hydration mismatches when updates happen to the store state between ssr and csr

* refactor: revert changes to oldImpl

* fix: make selector default to identity function

if we default to `api.getState`, we will always read the client snapshot if there is no selector passed. An identity function returns its argument, which is either the snapshot (api.getState) or the server snapshot (api.getServerState)

* define getInitialState in vanilla

* revert WithReact

* fix them

* fix test

* oops, fix another test too

* forgot to use identity

* test: add a test for hydration errors

* fix(readme): imply getInitialState is a public api

---------

Co-authored-by: daishi <daishi@axlight.com>
2024-01-20 09:05:58 +09:00
Charles Kornoelje
9baf0a5d38
chore(test): stop testing deprecated features and test subscribe in vanilla (#2244)
* chore(test): update test to stop testing deprecated features

* chore(test): add subscribe test for zustand/vanilla

* chore(test): only verify that subscribe exists on `create`

* chore(test): switch type of test
2023-12-13 00:46:50 +09:00
wulimao49
949b505a4b
fix(vanilla): unexpected null state update behavior (#2213)
* fix: unexpected null state update behavior

* chore: lint code

* test: add test for setting state to null

---------

Co-authored-by: wulimao <tao@trlab.com>
2023-11-27 18:35:14 +09:00
Daishi Kato
9857a676a9
refactor: revisit prettier config to be minimal (#2193) 2023-11-14 12:19:51 +09:00
Danilo Britto
e414f7ccf4
fix(shallow): Extract shallow vanilla and react (#2097)
* Update readmes

* Splitting shallow in two modules

* Update tests

* Minor changes

* Minor changes

* Rename shadow.tests.tsx to shallow.test.tsx

* Add new entrypoint for shallow/react

* Update structure

* Update shallow to export from vanilla and react

* Add vanilla/shallow and react/shallow entrypoints

* Update tests

* Update readmes

* Update src/shallow.ts

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>

* Minor changes

* Update readmes

* Update readmes

* Update tests

* Minor changes

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
2023-10-05 23:04:56 +09:00
Daishi Kato
0504d4376a
chore(deps): update dev dependencies (#2093)
* chore(deps): update dev dependencies

* run prettier

* fix tsconfig

* fix workflow file
2023-10-02 22:28:51 +09:00
Fabrizio Vitale
3cbd468fe5
feat: add useShallow (#2090)
* feat: add useShallow

See
- https://github.com/pmndrs/zustand/discussions/1937
- https://github.com/pmndrs/zustand/discussions/1937#discussioncomment-7118242
- https://github.com/pmndrs/zustand/discussions/1937#discussioncomment-6974554

* chore(useShallow): improve unit tests

* chore(useShallow): PR feedback https://github.com/pmndrs/zustand/pull/2090#discussion_r1341963105

* fix(useShallow): tests not working on test_matrix (cjs, production, CI-MATRIX-NOSKIP)

* chore(useShallow): fix eslint warning issue (unused import)

* refactor(useShallow): simplify tests

* docs(useShallow): add guide

* fix(useShallow): prettier:ci error https://github.com/pmndrs/zustand/actions/runs/6369420511/job/17289749161?pr=2090

* docs(useShallow): update readme

* docs(useShallow): remove obsolete line from readme

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>

* doc(useShallow): PR feedback https://github.com/pmndrs/zustand/pull/2090#discussion_r1342120701

* docs(useShallow): small improvements of the useShallow guide

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
2023-10-02 22:13:13 +09:00
JiWon Kim
1e846b39b1
test(ssr): Validate state synchronization between server and client in React 18 using Zustand (#903) (#2088)
* test(ssr): Validate state synchronization between server and client in React 18 using Zustand (#903)

* test(ssr): dynamically import hydrateRoot for React 18 and skip if version < 18

* test(ssr): implement conditional describe based on React version

* test(ssr): Refactor SSR code using skipIf and importActual

* test(ssr): Refactor code using 'importActual' with a more specific type for 'hydrateRoot'

* test(ssr): remove async from the main test function

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
2023-10-02 22:08:18 +09:00
Daishi Kato
5777a65cf5
chore(deps): update dev dependencies (#1965) 2023-08-01 10:42:18 +09:00
Daishi Kato
c6900a4562
feat: deprecate equalityFn and add createWithEqualityFn (#1945)
* feat: deprecate equalityFn and add createWithEqualityFn

* add link to deprecation message
2023-08-01 10:15:09 +09:00
Arjun Vegda
496a466c2c
chore(tests): migrate to vitest (#1753)
* test: migrate to vitest

* test: try #1 remove CI-MATRIX tags

* test: try 2 remove import/require replace

* chore: remove unused scripts/assignments

* chore(test-multiple-builds.yml): remove import/require replace script

* fix merging main

---------

Co-authored-by: daishi <daishi@axlight.com>
2023-05-04 13:25:24 +09:00
Laurenz Honauer
630ba1a3e4
feat(middleware/persist): improve createJSONStorage for Maps (#1763)
* feat: add support for Maps to persist middleware

* refactor: change createJsonStorage to accept custom reviver/replacer

* refactor: map support code review
2023-05-04 12:55:59 +09:00
Daishi Kato
f37530fc3d
chore: add extentsion in imports (#1678)
* chore: add extentsion in imports

* fix github workflow

* revert for zustand/context

* do not patch :)

* fix workflow file

* update ts 5

* patch tsconfig

* use old typescript for react 16

* downlevel-dts to 3.8

* Revert "downlevel-dts to 3.8"

This reverts commit d03e5266e14146ed4a7c92e8a5cd2cb295727f69.

* patch workflow file

* patch for react 16

* remove ts3.4 in workflow

* skipLibChecks

* revert changes in test-multiple-versions.yml

* fix sed

* wip: add allowJs

* Revert "wip: add allowJs"

This reverts commit fca34d7d2decc1e469a733224f7680ab37792dc8.

* use ts 495

* useESM false

* Revert "useESM false"

This reverts commit 07a91d8acb14bc5839013aad47d0606dec312d62.

* no coverage

* no coverage 2

* no coverage 3

* wip

* disable transform

* revert a change

* revert changes

* test: try ignoring tests with dynamic imports

* test: skip tests that require/tests modules in isolation

* test: remove dynamic import

* run skipped tests on CI

* test: add new devtools imports to ci-only tests

* revert CI-ONLY-* hack

* wip: workaround for react 16

* wip: workaround for react 16

* wip: workaround for react 16

* wip: workaround for react 16

* wip: workaround for react 16

* wip: workaround for react 16

* wip: workaround for react 16

* wip: workaround for react 16

* wip: workaround for react 16

* wip: workaround for react 16

* wip: workaround for react 16

* CI-MATRIX- for devtools CI hacks

* test: add env variable to test multiple builds workflow

* hack await import

* hack await import for another one

* wip: experimenting workflow file

* wip: experimenting workflow file

* wip: experimenting workflow file

* use different env name

* wip: experimenting workflow file

* do not use two envs

* revert to NODE_ENV

---------

Co-authored-by: Arjun <14841132+arjunvegda@users.noreply.github.com>
2023-05-02 06:28:46 +09:00
coffeebeats
f54469551f
fix(middleware/persist): ensure argument for onRehydrateStorage and onHydrate is defined on first hydration (#1692)
* add tests ensuring that onRehydrateStorage is always passed the latest state

* fix persist to always pass latest state to onRehydrateStorage and onHydrate listeners

* document that tests for onHydrate during first hydration are not possible

* ensure state updates during onHydrate are reflected in onRehydrateStorage callback

* undo modifications to persist's old implementation
2023-03-31 22:11:17 +09:00
coffeebeats
309c672fb7
fix(middleware/persist): ensure persist does not drop updates in onRehydrateStorage when using a synchronous storage API (#1689)
* document a potential issue with stale state being passed to 'onRehydrateStorage'

* fix an issue where state updates during 'onRehydrateStorage' were overwritten with sync storage reads

* add tests ensuring updates during the 'onRehydrateStorage' hook are handled correctly

* Update tests/persistSync.test.tsx

* Apply suggestions from code review

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
2023-03-31 22:06:38 +09:00
George Manning
38c905564c
feat(middleware/persist): add skip hydration option #405 (#1647)
* add manual hydration option to persist middleware

* rename variable, update jsdoc, remove from oldImpl

* add tests for persist skipHydration

* add docs

* Update docs/integrations/persisting-store-data.md

Co-authored-by: Blazej Sewera <code@sewera.dev>

* Update docs/integrations/persisting-store-data.md

Co-authored-by: Blazej Sewera <code@sewera.dev>

* Update src/middleware/persist.ts

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
Co-authored-by: Blazej Sewera <code@sewera.dev>
2023-03-31 20:20:16 +09:00
Luke Murray
4517fed815
fix(react, types): relax react types (#1589)
* relax react types

* make react types more flexible
2023-03-06 13:59:47 +09:00
Daishi Kato
9062ca634f
chore: remove __DEV__ with ts-jest (#1598)
* wip: use ts-jest instead of swc/jest

* use esm in jest

* remove types/jest

* remove __DEV__

* fix rollup config

* fix github workflow

* hack jest.Mock

* wip: ts

* skipLibCheck for older ts 2

* wip: ts

* wip: workflow...

* wip: workflow...

* wip: workflow...

* experiment...

* experiment...2

* experiment...3

* experiment...4

* jest preset
2023-02-10 19:05:12 +09:00
Daishi Kato
a5a8f28999
fix(middleware/persist): hydrate in sync (new impl with storage option) (#1518)
* fix tests to use storage option

* fix the impl
2023-01-10 18:32:06 +09:00