metamask-mobile icon indicating copy to clipboard operation
metamask-mobile copied to clipboard

feat(tabs): enhance HomepageDiscoveryTabs tests and context stability

Open PatrykLucka opened this issue 5 months ago • 3 comments

Description

Memoizes the TabIconAnimationContext provider value in HomepageDiscoveryTabs so tab icon consumers do not receive a new context object on unrelated parent rerenders. This keeps the Reanimated SharedValue plumbing intact while reducing unnecessary context invalidation for the homepage discovery tab bar.

This also moves the existing React compiler suppression onto the exact Reanimated shared-value mutation it documents, and adds a focused regression test that verifies the provider value remains referentially stable across unrelated rerenders.

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TMCU-882

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

After

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
    • See trace() for usage and addToken for an example

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 Small React performance/context fix with no auth, data, or API changes; behavior is unchanged aside from fewer context updates.

Overview HomepageDiscoveryTabs now memoizes the TabIconAnimationContext provider value with useMemo, so tab icon consumers keep the same context object reference when the parent rerenders for unrelated props (e.g. walletHeaderOffset) instead of getting a fresh inline object every time.

The React compiler eslint-disable for Reanimated SharedValue mutation is relocated to sit on the iconCollapseProgress.value = withTiming(...) line it documents.

Tests mock useSharedValue for a stable shared value and add a regression case that asserts the context value is referentially stable across such rerenders.

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

PatrykLucka avatar Jun 25 '26 13:06 PatrykLucka

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.

github-actions[bot] avatar Jun 25 '26 13:06 github-actions[bot]

PR template — items to address before "Ready for review"

Warnings — informational, address before merging:

  • Manual testing steps still contain template content (the Gherkin example title or a [...] placeholder). Replace with real steps, or write N/A — <reason>.
  • Screenshots/Recordings section is empty. Add an image/video for user-facing changes, logs/console output for non-user-facing changes, or write N/A if no evidence is applicable.
  • Pre-merge author checklist has unchecked items (e.g. "I've tested on Android"). Every box must be consciously checked — see docs/readme/ready-for-review.md.

See docs/readme/ready-for-review.md for the full Definition of Ready for Review.

metamask-ci avatar Jun 25 '26 13:06 metamask-ci

🔍 Smart E2E Test Selection

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

E2E Test Selection: The changes are confined to HomepageDiscoveryTabs.tsx and its test file. The functional change is wrapping the TabIconAnimationContext.Provider value in useMemo to stabilize the context reference across re-renders — a standard React optimization pattern. The eslint-disable comment was also moved to a more specific location (cosmetic). The test file adds a unit test to verify the memoization behavior.

This component is the Trending/Discovery tabs on the wallet homepage. SmokeWalletPlatform covers the Trending discovery tab including search, browsing content feeds (Predictions, Tokens, Perps, Sites sections), and browser navigation integration. Since the change touches the container component for these tabs, SmokeWalletPlatform is the appropriate tag to validate the change doesn't break the Trending tab UI or navigation.

No other tags are needed: the change doesn't affect confirmations, network management, swaps, staking, accounts, snaps, or any other feature area. The risk is low since it's a pure React optimization (useMemo) with no logic changes.

Performance Test Selection: The change adds useMemo to stabilize a context value reference, which is a micro-optimization that prevents unnecessary re-renders of context consumers. While this is technically a performance improvement, it's too minor to warrant running dedicated performance tests. The change doesn't affect any of the measured performance scenarios (app launch, onboarding, login, swaps, asset loading, account list, predict, perps). No performance spec files were changed.

View GitHub Actions results

github-actions[bot] avatar Jun 26 '26 09:06 github-actions[bot]

No release label on PR. Adding release label release-8.2.0 on PR, as PR was added to branch 8.2.0 when release was cut.

gauthierpetetin avatar Jul 06 '26 10:07 gauthierpetetin