Skip to content

Commit 3b50a63

Browse files
committed
Add isValidJson check for child state from BaseControllerV2 controllers
1 parent 09b238f commit 3b50a63

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

packages/composable-controller/src/ComposableController.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
BaseState,
66
BaseConfig,
77
} from '@metamask/base-controller';
8-
import type { Json } from '@metamask/utils';
8+
import { isValidJson, type Json } from '@metamask/utils';
99

1010
export const controllerName = 'ComposableController';
1111

@@ -156,10 +156,12 @@ export class ComposableController extends BaseController<
156156
});
157157
} else if (isBaseController(controller)) {
158158
this.messagingSystem.subscribe(`${name}:stateChange`, (childState) => {
159-
this.update((state) => ({
160-
...state,
161-
[name]: childState,
162-
}));
159+
if (isValidJson(childState)) {
160+
this.update((state) => ({
161+
...state,
162+
[name]: childState,
163+
}));
164+
}
163165
});
164166
} else {
165167
throw new Error(

0 commit comments

Comments
 (0)