Skip to content

Commit 48b371c

Browse files
committed
fix: comparison typo
This bug prevented Immer from _not_ generating a "replace" patch when the new value is identical to the old value.
1 parent 551d877 commit 48b371c

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

__tests__/patch.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ describe("same value replacement - 2", () => {
292292
d.x = 4
293293
d.x = a
294294
},
295-
// immer does not detect this is not an actual change
296-
[{op: "replace", path: ["x"], value: {y: 3}}]
295+
[]
297296
)
298297
})
299298

@@ -314,8 +313,7 @@ describe("same value replacement - 4", () => {
314313
d.x = 4
315314
d.x = 3
316315
},
317-
// immer does not detect this is not an actual change
318-
[{op: "replace", path: ["x"], value: 3}]
316+
[]
319317
)
320318
})
321319

src/patches.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function generateObjectPatches(state, basePath, patches, inversePatches) {
5858
const origValue = base[key]
5959
const value = copy[key]
6060
const op = !assignedValue ? "remove" : key in base ? "replace" : "add"
61-
if (origValue === base && op === "replace") return
61+
if (origValue === value && op === "replace") return
6262
const path = basePath.concat(key)
6363
patches.push(op === "remove" ? {op, path} : {op, path, value})
6464
inversePatches.push(

0 commit comments

Comments
 (0)