bito-code-review[bot] commented on code in PR #38524:
URL: https://github.com/apache/superset/pull/38524#discussion_r2906928216
##########
superset-frontend/packages/superset-ui-core/src/components/EditableTitle/index.tsx:
##########
@@ -105,15 +105,21 @@ export function EditableTitle({
return 0;
}
- useEffect(() => {
+ useLayoutEffect(() => {
const { font } = window.getComputedStyle(
contentRef.current?.resizableTextArea?.textArea || document.body,
);
const textWidth = measureTextWidth(currentTitle || '', font);
const padding = 20;
const maxAllowedWidth = typeof maxWidth === 'number' ? maxWidth : Infinity;
setInputWidth(Math.min(textWidth + padding, maxAllowedWidth));
- }, [currentTitle]);
+ }, [currentTitle, canEdit, maxWidth]);
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Unnecessary dependency in useLayoutEffect</b></div>
<div id="fix">
canEdit is listed in the dependencies but not used in the useLayoutEffect,
violating React's exhaustive-deps rule and causing unnecessary re-executions
when canEdit changes. Remove it to optimize performance and follow best
practices.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
}, [currentTitle, maxWidth]);
````
</div>
</details>
</div>
<small><i>Code Review Run #067228</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
superset-frontend/src/dashboard/components/gridComponents/Tab/Tab.tsx:
##########
@@ -446,7 +446,7 @@ const Tab = (props: TabProps): ReactElement => {
title={component.meta.text}
defaultTitle={component.meta.defaultText}
placeholder={component.meta.placeholder}
- canEdit={editMode && isFocused}
+ canEdit={editMode}
onSaveTitle={handleChangeText}
showTooltip={false}
editing={editMode && isFocused}
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Inconsistent tab editing logic</b></div>
<div id="fix">
The canEdit prop allows editing tab titles even when the tab is not focused,
but the editing state remains tied to focus. This inconsistency could lead to
confusing behavior where users can initiate editing on unfocused tabs. Revert
to the original logic where canEdit depends on both editMode and isFocused.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
title={component.meta.text}
defaultTitle={component.meta.defaultText}
placeholder={component.meta.placeholder}
canEdit={editMode && isFocused}
onSaveTitle={handleChangeText}
showTooltip={false}
editing={editMode && isFocused}
````
</div>
</details>
</div>
<small><i>Code Review Run #067228</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
superset-frontend/packages/superset-ui-core/src/components/EditableTitle/index.tsx:
##########
@@ -105,15 +105,21 @@ export function EditableTitle({
return 0;
}
- useEffect(() => {
+ useLayoutEffect(() => {
const { font } = window.getComputedStyle(
contentRef.current?.resizableTextArea?.textArea || document.body,
);
const textWidth = measureTextWidth(currentTitle || '', font);
const padding = 20;
const maxAllowedWidth = typeof maxWidth === 'number' ? maxWidth : Infinity;
setInputWidth(Math.min(textWidth + padding, maxAllowedWidth));
- }, [currentTitle]);
+ }, [currentTitle, canEdit, maxWidth]);
+
+ useEffect(() => {
+ if (editing) {
+ setIsEditing(true);
+ }
+ }, [editing]);
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Incomplete prop synchronization in editing state</b></div>
<div id="fix">
The new useEffect only sets isEditing to true when editing is true, but
doesn't reset it to false when editing becomes false. This prevents the
component from exiting edit mode if the editing prop is toggled off externally,
leading to incorrect UI state. Sync the state properly with
setIsEditing(editing).
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
useEffect(() => {
setIsEditing(editing);
}, [editing]);
````
</div>
</details>
</div>
<small><i>Code Review Run #067228</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]