Skip to content
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

perf(exchange layer): deduplicate exchange tooltips #6594

Merged
merged 8 commits into from
Apr 9, 2024

Conversation

VIKTORVAV99
Copy link
Member

@VIKTORVAV99 VIKTORVAV99 commented Mar 29, 2024

Issue

We have a duplicate code that is functioning almost exactly the same and is creating a lot of unnecessary dom elements of which half are hidden at any given time.

Description

This PR deduplicates the code and unifies the MobileExchangeTooltip and ExchangeTooltip as well as ExchangeTooltipWrapper and MobileExchangeTooltipWrapper into just one single component respectively that can be used by both mobile and none mobile.

Some highlights:

  • Changes the click behaviour on "desktop" so the tooltip doesn't disappear when you click on the arrow.
  • Deduplicates the code between the tooltips and wrappers into one.
  • Adds a useDimension hook to get if the screen size is below or above the mobile breakpoint.
  • Optimises the early returns of the wrapper to reduce the amount of function calls that are made if we return early.
  • Removes unneeded dom elements in the tooltip.
  • Reduces the dom count by 792 elements (dependant on how many arrows are rendered)

Double check

  • I have tested my parser changes locally with poetry run test_parser "zone_key"
  • I have run pnpx prettier@2 --write . and poetry run format in the top level directory to format my changes.

web/src/features/exchanges/ExchangeTooltip.tsx Outdated Show resolved Hide resolved
web/src/hooks/dimensions.ts Outdated Show resolved Hide resolved
@VIKTORVAV99 VIKTORVAV99 marked this pull request as ready for review March 31, 2024 16:47
@VIKTORVAV99 VIKTORVAV99 requested review from a team and silkeholmebonnen and removed request for a team March 31, 2024 16:48
@silkeholmebonnen
Copy link
Contributor

The tooltip on mobile goes out of the screen sometimes, and it didn't before.
Screenshot 2024-04-04 at 08 50 26
image

It seems like this was already a problem on desktop before, but we might want to change it in this PR as well?
Screenshot 2024-04-04 at 08 51 06

@VIKTORVAV99
Copy link
Member Author

The tooltip on mobile goes out of the screen sometimes, and it didn't before.

Screenshot 2024-04-04 at 08 50 26 image

It seems like this was already a problem on desktop before, but we might want to change it in this PR as well?

Screenshot 2024-04-04 at 08 51 06

Nice find!

There is another PR open at #6359 that focuses on that for other tooltips so I'll try and get that merged as soon as possible and see if it fixes this as well or can be reused in here.

Copy link
Contributor

@silkeholmebonnen silkeholmebonnen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I left some comments with questions:)

web/src/components/tooltips/TooltipWrapper.tsx Outdated Show resolved Hide resolved
web/src/features/exchanges/ExchangeTooltip.tsx Outdated Show resolved Hide resolved
web/src/features/exchanges/ExchangeArrow.tsx Show resolved Hide resolved
Copy link
Member

@madsnedergaard madsnedergaard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments, but nice :)

web/src/components/tooltips/TooltipWrapper.tsx Outdated Show resolved Hide resolved
@@ -17,10 +18,27 @@ export default function TooltipWrapper(
if (!tooltipContent) {
return children;
}
const [isOpen, setIsOpen] = useState(false);
const { isMobile } = useDimensions();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use our existing hook instead: const isBiggerThanMobile = useBreakpoint('sm');

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the sm breakpoint is a lot smaller than what we use as isMobile on the map, should it not be md? Or should we change the map as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up using isMobile and negated the value of the hook (was quicker and less error prone than changing reversing all the logic.

I also used 'md' to match what it was before, but I'm open to changing this.

if (transform.x - 100 * transform.k > viewportWidth) {
return null;
}
useEffect(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this break the Rules of Hooks, as the hook is only conditionally rendered? Guess this was also a problem before though, so we should probably use the linting plugin for hooks: https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks

Copy link
Member Author

@VIKTORVAV99 VIKTORVAV99 Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know but since the renders should not change between the hours themselves and we are re rendering all exchanges I think we should be safe, but I'll look into it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it as is now and then I'll open a new PR with the new eslint plugin and fix everything that needs to be fixed in there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks! :)

web/src/features/exchanges/ExchangeArrow.tsx Outdated Show resolved Hide resolved
@VIKTORVAV99 VIKTORVAV99 enabled auto-merge (squash) April 9, 2024 13:51
@VIKTORVAV99 VIKTORVAV99 merged commit b90091a into master Apr 9, 2024
22 checks passed
@VIKTORVAV99 VIKTORVAV99 deleted the vik/deduplicate_exchange_tooltips branch April 9, 2024 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend 🎨 performance 🏎 techdebt Unpleasantness that does (or may in future) affect development
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants