Skip to content

Commit

Permalink
fix: Fix create/update metric fragment
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Gudahtt committed Dec 5, 2024
1 parent ceeb5b6 commit f8ff8f7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/scripts/controllers/metametrics-controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
cloneDeep,
isEqual,
memoize,
merge,
Expand Down Expand Up @@ -584,7 +585,9 @@ 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
// @ts-expect-error this is caused by a bug in Immer, not being able to handle recursive types like Json
state.fragments[id] = merge(cloneDeep(additionalFragmentProps), fragment);
});

if (fragment.initialEvent) {
Expand Down

0 comments on commit f8ff8f7

Please sign in to comment.