fix(perps): Button flash when open a market with an open position #27671
Conversation
|
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. |
TAT-2236: Button color flash when open a market with an open positionSummaryWhen navigating to a market with an existing position, Long/Short buttons flashed briefly before switching to Modify/Close buttons. The fix converts an async state derivation (useEffect) to a synchronous one (useMemo) in Root CauseFile: The
Reproduction CommitSHA: Metro log excerpt proving the bug: Changes
Test PlanAutomated
Manual (Gherkin)Feature: Market detail action buttons
Scenario: Open market with existing position
Given I have an open BTC position
When I navigate to the BTC market detail screen
Then I see Modify/Close buttons immediately
And I do not see Long/Short buttons flash
Scenario: Open market without position
Given I have no position on SOL
When I navigate to the SOL market detail screen
Then I see Long/Short buttons immediately
And I do not see Modify/Close buttons flashEvidence
JIRATAT-2236 Run Details
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection: The hook is consumed by:
Tag selection rationale:
The change is a rendering optimization (useMemo vs useState+useEffect) that should not break any existing functionality but needs validation that the fix works correctly in E2E flows. Performance Test Selection: |
|
✅ E2E Fixture Validation — Schema is up to date |
|




Description
When navigating to a market with an existing position, Long/Short buttons briefly flashed before switching to Modify/Close. Root cause:
positionsinusePerpsLivePositionswas derived fromrawPositionsvia auseEffect, creating a one-frame lag whereisInitialLoadingwasfalsebutpositionsstill held stale data. Fix: replace the state+effect pattern withuseMemofor synchronous derivation.Changelog
CHANGELOG entry: Fixed button flash (Long/Short briefly visible) when opening a market with an existing position
Related issues
Fixes: TAT-2236
Manual testing steps
Screenshots/Recordings
Before
See automation/27671/before.mp4
After
See automation/27671/after.mp4
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Low Risk
Low risk: small hook refactor to compute
positionssynchronously plus a targeted regression test; main risk is subtle rendering behavior changes around initial WebSocket updates.Overview
Fixes a one-render mismatch in
usePerpsLivePositionswhereisInitialLoadingcould flip tofalsebefore derivedpositionsupdated, causing a brief Long/Short button flash when opening a market with an existing position.positionsis now derived fromrawPositionsandpriceDataviauseMemo(instead of state set in an effect), and a new regression test asserts that the first WebSocket update makesisInitialLoading=falseandpositionsavailable in the same render.Written by Cursor Bugbot for commit 997d441. This will update automatically on new commits. Configure here.