From f399907a1de87440c61af84e2671761a2338b695 Mon Sep 17 00:00:00 2001 From: Jackson B Date: Sat, 20 Sep 2025 17:54:23 +1000 Subject: [PATCH 1/2] Optimize `isFrozen` utility to handle primitives and null/undefined efficiently. --- src/utils/common.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/utils/common.ts b/src/utils/common.ts index 0ae33ba1..ae066e82 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -198,12 +198,12 @@ export function freeze(obj: T, deep?: boolean): T export function freeze(obj: any, deep: boolean = false): T { if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj if (getArchtype(obj) > 1 /* Map or Set */) { - Object.defineProperties(obj, { - set: {value: dontMutateFrozenCollections as any}, - add: {value: dontMutateFrozenCollections as any}, - clear: {value: dontMutateFrozenCollections as any}, - delete: {value: dontMutateFrozenCollections as any} - }) + Object.defineProperties(obj, { + set: {value: dontMutateFrozenCollections as any}, + add: {value: dontMutateFrozenCollections as any}, + clear: {value: dontMutateFrozenCollections as any}, + delete: {value: dontMutateFrozenCollections as any} + }) } Object.freeze(obj) if (deep) @@ -218,5 +218,8 @@ function dontMutateFrozenCollections() { } export function isFrozen(obj: any): boolean { + // Fast path: primitives and null/undefined are always "frozen" + if (obj === null || typeof obj !== "object") return true + return Object.isFrozen(obj) } From 75541cbe3a94227a39a1a6542628b4ec0efa305d Mon Sep 17 00:00:00 2001 From: Jackson B Date: Sat, 20 Sep 2025 17:59:01 +1000 Subject: [PATCH 2/2] Undo linting change