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


##########
superset-frontend/src/preamble.ts:
##########
@@ -64,65 +64,40 @@ export default function initPreamble(): Promise<void> {
     // Setup SupersetClient early so we can fetch language pack
     setupClient({ appRoot: applicationRoot() });
 
-    // Initialize feature flags before the first await below. Not every
-    // entry point awaits initPreamble() before importing plugins (see
-    // webpack.config.js's addPreamble()), and plugin modules can call
-    // isFeatureEnabled() during import, which would see stale/missing
-    // flags if this ran after the language-pack fetch instead. See #37310.
-    initFeatureFlags(bootstrapData.common.feature_flags);
-
-    // Load language pack before rendering.
-    // Prefer the pack already on hand: either an operator-supplied
-    // common.language_pack (COMMON_BOOTSTRAP_OVERRIDES_FUNC) or the
-    // window global set by the versioned script tag spa.html loads
-    // before this bundle. Either way, module-level `const X = t('...')`
-    // calls in code-split chunks all see a configured translator. Fall
-    // back to the async fetch only when neither is present (e.g. the
-    // script tag failed to load, or a legacy entry that doesn't extend
-    // spa.html). See issue #35330.
+    // Load language pack before rendering
+    // Use native fetch to avoid race condition with SupersetClient 
initialization
     if (lang !== 'en') {
-      const bootstrapPack =
-        (bootstrapData.common as { language_pack?: LanguagePack })
-          .language_pack ??
-        (typeof window !== 'undefined'
-          ? window.__SUPERSET_LANGUAGE_PACK__
-          : undefined);
-      if (bootstrapPack) {
-        configure({ languagePack: bootstrapPack });
-        dayjs.locale(lang);
-      } else {
-        const abortController = new AbortController();
-        const timeoutId = window.setTimeout(() => {
-          abortController.abort();
-        }, LANGUAGE_PACK_REQUEST_TIMEOUT_MS);
-
-        try {
-          const languagePackUrl = makeUrl(`/language_pack/${lang}/`);
-          const resp = await fetch(languagePackUrl, {
-            signal: abortController.signal,
-          });
-          if (!resp.ok) {
-            throw new Error(`Failed to fetch language pack: ${resp.status}`);
-          }
-          const json = await resp.json();
-          configure({ languagePack: json as LanguagePack });
-          if (typeof window !== 'undefined') {
-            window.__SUPERSET_LANGUAGE_PACK__ = json as LanguagePack;
-          }
-          dayjs.locale(lang);
-        } catch (err) {
-          logging.warn(
-            'Failed to fetch language pack, falling back to default.',
-            err,
-          );
-          configure();
-          dayjs.locale('en');
-        } finally {
-          window.clearTimeout(timeoutId);
+      const abortController = new AbortController();
+      const timeoutId = window.setTimeout(() => {
+        abortController.abort();
+      }, LANGUAGE_PACK_REQUEST_TIMEOUT_MS);
+
+      try {
+        const languagePackUrl = makeUrl(`/superset/language_pack/${lang}/`);
+        const resp = await fetch(languagePackUrl, {
+          signal: abortController.signal,
+        });
+        if (!resp.ok) {
+          throw new Error(`Failed to fetch language pack: ${resp.status}`);
         }
+        const json = await resp.json();
+        configure({ languagePack: json as LanguagePack });

Review Comment:
   **Suggestion:** This replaces a server-supplied operator language pack with 
the fetched catalog; if the request fails, the catch also resets translations 
to English.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Logic error`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![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=a7274ca9224b40249271079e445d639a&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=a7274ca9224b40249271079e445d639a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/src/preamble.ts
   **Line:** 84:84
   **Comment:**
        *Logic Error: This replaces a server-supplied operator language pack 
with the fetched catalog; if the request fails, the catch also resets 
translations to English.
   
   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%2F45605&comment_hash=9e7cfd376b7588ad030f72d7228f96db500bbc59bddc7242a15dcda70b88b28a&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45605&comment_hash=9e7cfd376b7588ad030f72d7228f96db500bbc59bddc7242a15dcda70b88b28a&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