Skip to content

TAT-2236: Button color flash when open a market with an open position#27624

Closed
abretonc7s wants to merge 1 commit into
mainfrom
fix/perps/tat-2236
Closed

TAT-2236: Button color flash when open a market with an open position#27624
abretonc7s wants to merge 1 commit into
mainfrom
fix/perps/tat-2236

Conversation

@abretonc7s
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s commented Mar 18, 2026

Summary

Fixes a button flash on PerpsMarketDetails where Long/Short buttons appeared briefly before Modify/Close buttons when navigating to a market with an open position.

Root cause: usePerpsLivePositions used a separate useState + useEffect to derive enriched positions from raw positions. When a WebSocket update arrived, rawPositions and isInitialLoading updated in the same React batch, but positions (derived via useEffect) lagged by one render frame. This caused a single frame where isInitialLoading=false (buttons visible) but positions=[] (no existing position found), rendering Long/Short buttons before Modify/Close.

Fix: Replace the useState+useEffect pattern with useMemo so enriched positions are derived synchronously in the same render as rawPositions updates.

Changes

  • usePerpsLivePositions.ts: Changed positions from state variable to useMemo derived from rawPositions and priceData
  • useLivePositions.test.ts: Added test verifying positions and isInitialLoading update atomically (no inconsistent intermediate state)

Test Plan

Automated

  • yarn jest app/components/UI/Perps/hooks/stream/useLivePositions.test.ts — 32/32 pass
  • yarn lint:tsc — no new errors
  • validate-recipe.sh — 11/11 steps pass

Manual (Gherkin)

Given I have an open BTC position
When I navigate from Wallet to PerpsMarketDetails for BTC
Then I see "Modify" and "Close long" buttons immediately
And I never see "Long" / "Short" buttons flash

Given I have no ATOM position
When I navigate to PerpsMarketDetails for ATOM
Then I see "Long" and "Short" buttons immediately

Evidence

  • before.mp4: Shows flash of Long/Short buttons before Modify/Close on BTC market
  • after.mp4: Modify/Close buttons appear immediately without flash
  • Screenshots: market-detail-with-position.png, market-detail-no-position.png

JIRA

TAT-2236

@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.

@metamaskbot metamaskbot added the team-perps Perps team label Mar 18, 2026
@github-actions github-actions Bot added the risk-low Low testing needed · Low bug introduction risk label Mar 18, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
No files changed - no analysis needed

Performance Test Selection:
No files changed - no performance tests needed

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

@abretonc7s abretonc7s closed this Mar 19, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

risk-low Low testing needed · Low bug introduction risk team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants