Skip to content

Commit

Permalink
fix: Fix create 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 4f47a46
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 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,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) {
Expand Down

0 comments on commit 4f47a46

Please sign in to comment.