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


##########
superset-frontend/packages/superset-ui-core/src/components/AsyncAceEditor/index.tsx:
##########
@@ -281,6 +282,30 @@ export function AsyncAceEditor(
           };
         }, [ref]);
 
+        // Ace caches the measured glyph width in its internal FontMetrics and
+        // only re-measures when its hidden measure node's own size changes. If
+        // the editor font finishes loading after construction, the cached 
width
+        // can stop matching the rendered glyphs and the caret drifts further
+        // from the text the longer the line, the residual misalignment in 
issue
+        // #41664 that the font-family CSS from #38928 does not address. Force 
a
+        // re-measure once the document's fonts have settled (and immediately,
+        // for the already-loaded case) so the caret stays aligned.
+        // `updateFontSize` runs Ace's `checkForSizeChanges`, which on a 
metrics
+        // change emits `changeCharacterSize`; Ace's renderer reacts with a
+        // forced resize and full re-render, so no explicit resize call is
+        // needed here.
+        const handleLoad = useCallback(
+          (editor: Ace.Editor) => {
+            const remeasure = () => {
+              editor.renderer.updateFontSize();
+            };
+            remeasure();
+            document.fonts?.ready?.then(remeasure).catch(() => {});

Review Comment:
   **Suggestion:** The optional chaining stops before `.catch`, so when 
`document.fonts` or `document.fonts.ready` is unavailable this expression 
evaluates to `undefined` and then immediately throws at runtime when accessing 
`.catch`. Guard the whole promise chain (including the catch call) or branch 
before chaining so editors still load safely in environments without the Font 
Loading API. [type error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   ❌ Ace-backed editors crash in environments without document.fonts.
   ⚠️ SQL Lab SQLEditor fails to mount in affected browsers.
   ⚠️ MarkdownEditor in dashboards broken when Font Loading API missing.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. In
   
`superset-frontend/packages/superset-ui-core/src/components/AsyncAceEditor/index.tsx:495-496`,
   `ReactAceEditor` is rendered with `onLoad={handleLoad}`, ensuring 
`handleLoad` runs
   whenever an Ace editor instance finishes loading.
   
   2. The `handleLoad` callback in the same file calls
   `document.fonts?.ready?.then(remeasure).catch(() => {});` at line 303 
(verified via Grep),
   immediately after invoking `remeasure()`.
   
   3. In an environment where the Font Loading API is absent or incomplete (for 
example,
   jsdom, where `document.fonts.ready` is described as “not implemented” in
   `superset-frontend/src/utils/downloadAsImage.test.ts:41-42`), the optional 
chain
   `document.fonts?.ready?.then(remeasure)` evaluates to `undefined`, and then 
the
   non-optional `.catch` access on that `undefined` value throws a `TypeError` 
at
   `index.tsx:303`.
   
   4. Render any component backed by `AsyncAceEditor`, such as `SQLEditor` 
instantiated in
   
`superset-frontend/packages/superset-ui-core/src/components/AsyncAceEditor/AsyncAceEditor.test.tsx:39`
   (`render(<SQLEditor />)`); when Ace completes loading and calls 
`handleLoad`, the
   `TypeError` from step 3 occurs, causing the editor initialization to fail in 
environments
   without a working `document.fonts.ready`.
   ```
   </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=858a591f9e5a4c0fb275873df4ac581b&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=858a591f9e5a4c0fb275873df4ac581b&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/packages/superset-ui-core/src/components/AsyncAceEditor/index.tsx
   **Line:** 303:303
   **Comment:**
        *Type Error: The optional chaining stops before `.catch`, so when 
`document.fonts` or `document.fonts.ready` is unavailable this expression 
evaluates to `undefined` and then immediately throws at runtime when accessing 
`.catch`. Guard the whole promise chain (including the catch call) or branch 
before chaining so editors still load safely in environments without the Font 
Loading API.
   
   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%2F41697&comment_hash=3b21f67239a77feab03c28c75e14f0904a8cf224e9efcc232c74300f726ea39d&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41697&comment_hash=3b21f67239a77feab03c28c75e14f0904a8cf224e9efcc232c74300f726ea39d&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