chore: Simplify TokenListController initialization#7740
Merged
Conversation
8bed328 to
ca3acb1
Compare
ca3acb1 to
07a04f4
Compare
sahar-fehri
reviewed
Jan 27, 2026
| * data loaded from storage would be immediately written back. | ||
| * Chains are removed from this set after being skipped once. | ||
| */ | ||
| readonly #chainsLoadedFromStorage: Set<Hex> = new Set(); |
Contributor
There was a problem hiding this comment.
Thanks a lot for removing this! That was a workaround to avoid doing redundant writes 🙏
ad6a0f8 to
11d2a4f
Compare
sahar-fehri
previously approved these changes
Jan 28, 2026
There was some complexity in handling the order of operations between controller initialization and the event to persist state changes. To simplify this, the controller has been updated such that it no longer persists state changes until _after_ initialization. This makes the logic easier to follow, and lets us delete an instance variable and a few blocks of code. The controller will be initialized as part of wallet initialization, so it will not be "constructed but uninitialized" for any significant length of time.
11d2a4f to
6060063
Compare
Member
Author
|
Rebased to resolve conflicts |
Member
Author
|
@metamaskbot publish-previews |
Contributor
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
sahar-fehri
approved these changes
Jan 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
There was some complexity in handling the order of operations between controller initialization and the event to persist state changes.
To simplify this, the controller has been updated such that it no longer persists state changes until after initialization. This makes the logic easier to follow, and lets us delete an instance variable and a few blocks of code.
The controller will be initialized as part of wallet initialization, so it will not be "constructed but uninitialized" for any significant length of time.
References
Related to changes made in this PR: #7413
Checklist
Note
Medium Risk
Changes when
TokenListControllerstarts persistingtokensChainsCacheand adjusts initialization/storage synchronization logic; regressions could cause missed or unintended StorageService writes/overwrites during startup.Overview
TokenListControllerno longer subscribes tostateChangefor debounced StorageService persistence untilinitialize()is called, simplifying construction-time behavior.Initialization/storage sync logic is simplified by removing the “loaded-from-storage skip” tracking and by scheduling persistence for any chains already present in state at init time. Tests are updated to explicitly call
initialize()before asserting persistence, and new cases cover no persistence before init and persisting updates that occurred prior to init.Written by Cursor Bugbot for commit 6060063. This will update automatically on new commits. Configure here.