From 9fc3818856e3281243eacec90c5a2057fcd2916a Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Thu, 19 May 2022 17:39:36 -0400 Subject: [PATCH] Avoid using Object.isFrozen to prevent dev/prod differences. If you revert the previous commit and run `npm test`, you'll see all the tests this dynamic Object.isFrozen check has been silently protecting from failing, but only (and this is the important part) in development. Since we only actually freeze objects with Object.freeze in development, this Object.isFrozen check does not help in production, so an object that would have been frozen in development gets reused as a mutable copy, potentially acquiring properties it should not acquire (a bug fixed by the previous commit, first reported in issue #9735). --- src/utilities/common/mergeDeep.ts | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/utilities/common/mergeDeep.ts b/src/utilities/common/mergeDeep.ts index c65405274e6..22db21e4540 100644 --- a/src/utilities/common/mergeDeep.ts +++ b/src/utilities/common/mergeDeep.ts @@ -101,21 +101,17 @@ export class DeepMerger { public shallowCopyForMerge(value: T): T { if (isNonNullObject(value)) { - if (this.pastCopies.has(value)) { - // In order to reuse a past copy, it must be mutable, but copied objects - // can sometimes be frozen while this DeepMerger is still active. - if (!Object.isFrozen(value)) return value; - this.pastCopies.delete(value); - } - if (Array.isArray(value)) { - value = (value as any).slice(0); - } else { - value = { - __proto__: Object.getPrototypeOf(value), - ...value, - }; + if (!this.pastCopies.has(value)) { + if (Array.isArray(value)) { + value = (value as any).slice(0); + } else { + value = { + __proto__: Object.getPrototypeOf(value), + ...value, + }; + } + this.pastCopies.add(value); } - this.pastCopies.add(value); } return value; }