TAT-2236: Button color flash when open a market with an open position#27624
Closed
abretonc7s wants to merge 1 commit into
Closed
TAT-2236: Button color flash when open a market with an open position#27624abretonc7s wants to merge 1 commit into
abretonc7s wants to merge 1 commit into
Conversation
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
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection: Performance Test Selection: |
|
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.



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:
usePerpsLivePositionsused a separateuseState+useEffectto derive enriched positions from raw positions. When a WebSocket update arrived,rawPositionsandisInitialLoadingupdated in the same React batch, butpositions(derived via useEffect) lagged by one render frame. This caused a single frame whereisInitialLoading=false(buttons visible) butpositions=[](no existing position found), rendering Long/Short buttons before Modify/Close.Fix: Replace the
useState+useEffectpattern withuseMemoso enriched positions are derived synchronously in the same render asrawPositionsupdates.Changes
usePerpsLivePositions.ts: Changedpositionsfrom state variable touseMemoderived fromrawPositionsandpriceDatauseLivePositions.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 passyarn lint:tsc— no new errorsvalidate-recipe.sh— 11/11 steps passManual (Gherkin)
Evidence
market-detail-with-position.png,market-detail-no-position.pngJIRA
TAT-2236