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: Memoize ToggleButton.tsx and specific toggles #7633

Merged
merged 3 commits into from
Jan 6, 2025

Conversation

VIKTORVAV99
Copy link
Member

Issue

These toggles are re-rendered often even if their states or props don't change.

Description

Memoizes the toggles, moves out the object declaration to outside the function so it's stable and uses useCallbacks to ensure the internal functions are stable between renders.

Double check

  • I have run pnpx prettier@2 --write . and poetry run format in the top level directory to format my changes.

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

web/src/features/map-controls/ConsumptionProductionToggle.tsx:23

  • The onSetCurrentMode function should check if the option is different from currentMode before calling trackEvent and setCurrentMode.
const onSetCurrentMode = useCallback(

web/src/features/map-controls/SpatialAggregatesToggle.tsx:23

  • [nitpick] The function name 'onSetCurrentMode' is ambiguous. It should be renamed to 'handleModeChange' or something more descriptive.
const onSetCurrentMode = useCallback(
Copy link
Collaborator

@tonypls tonypls left a comment

Choose a reason for hiding this comment

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

LGTM!

@VIKTORVAV99 VIKTORVAV99 merged commit 5c38300 into master Jan 6, 2025
23 checks passed
@VIKTORVAV99 VIKTORVAV99 deleted the vik/perf_memoize_Toggles branch January 6, 2025 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants