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


##########
superset-frontend/src/preamble.ts:
##########
@@ -27,7 +27,7 @@ import setupDashboardComponents from 
'./setup/setupDashboardComponents';
 import { User } from './types/bootstrapTypes';
 import getBootstrapData, { applicationRoot } from './utils/getBootstrapData';
 import { makeUrl } from './utils/pathUtils';
-import './hooks/useLocale';
+import { DAYJS_LOCALE_MAPPING } from './hooks/useLocale';

Review Comment:
   **Suggestion:** Importing `DAYJS_LOCALE_MAPPING` from `./hooks/useLocale` 
pulls in the entire hook module on the bootstrap path, including React/Redux 
hook dependencies and all dayjs locale side-effect imports. This increases 
initial bundle work for every entrypoint and can create fragile initialization 
coupling between preamble and UI hook code. Move the dayjs locale mapping to a 
small shared constants module (without hook imports/side effects) and import 
that from both `preamble.ts` and `useLocale.ts`. [performance]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ All entrypoints eagerly load React/Redux via preamble.
   - ⚠️ Dayjs locale side-effects run on every bootstrap.
   - ⚠️ Increased initial JS bundle size for all entrypoints.
   - ⚠️ Tighter coupling between bootstrap and UI hooks module.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Build or run any frontend entrypoint where 
`superset-frontend/src/preamble.ts` is
   prepended; this is stated explicitly in `preamble.ts` lines 131–133 (`// 
This module is
   prepended to multiple webpack entrypoints`).
   
   2. During bundling, the new import at `preamble.ts:30` (`import { 
DAYJS_LOCALE_MAPPING }
   from './hooks/useLocale';`) causes webpack to include the entire
   `superset-frontend/src/hooks/useLocale.ts` module in the preamble chunk.
   
   3. The `useLocale.ts` module (lines 19–22) imports React and Redux hooks 
(`useEffect`,
   `useState` from `react`, `useSelector` from `react-redux`), and lines 23–38 
import many
   dayjs locale side-effect modules (`'dayjs/locale/en'`, `'dayjs/locale/fr'`,
   `'dayjs/locale/zh-cn'`, `'dayjs/locale/zh-tw'`, etc.), all of which are 
executed when the
   module is loaded, regardless of whether the `useLocale` hook is ever used on 
that
   entrypoint.
   
   4. Because `preamble.ts` runs on every prepended entrypoint, this change 
forces
   React/Redux and all dayjs locales defined in `useLocale.ts` to be eagerly 
loaded and
   executed during bootstrap for all entrypoints, including ones that do not 
use the
   `useLocale` hook, increasing initial JS size and startup work. Moving
   `DAYJS_LOCALE_MAPPING` into a small side-effect-free constants module and 
importing that
   from both `preamble.ts` and `useLocale.ts` would avoid pulling in these 
extra dependencies
   on the bootstrap path.
   ```
   </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=969dd9e3ce0045469101781ab8c11062&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=969dd9e3ce0045469101781ab8c11062&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/preamble.ts
   **Line:** 30:30
   **Comment:**
        *Performance: Importing `DAYJS_LOCALE_MAPPING` from `./hooks/useLocale` 
pulls in the entire hook module on the bootstrap path, including React/Redux 
hook dependencies and all dayjs locale side-effect imports. This increases 
initial bundle work for every entrypoint and can create fragile initialization 
coupling between preamble and UI hook code. Move the dayjs locale mapping to a 
small shared constants module (without hook imports/side effects) and import 
that from both `preamble.ts` and `useLocale.ts`.
   
   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%2F39667&comment_hash=93dd710a6e2195e3ac100a69bb8c37035745abf03c8a0376092deba2215bc42b&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39667&comment_hash=93dd710a6e2195e3ac100a69bb8c37035745abf03c8a0376092deba2215bc42b&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