zustand/middlerware/immer stopped working since v5.0.4 (React Native only) #3211
-
I'm currently getting the following error when using The thrown error is:
I've managed to pin point the issue to v5.0.4, the one that patched the library for react-native It seems that zustand immer doesn't apply the This is a small working demo that works with zustand import { enableMapSet, produce } from "immer";
import { create } from "zustand";
import { immer } from "zustand/middleware/immer";
enableMapSet();
// Test with a simple Map
try {
console.log("Testing with Map...");
const testMap = new Map<string, any>();
testMap.set("test", { value: 1 });
const newMap = produce(testMap, (draft) => {
draft.set("test", { value: 2 });
});
console.log("Map test successful:", newMap.get("test").value === 2);
} catch (error) {
console.error("Map test failed:", error);
}
// Test with Zustand store using Map
try {
console.log("Testing with Zustand store...");
interface TestState {
testMap: Map<string, any>;
updateMap: (key: string, value: any) => void;
}
const useTestStore = create<TestState>()(
immer((set) => ({
testMap: new Map([["initial", { count: 0 }]]),
updateMap: (key, value) =>
set((state) => {
state.testMap.set(key, value);
}),
})),
);
const { updateMap } = useTestStore.getState();
updateMap("test", { count: 5 });
console.log(
"Zustand test successful:",
useTestStore.getState().testMap.get("test").count === 5,
);
} catch (error) {
console.error("Zustand test failed:", error);
}
console.log("===== IMMER TEST COMPLETED ====="); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Thanks for reporting. So, #3087 changed the behavior according to your investigation. |
Beta Was this translation helpful? Give feedback.
-
Yes
…On Fri, 15 Aug 2025, 1:21 pm gabimoncha, ***@***.***> wrote:
thanks a ton @dai-shi <https://github.com/dai-shi>. You are right, their
package.json config was incorrect.
i removed the react-native line and changed the exports to this and now
it works. Will patch the lib for now and make a PR for immer
"exports": {
"./package.json": "./package.json",
".": {
"react-native": {
"types": "./dist/immer.d.ts",
"default": "./dist/immer.legacy-esm.js"
},
"import": {
"types": "./dist/immer.d.ts",
"default": "./dist/immer.mjs"
},
"require": {
"types": "./dist/immer.d.ts",
"default": "./dist/cjs/index.js"
}
}
},
—
Reply to this email directly, view it on GitHub
<#3211 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BUF75NVDXZO4I7KUKTYE4OD3NWYDFAVCNFSM6AAAAACD4RKPOKVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTIMJRGUYDGMQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
thanks a ton @dai-shi. You are right, their package.json config was incorrect.
i removed the
react-native
line and changed the exports to this and now it works. Will patch the lib for now and make a PR for immer