Skip to content

fix: stabilize useWithdrawalRequests selectors to prevent unnecessary re-renders#29597

Merged
vinnyhoward merged 1 commit into
mainfrom
fix-perps-withdrawal-selector-unstable-ref
May 1, 2026
Merged

fix: stabilize useWithdrawalRequests selectors to prevent unnecessary re-renders#29597
vinnyhoward merged 1 commit into
mainfrom
fix-perps-withdrawal-selector-unstable-ref

Conversation

@vinnyhoward

@vinnyhoward vinnyhoward commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Description

Inline [] fallbacks in useWithdrawalRequests selectors were creating new array references on every render, triggering React-Redux's "Selector unknown returned a different result" warning and causing unnecessary re-renders in PerpsProgressBar on mount.

Fixed by replacing inline [] literals with module-level constants and short-circuiting .filter() on empty arrays so selectors always return the same reference.

Performance impact: FPS on Perps tab mount improved from 60→22 drops down to a stable 60→57, nearly eliminating the frame drop entirely and it doesn't take ~1 second for the Perps screen to show anymore

NOTE: Unrelated to these changes, there is a considerate amount of frame drop when you're on the Perps home screen and from the UI hydrating. The frames drop as low as 8 FPS. This happens in main and this branch as well. Might be worth a follow up ticket

Changelog

CHANGELOG entry:null

Related issues

Fixes:

Manual testing steps

Feature: Perps home screen mount

  Scenario: user opens the app with Perps hub tab visible
    Given the hub tabs A/B test is enabled
    And the user has no pending withdrawal requests

    When the app loads and PerpsProgressBar mounts
    Then no "Selector unknown returned a different result" warning appears in the console
    And the Perps tab renders without unnecessary re-renders
    And FPS remains at or above 57 during mount

Screenshots/Recordings

Simulator.Screen.Recording.-.iPhone.17.-.2026-04-30.at.16.09.38.mov

Before

Simulator.Screen.Recording.-.iPhone.17.-.2026-04-30.at.16.05.29.mov

After

Simulator.Screen.Recording.-.iPhone.17.-.2026-04-30.at.16.09.38.mov

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

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.

Note

Low Risk
Low risk performance-only change: replaces inline empty-array fallbacks with stable module constants to avoid React-Redux selector warnings and unnecessary re-renders; no business logic or API behavior changes expected.

Overview
Prevents unnecessary re-renders in useWithdrawalRequests by replacing inline [] selector fallbacks with module-level EMPTY_WITHDRAWAL_REQUESTS/EMPTY_TX_HASHES constants and short-circuiting the withdrawal .filter() when there’s no selected address or the list is empty.

This makes selector outputs stable across renders (eliminating the “selector returned a different result” warning) while keeping the displayed/polled withdrawal logic unchanged.

Reviewed by Cursor Bugbot for commit e020446. Bugbot is set up for automated code reviews on this repo. Configure here.

@vinnyhoward vinnyhoward requested a review from a team as a code owner April 30, 2026 22:17
@github-actions

Copy link
Copy Markdown
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.

@metamaskbotv2 metamaskbotv2 Bot added the team-mobile-ux Mobile UX team label Apr 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 92%
click to see 🤖 AI reasoning details

E2E Test Selection:
The change in useWithdrawalRequests.ts is a minor optimization/bug fix:

  1. Introduces stable module-level empty array constants (EMPTY_WITHDRAWAL_REQUESTS, EMPTY_TX_HASHES) to prevent unnecessary re-renders due to referential inequality on each render cycle.
  2. Adds an early-exit optimization when withdrawals.length === 0 to skip unnecessary .filter() calls.
  3. Changes || to ?? for more precise null/undefined handling.

The change is scoped entirely to the Perps withdrawal requests hook, used only in PerpsProgressBar component. No interface changes, no API changes, no logic changes beyond the early-exit optimization.

SmokePerps is selected as the primary tag since this directly affects Perps withdrawal functionality. Per the SmokePerps tag description, SmokeWalletPlatform (Trending section) and SmokeConfirmations (on-chain transactions) must also be selected.

Performance Test Selection:
While the change introduces stable array references (a minor performance improvement), the optimization is too small and localized to warrant dedicated performance testing. The change actually reduces unnecessary re-renders rather than introducing performance concerns.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@Cal-L Cal-L left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@vinnyhoward vinnyhoward enabled auto-merge April 30, 2026 22:47
@vinnyhoward vinnyhoward added this pull request to the merge queue May 1, 2026
Merged via the queue into main with commit bc0ab56 May 1, 2026
126 of 130 checks passed
@vinnyhoward vinnyhoward deleted the fix-perps-withdrawal-selector-unstable-ref branch May 1, 2026 01:32
@github-actions github-actions Bot locked and limited conversation to collaborators May 1, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.77.0 Issue or pull request that will be included in release 7.77.0 label May 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.77.0 Issue or pull request that will be included in release 7.77.0 size-S team-mobile-ux Mobile UX team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants