From 4f47a46d139a2bc1448141efb8a85cbb1e2e5385 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Thu, 5 Dec 2024 14:46:44 -0330 Subject: [PATCH] fix: Fix create metric fragment The function `createEventFragment` of the `MetaMetricsController` was broken recently in the migration to BaseControllerV2 (#28113). We ended up trying to mutate a piece of Immer state, resulting in an error. The affected line was updated to use `cloneDeep` prior to mutating, so that we're no longer attempting to mutate a frozen object. Fixes ##28599 --- app/scripts/controllers/metametrics-controller.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/scripts/controllers/metametrics-controller.ts b/app/scripts/controllers/metametrics-controller.ts index e286a3a47d02..f82d79d66680 100644 --- a/app/scripts/controllers/metametrics-controller.ts +++ b/app/scripts/controllers/metametrics-controller.ts @@ -1,4 +1,5 @@ import { + cloneDeep, isEqual, memoize, merge, @@ -584,7 +585,8 @@ export default class MetaMetricsController extends BaseController< : {}; this.update((state) => { - state.fragments[id] = merge(additionalFragmentProps, fragment); + // We're cloning "additionalFragmentProps" because it can contain a frozen piece of Immer state + state.fragments[id] = merge(cloneDeep(additionalFragmentProps), fragment); }); if (fragment.initialEvent) {