fix(assets): memoize selectAllTokensFlat for referential stability - #33753
Conversation
Switch selectAllTokensFlat to createDeepEqualSelector and return a shared frozen empty array so consumers do not re-render when token map content is unchanged. Co-authored-by: prithpal.sooriya <prithpal.sooriya@consensys.net>
…tests Isolate referential-stability assertions from prior selector cache state. Co-authored-by: prithpal.sooriya <prithpal.sooriya@consensys.net>
Cast the frozen empty array as Token[] before Object.freeze so lint:tsc accepts the shared empty reference.
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Impact analysis:
Conclusion: No E2E smoke tags are needed. The change is a low-risk internal optimization with unit test coverage. No performance test tags are warranted either, as this is a selector-level memoization fix that doesn't affect any measured performance scenarios (onboarding, login, launch, swaps, asset loading, etc.). Performance Test Selection: |
|



Description
Memoizes
selectAllTokensFlatso consumers do not re-render when the flattened token list content is unchanged.selectAllTokensFlatpreviously usedcreateSelectorand returned a fresh[]for the empty case. Because the result function always builds a new array viareduce/concat, any recomputation produced a new reference even when token contents were identical.This change:
selectAllTokensFlattocreateDeepEqualSelector(already used by sibling token selectors)EMPTY_TOKENS) for the empty caseCaller note (out of scope): the only production consumer found is
app/util/sentry/tags/index.ts, which reads.lengthand does not immediately.map/.filterthe result.Changelog
CHANGELOG entry: null
Related issues
Fixes: #31345
Fixes: ASSETS-3721
Manual testing steps
Unit coverage:
yarn jest app/selectors/tokensController(23 passed), including referential-stability assertions.Screenshots/Recordings
N/A — selector-only performance fix; no UI changes.
Before
N/A
After
N/A
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an examplePre-merge reviewer checklist
Note
Low Risk
Selector-only memoization with no auth, data, or API behavior changes; production use is limited to Sentry tag
.length.Overview
selectAllTokensFlatno longer returns a new array reference on every recompute when the flattened token list is unchanged, which cuts unnecessary re-renders for Redux subscribers.The selector is switched from
createSelectortocreateDeepEqualSelector(aligned with other token selectors), and the empty case returns a shared frozenEMPTY_TOKENSinstead of a fresh[]. Unit tests assert stable references for repeated calls, equal-content state, and empty token maps.Reviewed by Cursor Bugbot for commit 9d0d7e4. Bugbot is set up for automated code reviews on this repo. Configure here.