codeant-ai-for-open-source[bot] commented on code in PR #42479:
URL: https://github.com/apache/superset/pull/42479#discussion_r3657470773


##########
superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.tsx:
##########
@@ -320,11 +320,39 @@ const Chart = (props: ChartProps) => {
   );
 
   useLayoutEffect(() => {
-    if (isExpanded && descriptionRef.current) {
-      setDescriptionHeight(descriptionRef.current.offsetHeight);
-    } else {
+    if (!isExpanded || !descriptionRef.current) {
       setDescriptionHeight(0);
+      return undefined;
     }
+
+    let isDescriptionHeightSet = false;
+    const initialHeight = descriptionRef.current.offsetHeight;
+    if (initialHeight > 0) {
+      setDescriptionHeight(initialHeight);
+      isDescriptionHeightSet = true;
+    }
+
+    if (typeof ResizeObserver !== 'undefined') {
+      const observer = new ResizeObserver(entries => {
+        for (const entry of entries) {
+          if (entry.target === descriptionRef.current) {
+            const height = (entry.target as HTMLElement).offsetHeight;
+            if (height > 0 || !isDescriptionHeightSet) {
+              setDescriptionHeight(height);
+              isDescriptionHeightSet = true;
+            }
+          }
+        }
+      });
+
+      observer.observe(descriptionRef.current);
+
+      return () => {
+        observer.disconnect();
+      };
+    }
+
+    return undefined;

Review Comment:
   **Suggestion:** When `ResizeObserver` is unavailable, this effect only 
measures `offsetHeight` once. If the markdown description renders 
asynchronously afterward, `descriptionHeight` remains stale and the chart can 
be clipped or allocated the wrong height. Provide a fallback measurement/update 
mechanism or require the observer support used by this component. [possible bug]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ Expanded dashboard chart height can become stale.
   - ❌ Delayed descriptions may be clipped or leave excess space.
   - ⚠️ Jest environments without ResizeObserver cannot detect this regression.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Render an expanded dashboard chart through `Chart` in
   `superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.tsx`, 
with
   `isExpanded` true so the effect at lines 322-356 runs.
   
   2. Use a browser or test environment where `ResizeObserver` is undefined; 
the effect
   therefore skips the observer branch at lines 335-353.
   
   3. The effect measures `descriptionRef.current.offsetHeight` once at line 
329, before
   delayed markdown content changes the description element's height.
   
   4. After the description renders additional content, no callback or fallback 
measurement
   runs because lines 355-356 return without scheduling an update; 
`descriptionHeight`
   remains stale and the chart height calculation uses the old value.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=6afff0ee0fe1445dba467b5f0dd3dbf5&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=6afff0ee0fe1445dba467b5f0dd3dbf5&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.tsx
   **Line:** 335:355
   **Comment:**
        *Possible Bug: When `ResizeObserver` is unavailable, this effect only 
measures `offsetHeight` once. If the markdown description renders 
asynchronously afterward, `descriptionHeight` remains stale and the chart can 
be clipped or allocated the wrong height. Provide a fallback measurement/update 
mechanism or require the observer support used by this component.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42479&comment_hash=152d7b1ac738c8df8a2a86d19aaf7d502fff3508f51442436cfd67813c635391&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42479&comment_hash=152d7b1ac738c8df8a2a86d19aaf7d502fff3508f51442436cfd67813c635391&reaction=dislike'>👎</a>



-- 
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]

Reply via email to