MetaMask / MetaMask/metamask-extension
[State Sync Redesign 3.8] Remove `forceUpdateMetamaskState` (~109 call sites)
- Dominant language
- TypeScript
- Stars
- 13.2k
- Forks
- 5.6k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 451
Description
`forceUpdateMetamaskState` is a pull-based sync mechanism: it calls `submitRequestToBackground('getStatePatches')` to flush `PatchStore`, then dispatches `updateMetamaskState`. With per-controller subscriptions, state changes arrive automatically — this entire pattern becomes unnecessary.
Current usage pattern (repeated ~109 times in `ui/store/actions.ts`):
```typescript
await submitRequestToBackground('someMethod', [args]);
await forceUpdateMetamaskState(dispatch);
```
## Steps
1. Verify that per-controller subscriptions deliver state changes for every action that currently uses `forceUpdateMetamaskState` (audit all 109 call sites)
2. Remove `forceUpdateMetamaskState` calls one domain at a time (can parallel with Issue 3.7 domain migration)
3. Remove the `getStatePatches` RPC method from `setupControllerConnection` in `metamask-controller.js`
4. Remove `forceUpdateMetamaskState` function from `ui/store/actions.ts`
5. Also remove from non-action callers: `snap-interface.tsx` (3 sites), `unlock-page.component.tsx` (5 sites), `useSnapSettings.ts` (2 sites), `useAccountsOperationsLoadingStates.ts` (2 sites)
## Files
- `ui/store/actions.ts`
- `app/scripts/metamask-controller.js`
- `ui/contexts/snaps/snap-interface.tsx`
- `ui/pages/unlock-page/unlock-page.component.tsx`
- `ui/hooks/snaps/useSnapSettings.ts`
## Risk
Medium — each removal must be validated against the subscription path delivering the same update. If subscription is delayed or missed, UI shows stale data.
## Dependencies
Issue 3.7 (domain migration must be complete for each domain before its `forceUpdateMetamaskState` calls can be removed)
## Context
Part of [State Sync Redesign — Epic 3: UI-controller subscriptions].
Contributor guide
Research direction
Start by reading Issue 3.7 and auditing the roughly 109 call sites in ui/store/actions.ts, along with the non-action callers in snap-interface.tsx, unlock-page.component.tsx, useSnapSettings.ts, and useAccountsOperationsLoadingStates.ts. Verify per-controller subscriptions cover each action before removing calls. Done means the forceUpdateMetamaskState function and getStatePatches RPC are removed, with all affected UI updates still delivered through subscriptions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- backend, frontend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100