Repository: immerjs/immer

Issue:
Object values of a `Map` are not frozen anymore
## 🐛 Bug Report

Starting with Immer 10.0.4, `enableMapSet()` does not seem to work as expected as values (if objects) of a native `Map` aren't frozen anymore.

## Link to repro

https://stackblitz.com/edit/immer-10-0-4-map-bug

## To Reproduce

Create a Map with objects by using `produce` and check the values of the Map with `Object.isFrozen(...)`.

## Observed behavior

Objects inside a Map are not frozen.

## Expected behavior

Objects inside a Map are frozen. The provided repo works if the Immer version is set to 10.0.3.

## Environment

- **Immer version:** 10.0.4
- [x] I filed this report against the _latest_ version of Immer


Hints from issue comments:
@mweststrate: Note to self, see also #1069 @mweststrate: Thanks for the detailed report, will investigate at a later point. @github-actions: :tada: This issue has been resolved in version 10.1.2 :tada:

The release is available on:
- [npm package (@latest dist-tag)](https://www.npmjs.com/package/immer/v/10.1.2)
- [GitHub release](https://github.com/immerjs/immer/releases/tag/v10.1.2)

Your **[semantic-release](https://github.com/semantic-release/semantic-release)** bot :package::rocket:

Solution patch:
diff --git a/src/core/finalize.ts b/src/core/finalize.ts
index 6ee69ce..bf1ac74 100644
--- a/src/core/finalize.ts
+++ b/src/core/finalize.ts
@@ -15,7 +15,8 @@ import {
 	getPlugin,
 	die,
 	revokeScope,
-	isFrozen
+	isFrozen,
+	isMap
 } from "../internal"
 
 export function processResult(result: any, scope: ImmerScope) {
@@ -151,7 +152,9 @@ function finalizeProperty(
 		if (
 			(!parentState || !parentState.scope_.parent_) &&
 			typeof prop !== "symbol" &&
-			Object.prototype.propertyIsEnumerable.call(targetObject, prop)
+			(isMap(targetObject)
+				? targetObject.has(prop)
+				: Object.prototype.propertyIsEnumerable.call(targetObject, prop))
 		)
 			maybeFreeze(rootScope, childValue)
 	}
diff --git a/website/docs/update-patterns.md b/website/docs/update-patterns.md
index a239ff1..5241593 100644
--- a/website/docs/update-patterns.md
+++ b/website/docs/update-patterns.md
@@ -137,7 +137,7 @@ const nextStore = produce(store, draft => {
 	const user = draft.users.get("17")
 	// when filtering, creating a fresh collection is simpler than
 	// removing irrelevant items
-	user.todos = user.todos.filter(todo => todo.done)
+	user.todos = user.todos.filter(todo => !todo.done)
 })
 ```
 



Test patch:
diff --git a/__tests__/frozen.js b/__tests__/frozen.js
index f130f3c..3a6d8bc 100644
--- a/__tests__/frozen.js
+++ b/__tests__/frozen.js
@@ -147,10 +147,12 @@ function runTests(name) {
 
 			const res = produce(base, draft => {
 				draft.set("a", 1)
+				draft.set("o", {b: 1})
 			})
 			expect(() => res.set("b", 2)).toThrowErrorMatchingSnapshot()
 			expect(() => res.clear()).toThrowErrorMatchingSnapshot()
 			expect(() => res.delete("b")).toThrowErrorMatchingSnapshot()
+			expect(Object.isFrozen(res.get("o"))).toBe(true)
 
 			// In draft, still editable
 			expect(produce(res, d => void d.set("a", 2))).not.toBe(res)