rusackas commented on code in PR #45605:
URL: https://github.com/apache/superset/pull/45605#discussion_r4353771521


##########
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:
   Good catch. The branch had reverted the bootstrap/window pack path in 
`preamble.ts`; I restored it and only the `dayjs` locale mapping differs now.



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