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 52a61d4
Show file tree
Hide file tree
Showing 2 changed files with 3 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
3 changes: 2 additions & 1 deletion app/scripts/controllers/metametrics-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,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 52a61d4

Please sign in to comment.