refactor(ui): fix React anti-patterns in BaseSettingsDialog#21150
refactor(ui): fix React anti-patterns in BaseSettingsDialog#21150ayush31010 wants to merge 3 commits intogoogle-gemini:mainfrom
Conversation
Addresses two issues raised in google-gemini#21140: 1. Redundant callbacks: `handleScopeHighlight` and `handleScopeSelect` had identical implementations. Replaced with a single `handleScopeChange` callback passed to both `onSelect` and `onHighlight` on <RadioButtonSelect />. 2. Misused effect for derived state: a `useEffect` was calling `setFocusSection('settings')` whenever `showScopeSelector` was hidden and `focusSection === 'scope'`. Effects are for subscribing to external systems, not deriving values from existing state/props. Replaced with an `effectiveFocusSection` variable computed inline during render, which all render expressions and the key-handler now consume instead of reading `focusSection` directly. No behaviour change; all 28 existing tests continue to pass. Closes google-gemini#21140
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the BaseSettingsDialog component to address two React anti-patterns. The redundant handleScopeHighlight and handleScopeSelect callbacks have been consolidated into a single handleScopeChange function, reducing code duplication. Additionally, a useEffect hook that was incorrectly used for deriving state has been replaced with an inline computation during the render phase. These changes improve code quality and align with React best practices without altering functionality.
|
Hey I'm already assigned to this issue. I'm the one who filed it. I would also say it's a little more complicated than only addressing the exact two examples I highlighted in the filed issue. My advice to you would be to consider that #21003 was merged in today, so help wanted issues should begin to clear up in the next weeks. Also you should actually verify that your /assign command succeeded before you assume it did! I was already assigned lol Really sorry about the miscommunication. |
|
merging this will just cause conflicts with #21206 which addresses the problem more holistically and is a path approved by jacob |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
I apologize if this comes across the wrong way:
The actual work of pruning out these anti patterns is something that was started in #15840 and has been proceeding with Merging this does not close the issue or fix the issue, so I will have to get it reopened. I also then have to worry abt whether the automated workflow will close my PR because it thinks the issue is fixed. It just fixes two of the easiest unfortunate react patterns that were the easiest examples to provide I don't mind resolving conflicts and you're right that it isn't a big deal but this is the situation and I'm sorry if my tone is unfortunate |
|
@Solventerritory apologies for the confusion as @psinha40898 pointed this issue is being addressed and this PR will not be merged. |
spencer426
left a comment
There was a problem hiding this comment.
Ignore my previous approval as this issue is already addressed.
Summary
Fixes the two React anti-patterns identified in #21140.
1. Redundant callbacks (Exhibit A)
handleScopeHighlightandhandleScopeSelecthad identical bodies. Replaced with a singlehandleScopeChangepassed to bothonSelectandonHighlighton<RadioButtonSelect />.2. Effect used for derived state (Exhibit B)
Effects are for subscribing to external systems. This value is purely derived from existing state and props, so computing it on render is the correct pattern.
Test plan
BaseSettingsDialogtests pass unchangedCloses #21140