-
Notifications
You must be signed in to change notification settings - Fork 1
ASAB Shell - Optimize handling/rendering the language flags #60
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,8 @@ export default function LanguageDropdown(props) { | |||||||||||||||
| }); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| const FLAG_STYLE = {width: '32px'}; | ||||||||||||||||
|
|
||||||||||||||||
| const { dispatch } = useAppStore(); | ||||||||||||||||
|
|
||||||||||||||||
| useEffect(() => { | ||||||||||||||||
|
|
@@ -45,7 +47,7 @@ export default function LanguageDropdown(props) { | |||||||||||||||
| if (language == 'cimode') return null; | ||||||||||||||||
| return ( | ||||||||||||||||
| <DropdownItem key={language} title={language} onClick={() => {changeLanguage(language)}}> | ||||||||||||||||
| <LanguageFlag language={language} className="pe-2" style={{width: '32px'}}/> | ||||||||||||||||
| <LanguageFlag language={language} className="pe-2" style={FLAG_STYLE}/> | ||||||||||||||||
| {t('i18n|language|'+language)} | ||||||||||||||||
| </DropdownItem> | ||||||||||||||||
| ); | ||||||||||||||||
|
|
@@ -56,6 +58,6 @@ export default function LanguageDropdown(props) { | |||||||||||||||
| ); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| function LanguageFlag({language, className, style}) { | ||||||||||||||||
| const LanguageFlag = React.memo(function LanguageFlag({language, className, style}) { | ||||||||||||||||
| return (<img className={className} src={`media/locale/${language}.svg`} style={style}/>) | ||||||||||||||||
| } | ||||||||||||||||
| }); | ||||||||||||||||
|
Comment on lines
+61
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add The flag image is missing an Proposed fix-const LanguageFlag = React.memo(function LanguageFlag({language, className, style}) {
- return (<img className={className} src={`media/locale/${language}.svg`} style={style}/>)
-});
+const LanguageFlag = React.memo(function LanguageFlag({language, className, style}) {
+ return (<img className={className} src={`media/locale/${language}.svg`} style={style} alt={`${language} flag`}/>)
+});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
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.
Move
FLAG_STYLEoutside the component for true memoization benefit.Defining
FLAG_STYLEinside the component function causes it to be recreated on every render, producing a new object reference each time. This defeats the optimization goal and breaksReact.memo's shallow comparison on theLanguageFlagcomponent.Proposed fix
Move the constant outside the component:
🤖 Prompt for AI Agents