Skip to content

fix/account-tracker-prevent-empty-state-update #5942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 10, 2025

Conversation

salimtb
Copy link
Contributor

@salimtb salimtb commented Jun 9, 2025

Explanation

This change prevents AccountTrackerController from overwriting cached balances with empty or unchanged state during refresh operations.

Currently, if all balance requests for a chain fail or return undefined (e.g., due to a temporary network issue), the controller updates the state with an empty object, erasing previous data. Additionally, even when the new balance data is identical to the current state, an update is still triggered, resulting in unnecessary stateChange emissions and potential UI re-renders.

This update introduces guards within the refresh method to:

  • Skip updates if the computed accountsForChain object is empty.
  • Skip updates if the resulting balances are identical to the current state.
  • Prevent stale or partial data from overriding valid cached values.
  • Reduce unnecessary re-renders and state emissions.

These changes help improve performance and stability, particularly under poor network conditions or when balance polling is frequent.

References

Changelog

@metamask/assets-controllers

UPDATE: Prevent AccountTrackerController from updating state with empty or unchanged data during balance refresh. Adds checks to avoid overwriting valid cached balances and reduce unnecessary stateChange emissions.

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@salimtb salimtb marked this pull request as ready for review June 9, 2025 12:49
@salimtb salimtb requested review from a team as code owners June 9, 2025 12:49
@salimtb salimtb merged commit e88bcf2 into main Jun 10, 2025
218 checks passed
@salimtb salimtb deleted the fix/account-tracker-prevent-empty-state-update branch June 10, 2025 08:19
@Prithpal-Sooriya Prithpal-Sooriya added the area-performance Issues relating to slowness of app, cpu usage, and/or blank screens. label Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-performance Issues relating to slowness of app, cpu usage, and/or blank screens.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stop empty state updates from AccountTrackerController
2 participants