bito-code-review[bot] commented on PR #42479:
URL: https://github.com/apache/superset/pull/42479#issuecomment-5091821524

   <!-- Bito Reply -->
   The flagged issue is correct. The current implementation in `Chart.tsx` only 
measures the description height once when `ResizeObserver` is unavailable, 
which fails to account for asynchronous content updates. 
   
   To resolve this, you can implement a `MutationObserver` as a fallback when 
`ResizeObserver` is not supported. This will monitor changes to the description 
element's subtree and trigger a re-measurement.
   
   ### Proposed Fix
   
   ```tsx
       // ... inside useLayoutEffect
       if (typeof ResizeObserver !== 'undefined') {
         // ... existing ResizeObserver logic
       } else if (typeof MutationObserver !== 'undefined' && 
descriptionRef.current) {
         const observer = new MutationObserver(() => {
           if (descriptionRef.current) {
             setDescriptionHeight(descriptionRef.current.offsetHeight);
           }
         });
         observer.observe(descriptionRef.current, { childList: true, subtree: 
true, characterData: true });
         return () => observer.disconnect();
       }
   
       return undefined;
   ```
   
   Would you like me to check the other comments on this PR and implement fixes 
for them as well?
   
   **superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.tsx**
   ```
   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();
         };
       } else if (typeof MutationObserver !== 'undefined' && 
descriptionRef.current) {
         const observer = new MutationObserver(() => {
           if (descriptionRef.current) {
             setDescriptionHeight(descriptionRef.current.offsetHeight);
           }
         });
         observer.observe(descriptionRef.current, { childList: true, subtree: 
true, characterData: true });
         return () => observer.disconnect();
       }
   ```


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