Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion __tests__/regressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {
original,
isDraft,
immerable,
enableMapSet
enableMapSet,
enablePatches
} from "../src/immer"

enableMapSet()
enablePatches()

runBaseTest("proxy (no freeze)", true, false)
runBaseTest("proxy (autofreeze)", true, true)
Expand Down Expand Up @@ -252,6 +254,26 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) {
})
})

test("#1160 assigning undefined to a key only present on the prototype is still stored as an own property", () => {
const proto = {[immerable]: true, name: undefined}
const state = Object.create(proto)

expect(Object.hasOwnProperty.call(state, "name")).toBe(false)

const [newState, patches] = produceWithPatches(state, draft => {
draft.name = undefined
})

expect(Object.hasOwnProperty.call(newState, "name")).toBe(true)
expect(patches).toEqual([
{
op: "add",
path: ["name"],
value: undefined
}
])
})

test("Nested and chained produce calls throw 'Cannot perform 'get' on a proxy that has been revoked' error", () => {
const state = {
foo: {
Expand Down
2 changes: 1 addition & 1 deletion src/core/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export const objectTraps: ProxyHandler<ProxyState> = {
if (
(state.copy_![prop] === value &&
// special case: handle new props with value 'undefined'
(value !== undefined || prop in state.copy_)) ||
(value !== undefined || has(state.copy_, prop, state.type_))) ||
// special case: NaN
(Number.isNaN(value) && Number.isNaN(state.copy_![prop]))
)
Expand Down
Loading