Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

produceWithPatches(draft => return anything) does not provide patch output if draft is not an object #888

Closed
3 tasks done
Jimmy89 opened this issue Dec 31, 2021 · 1 comment
Labels

Comments

@Jimmy89
Copy link

Jimmy89 commented Dec 31, 2021

馃悰 Bug Report

In case the draft is a boolean, string, null or number and the draft is overwritten by nothing the patch output of produceWithPatches is undefined.

Based on the output of an object or array the output would, for me, expected to be [{op: 'replace', path: [], value: undefined}].

Issue that might be related to this behavior: Github issue

Update: I also found out that any other boolean, string, null or number combination is not recorded in the patches, e.g. changing "foobar" into "something else" is also not recorded.

Link to repro

var {produceWithPatches, nothing, enablePatches} = require("immer")
enablePatches(true)
let [, patches] = produceWithPatches({abc: 123}, (draft) => nothing)
console.log(patches) // === [{op: 'replace', path: [], value: undefined}]

let [, patches2] = produceWithPatches(null, (draft) => nothing)
console.log(patches2) // !== [{op: 'replace', path: [], value: undefined}]

let [, patches3] = produceWithPatches(0, (draft) => nothing)
console.log(patches3) // !== [{op: 'replace', path: [], value: undefined}]

let [, patches4] = produceWithPatches("foobar", (draft) => nothing)
console.log(patches4) // !== [{op: 'replace', path: [], value: undefined}]

let [, patches5] = produceWithPatches([], (draft) => nothing)
console.log(patches5) // === [{op: 'replace', path: [], value: undefined}]

let [, patches6] = produceWithPatches(false, (draft) => nothing)
console.log(patches6) // !== [{op: 'replace', path: [], value: undefined}]

let [, patches7] = produceWithPatches("foobar", (draft) => "something else")
console.log(patches7) // !== [{op: 'replace', path: [], value: "something else"}]

let [, patches8] = produceWithPatches(false, (draft) => true)
console.log(patches8) // !== [{op: 'replace', path: [], value: true}]

To Reproduce

See code snippet above.

Observed behavior

produceWithPatches second ([1]) output parameter is undefined, in any combination where the original value is not an object.

Expected behavior

Expected output is [{op: 'replace', path: [], value: VALUE}].

Environment

Any browser
Immer: 9.0.7
setUseProxies does not matter.

We only accept bug reports against the latest Immer version.

  • Immer version:
  • I filed this report against the latest version of Immer
  • Occurs with setUseProxies(true)
  • Occurs with setUseProxies(false) (ES5 only)
@Jimmy89 Jimmy89 changed the title produceWithPatches(draft => nothing) does not provide patch output if draft is not an object produceWithPatches(draft => return anything) does not provide patch output if draft is not an object Dec 31, 2021
@github-actions
Copy link
Contributor

馃帀 This issue has been resolved in version 9.0.10 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant