Closed MajorLift closed 18 hours ago
@metamaskbot publish-preview
Preview builds have been published. See these instructions for more information about preview builds.
@metamaskbot publish-preview
Preview builds have been published. See these instructions for more information about preview builds.
@metamaskbot publish-preview
Preview builds have been published. See these instructions for more information about preview builds.
The issue suggests two solutions: supporting controllers with no state, or rejecting them. Why not reject instead, what advantage is there to passing in a "controller" with no state?
@Gudahtt The motivation for this PR is to make the ComposableController API more accommodating rather than require code changes downstream with stricter guardrails, but maybe that's the wrong direction to take.
My initial inclination was also to reject, which is reflected in the current state of the ComposableController. This had become a blocker for the update to v9 in mobile because the Engine class uses a single controllers
array that includes non-controllers to instantiate both the datamodel and context fields.
One concern I had regarding this was performance impacts on mobile Engine initialization time, since we would need to create a new filtered copy of the array that excludes non-controllers to pass into ComposableController.
However, I've implemented a refactor here 5d0807f05c40fd667dfef28a1ae1233e9bc95ef7 that removes a costly reduce
call by directly creating the Engine context property as an object keyed with controller names (this is also the approach taken by MetamaskController on extension).
If this doesn't cause any additional issues, then we could close this PR, and stricter safeguards on ComposableController could be preserved that enable it to avoid handling non-controllers altogether.
Closing as wont-fix. Downstream consumers will need to ensure that only stateful controllers are present in the input array they pass into the ComposableController
constructor.
Concerns over imposing performance penalty to mobile resolved here: https://github.com/MetaMask/metamask-mobile/pull/12374
References
Changelog
@metamask/composable-controller
Changed
ComposableController
controller optioncontrollers
and generic type parameterChildControllers
to accept all objects with a 'name' property. Passing in non-controller input no longer produces a runtime error.stateChange
event subscription operation will exclude non-controller input.ComposableControllerState
only accepts controllers with a 'state' property.isBaseController
,isBaseControllerV1
fromControllerInstance
tounknown
.Checklist