-
-
Notifications
You must be signed in to change notification settings - Fork 850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Applying patches returns empty array after update to v1.11.0 #301
Applying patches returns empty array after update to v1.11.0 #301
Comments
Closing issue. I fixed it by returning the new Working example for immer v1.12.0 (in TypeScript): import { produce, applyPatches } from "immer"
let patches = [] as any[]
const state0: { a: number, b?: number } = { a: 1 }
const state1 = produce(state0, (draft) => { draft.b = 9 }, (p) => { patches.push(...p) })
const state2 = produce(state1, (draft) => { draft.a = 3 }, (p) => { patches.push(...p) })
const state3 = produce(state2, (draft) => { draft.b = 99 }, (p) => { patches.push(...p) })
const state4 = produce(state3, (draft) => { draft.a = 5 }, (p) => { patches.push(...p) })
console.log(patches)
// [ { op: 'add', path: [ 'b' ], value: 9 },
// { op: 'replace', path: [ 'a' ], value: 3 },
// { op: 'replace', path: [ 'b' ], value: 99 },
// { op: 'replace', path: [ 'a' ], value: 5 } ]
const state5 = produce(state0,
(draft) => applyPatches(draft, patches),
(p) => { patches = p }
)
console.log(patches)
// [ { op: 'replace', path: [], value: { a: 5, b: 99 } } ]
console.log(state0)
// { a: 1 }
console.log(state4)
// { a: 5, b: 99 }
console.log(state5)
// { a: 5, b: 99 } |
This is an unintended breaking change. Thanks for reporting! 9a2e756 fixed a bug in #282, which is why v1.11.0+ is where this occurs. The I'm going to change |
In v1.12.1, the |
🎉 This issue has been resolved in version 1.12.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Works with immer v1.10.5. Does not work with immer v1.11.0 and v1.12.0.
Code to reproduce (in TypeScript):
Expected behavior: It logs the patches like in the comments.
Observed behavior: The second logged
patches
is an empty array[]
.The text was updated successfully, but these errors were encountered: