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 an empty base object as the merge
target, 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 cbc50c0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/scripts/controllers/metametrics-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ describe('MetaMetricsController', function () {
});

const expectedFragment = merge(
{},
SAMPLE_TX_SUBMITTED_PARTIAL_FRAGMENT,
SAMPLE_PERSISTED_EVENT_NO_ID,
{
Expand Down
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({}, additionalFragmentProps, fragment);
});

if (fragment.initialEvent) {
Expand Down

0 comments on commit cbc50c0

Please sign in to comment.