Conversation
Copilot
AI
changed the title
[WIP] Fix getPendingApprovals selector for memoization
Fix Jan 16, 2026
getPendingApprovals selector memoization to prevent cascade re-renders
Contributor
|
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. |
Contributor
Builds ready [e1a1618]
UI Startup Metrics (1305 ± 107 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
getPendingApprovals selector memoization to prevent cascade re-rendersgetPendingApprovals broken selector memoization to prevent global cascading re-renders
e1a1618 to
92acebb
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Contributor
Builds ready [fea5212]
UI Startup Metrics (1271 ± 116 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Contributor
Builds ready [1ce7ca4]
UI Startup Metrics (1309 ± 109 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
10 tasks
Contributor
Builds ready [f1cd417]
UI Startup Metrics (1289 ± 119 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs
|
Contributor
Builds ready [0f442cc]
UI Startup Metrics (1292 ± 111 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs
|
0f442cc to
f1cd417
Compare
Contributor
Builds ready [f1cd417]
UI Startup Metrics (1252 ± 106 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚀 Bundle size reduced!]
|
Contributor
Builds ready [f1cd417]
UI Startup Metrics (1252 ± 106 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚀 Bundle size reduced!]
|
Contributor
Builds ready [4984401]
UI Startup Metrics (1263 ± 110 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs
|
OGPoyraz
approved these changes
Jan 23, 2026
github-merge-queue bot
pushed a commit
that referenced
this pull request
Jan 23, 2026
…bal cascading re-renders (#39312) ## **Description** `getPendingApprovals` was creating a new array on every call via `Object.values()`, breaking memoization in the Routes component and triggering cascade re-renders across ~50-60 child components on every state change. **Changes:** - Wrapped `getPendingApprovals` in `createSelector` to memoize the `Object.values()` transformation - Added helper function `getPendingApprovalsObject` to extract the pendingApprovals object - Returns stable reference when underlying `pendingApprovals` object is unchanged **Implementation:** ```typescript // Before: new array every call export function getPendingApprovals(state: ApprovalsMetaMaskState) { return Object.values(state.metamask.pendingApprovals ?? {}); } // After: memoized transformation const getPendingApprovalsObject = (state: ApprovalsMetaMaskState) => state.metamask.pendingApprovals ?? {}; export const getPendingApprovals = createSelector( getPendingApprovalsObject, (approvals) => Object.values(approvals), ); ``` **Testing:** - Added unit tests verifying reference equality on repeated calls with identical state - Tests verify invalidation when pendingApprovals actually change - All existing tests pass (664 selector tests across 31 suites) - Covers edge cases (empty object, null/undefined values) ## **Changelog** CHANGELOG entry: Fixed critical performance issue slowing down all user actions by fixing approvals selector memoization ## **Related issues** Fixes: https://github.com/MetaMask/MetaMask-planning/issues/6673 - Part of [#6669](https://github.com/MetaMask/MetaMask-planning/issues/6669) — Break Global Re-render Cascade ## **Manual testing steps** 1. Open MetaMask extension 2. Navigate to any page that triggers state changes (e.g., switching networks, accounts) 3. Observe improved responsiveness compared to before (Routes component and children no longer re-render unnecessarily) 4. Verify approvals functionality works correctly (no behavioral changes) ## **Screenshots/Recordings** ### **Before** N/A - Performance improvement (internal optimization, no UI changes) ### **After** N/A - Performance improvement (internal optimization, no UI changes) ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Optimizes approvals selectors to avoid unnecessary renders by stabilizing outputs and handling empty/null states. > > - Wraps `getPendingApprovals` with `createSelector` and adds `getPendingApprovalsObject` using `EMPTY_OBJECT` fallback > - Converts `pendingApprovalsSortedSelector` to a memoized selector that sorts a copied array > - Leaves existing APIs intact while returning stable references when `pendingApprovals` is unchanged > - Adds unit tests validating memoization, change invalidation, and empty/null behavior > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 4984401. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Jongsun Suh <jongsun.suh@icloud.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Description
getPendingApprovalswas creating a new array on every call viaObject.values(), breaking memoization in the Routes component and triggering cascade re-renders across ~50-60 child components on every state change.Changes:
getPendingApprovalsincreateSelectorto memoize theObject.values()transformationgetPendingApprovalsObjectto extract the pendingApprovals objectpendingApprovalsobject is unchangedImplementation:
Testing:
Changelog
CHANGELOG entry: Fixed critical performance issue slowing down all user actions by fixing approvals selector memoization
Related issues
Fixes: https://github.com/MetaMask/MetaMask-planning/issues/6673
Manual testing steps
Screenshots/Recordings
Before
N/A - Performance improvement (internal optimization, no UI changes)
After
N/A - Performance improvement (internal optimization, no UI changes)
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Optimizes approvals selectors to avoid unnecessary renders by stabilizing outputs and handling empty/null states.
getPendingApprovalswithcreateSelectorand addsgetPendingApprovalsObjectusingEMPTY_OBJECTfallbackpendingApprovalsSortedSelectorto a memoized selector that sorts a copied arraypendingApprovalsis unchangedWritten by Cursor Bugbot for commit 4984401. This will update automatically on new commits. Configure here.