-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: oversubscription perps top movers #33150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gambinish
wants to merge
10
commits into
main
Choose a base branch
from
fix/oversubscription-perps-top-movers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4f10d76
feat(perps): add usePerpsLiveMovers hook with change-detected live ra…
gambinish 7dd76b0
perf: use usePerpsLiveMovers in Now-tab PerpsBlock
gambinish ed81a02
perf: pause Now-tab movers subscription when unfocused or tab inactive
gambinish caebfdf
perf: gate perps price subscription on focus
gambinish eb320cb
Merge branch 'main' into fix/oversubscription-perps-top-movers
gambinish 24bd247
chore: add further debounce configuration
gambinish b6e93fb
fix: include design system fix
gambinish 9f36d83
Merge branch 'fix/oversubscription-perps-top-movers' of github.com:Me…
gambinish c51eef0
fix: lint tsc
gambinish ee983bd
fix: bugbots
gambinish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
app/components/Views/TrendingView/ExploreActiveTabContext.test.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react-native'; | ||
| import { Text } from 'react-native'; | ||
| import { | ||
| ExploreActiveTabProvider, | ||
| useExploreActiveTab, | ||
| } from './ExploreActiveTabContext'; | ||
|
|
||
| const ActiveTabProbe: React.FC = () => { | ||
| const activeTab = useExploreActiveTab(); | ||
| return <Text testID="active-tab">{activeTab}</Text>; | ||
| }; | ||
|
|
||
| describe('ExploreActiveTabContext', () => { | ||
| it('defaults to "Now" when rendered outside a provider', () => { | ||
| render(<ActiveTabProbe />); | ||
|
|
||
| expect(screen.getByTestId('active-tab')).toHaveTextContent('Now'); | ||
| }); | ||
|
|
||
| it('exposes the provided active tab to descendants', () => { | ||
| render( | ||
| <ExploreActiveTabProvider activeTab="Macro"> | ||
| <ActiveTabProbe /> | ||
| </ExploreActiveTabProvider>, | ||
| ); | ||
|
|
||
| expect(screen.getByTestId('active-tab')).toHaveTextContent('Macro'); | ||
| }); | ||
|
|
||
| it('updates descendants when the active tab changes', () => { | ||
| const { rerender } = render( | ||
| <ExploreActiveTabProvider activeTab="Now"> | ||
| <ActiveTabProbe /> | ||
| </ExploreActiveTabProvider>, | ||
| ); | ||
|
|
||
| expect(screen.getByTestId('active-tab')).toHaveTextContent('Now'); | ||
|
|
||
| rerender( | ||
| <ExploreActiveTabProvider activeTab="Sports"> | ||
| <ActiveTabProbe /> | ||
| </ExploreActiveTabProvider>, | ||
| ); | ||
|
|
||
| expect(screen.getByTestId('active-tab')).toHaveTextContent('Sports'); | ||
| }); | ||
| }); |
39 changes: 39 additions & 0 deletions
39
app/components/Views/TrendingView/ExploreActiveTabContext.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import React, { | ||
| createContext, | ||
| useContext, | ||
| type PropsWithChildren, | ||
| } from 'react'; | ||
| import type { ExploreTabName } from './search/analytics'; | ||
|
|
||
| const DEFAULT_ACTIVE_TAB: ExploreTabName = 'Now'; | ||
|
|
||
| const ExploreActiveTabContext = | ||
| createContext<ExploreTabName>(DEFAULT_ACTIVE_TAB); | ||
|
|
||
| export interface ExploreActiveTabProviderProps extends PropsWithChildren { | ||
| activeTab: ExploreTabName; | ||
| } | ||
|
|
||
| /** | ||
| * Exposes the currently active Explore tab to descendants without threading | ||
| * it through `TabProps`. `TabsList` keeps every tab mounted simultaneously, | ||
| * so passing the active tab as a prop would give all six tabs a changing | ||
| * prop value on every switch, busting memoization for feeds that don't care | ||
| * which tab is active. Consumers that do care (e.g. `PerpsBlock` pausing its | ||
| * live subscription while hidden) read it via `useExploreActiveTab` instead. | ||
| */ | ||
| export const ExploreActiveTabProvider: React.FC< | ||
| ExploreActiveTabProviderProps | ||
| > = ({ activeTab, children }) => ( | ||
| <ExploreActiveTabContext.Provider value={activeTab}> | ||
| {children} | ||
| </ExploreActiveTabContext.Provider> | ||
| ); | ||
|
|
||
| /** | ||
| * The currently active Explore tab name (e.g. `'Now'`, `'Macro'`). Falls | ||
| * back to `'Now'` when rendered outside a provider, matching the tabs list's | ||
| * default first tab. | ||
| */ | ||
| export const useExploreActiveTab = (): ExploreTabName => | ||
| useContext(ExploreActiveTabContext); |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This state update rerenders ExploreFeed on every tab switch. useExploreRefresh() returns a new object, which recreates all six tab elements and causes every loaded feed to rerender - not only the component using the context. This adds rendering work during tab changes despite the context being intended to isolate active tab updates. Please move the active tab state into a smaller component or preserve stable tab content references when the active tab changes.