Skip to content

import createStore from zustand/vanilla - #219

Open
micmcg wants to merge 2 commits into
charkour:mainfrom
micmcg:import-createstore-from-zustand-vanilla
Open

micmcg wants to merge 2 commits into
charkour:mainfrom
micmcg:import-createstore-from-zustand-vanilla

Conversation

@micmcg

@micmcg micmcg commented Oct 21, 2026 •

Copy link
Copy Markdown

Importing zundo no longer loads React with this change. zundo uses createStore only to build the store that holds the undo history (store.temporal), and this PR imports it from zustand/vanilla instead of the zustand root.

In zustand 5, the root entry also re-exports zustand/react, which imports react. So a project that uses zundo only with a vanilla store still loads React. If React is not installed, importing zundo fails:

mkdir repro && cd repro && npm init -y
npm i zundo@2.3.0 zustand@5
node -e "import('zundo')"
# Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'react' imported from .../zustand/esm/react.mjs

require('zundo') fails the same way. With this branch, both load.

#98 made the same change in 2023. It was closed with "Actual issue fixed in #99", and its description said the bundle got bigger. I rebuilt #98 and the commit it was based on with the tools of that time (tsup 6.7.0, size-limit 8.2.4, zustand 4.3.8). The repo's size check (pnpm size) went from 860 B to 866 B. Neither build includes zustand's code, so the 6 bytes are the longer import path. Today pnpm size goes from 628 B to 634 B. I also bundled a small app that uses zundo with a vanilla store. Minified and gzipped, it is 708 B before and after this change. Without React installed, the app fails to build before this change and builds after it.

The second commit removes zustand 4.0.0 and 4.2.0 from the CI matrix, with the tsup patch step that ran only for 4.0.0. Before 4.3.0, zustand/vanilla exports createStore only as a default export, so the build and tests fail on those two versions. Both are below the peer range (^4.3.0 || ^5.0.0), and every release in that range exports the named createStore from zustand/vanilla. The commit is separate so you can drop it. If you want to keep support for zustand below 4.3.0, I can follow up with an import that falls back to the default export.

To test, run pnpm build && pnpm test:ci. Then run the repro above with the built package (npm pack, and install the tarball in place of zundo@2.3.0).

The zustand root entry also loads zustand's React hooks. With zustand 5
and no React installed, importing zundo in Node fails with "Cannot find
module 'react'". zundo only needs the vanilla store, so import it from
zustand/vanilla.
Both versions are below the peer range (^4.3.0 || ^5.0.0). Before 4.3.0,
zustand/vanilla exports createStore only as a default export, so the
build and tests fail on them after the previous commit. The tsup patch
step ran only for 4.0.0, so it goes too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant