Skip to content

Commit 2b7bf10

Browse files
committed
refactor(FR-2468): lazy-load 5 static pages and migrate lodash to lodash-es (#6422)
Resolves (FR-2468) ## Summary - Convert 5 statically imported pages (`ComputeSessionListPage`, `ModelStoreListPage`, `VFolderNodeListPage`, `ServingPage`, `Page404`) to `React.lazy()` in `routes.tsx`, enabling code splitting - Migrate all 222 lodash imports from `lodash` (CommonJS, not tree-shakeable) to `lodash-es` (ESM, tree-shakeable) across the codebase - Replace 2 lodash chain call sites (`_(array).map().some()`, `_(array).reduce()`) with native array methods / static `_.reduce()` - Add `lodash-es` and `@types/lodash-es` to pnpm catalog and react/package.json **Bundle impact** (main.js minified): - Before: **4.84 MB** - After: **~4.3 MB** (-540 KB, -11%) - App code: -498 KB (lazy loading) - lodash tree-shaking: -325 KB (546 KB → 221 KB) ## Test plan - [ ] Verify all pages load correctly (especially the 5 lazy-loaded pages) - [ ] Verify lodash utility functions work as expected - [ ] Run `pnpm run build` — no errors, main.js < 5 MB - [ ] TypeScript compiles without lodash-related errors
1 parent 2ab8e80 commit 2b7bf10

229 files changed

Lines changed: 345 additions & 238 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pnpm-lock.yaml

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ catalog:
2020
'@types/big.js': ^6.2.2
2121
'@types/jest': ^30.0.0
2222
'@types/lodash': ^4.17.24
23+
'@types/lodash-es': ^4.17.12
2324
'@types/node': ^22.19.15
2425
'@types/react': ^19.2.14
2526
'@types/react-copy-to-clipboard': ^5.0.7
@@ -48,6 +49,7 @@ catalog:
4849
jest-environment-jsdom: ^30.2.0
4950
jsonc-eslint-parser: ^2.4.2
5051
lodash: ^4.17.23
52+
lodash-es: ^4.17.21
5153
lucide-react: ^0.552.0
5254
marked: ^16.4.2
5355
prettier: ^3.8.1

react/jest.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
2323
},
2424
transformIgnorePatterns: [
25-
'node_modules/(?!(\\.pnpm/.+?/node_modules/(backend\\.ai-ui|nuqs)/|backend\\.ai-ui/|nuqs/))',
25+
'node_modules/(?!(\\.pnpm/.+?/node_modules/(backend\\.ai-ui|nuqs|lodash-es)/|backend\\.ai-ui/|nuqs/|lodash-es/))',
2626
`!${path.resolve(__dirname, '../packages/backend.ai-ui/src')}`,
2727
],
2828
transform: {

react/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"jotai-effect": "^2.2.3",
5151
"jotai-family": "^1.0.1",
5252
"katex": "^0.16.38",
53-
"lodash": "catalog:",
53+
"lodash-es": "catalog:",
5454
"lucide-react": "catalog:",
5555
"markdown-to-jsx": "^7.7.17",
5656
"marked": "catalog:",
@@ -124,6 +124,7 @@
124124
"@types/big.js": "catalog:",
125125
"@types/jest": "catalog:",
126126
"@types/lodash": "catalog:",
127+
"@types/lodash-es": "catalog:",
127128
"@types/node": "catalog:",
128129
"@types/react": "catalog:",
129130
"@types/react-copy-to-clipboard": "catalog:",

react/src/components/AccessKeySelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
import { AccessKeySelectQuery } from '../__generated__/AccessKeySelectQuery.graphql';
66
import { BAISelect, BAISelectProps } from 'backend.ai-ui';
7-
import _ from 'lodash';
7+
import * as _ from 'lodash-es';
88
import React from 'react';
99
import { useTranslation } from 'react-i18next';
1010
import { graphql, useLazyLoadQuery } from 'react-relay';

react/src/components/AgentDetailDrawerContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
toLocalId,
1616
} from 'backend.ai-ui';
1717
import dayjs from 'dayjs';
18-
import _ from 'lodash';
18+
import * as _ from 'lodash-es';
1919
import { useState } from 'react';
2020
import { useTranslation } from 'react-i18next';
2121
import { graphql, useFragment } from 'react-relay';

react/src/components/AgentDetailModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
BAIProgressWithLabel,
1717
convertToBinaryUnit,
1818
} from 'backend.ai-ui';
19-
import _ from 'lodash';
19+
import * as _ from 'lodash-es';
2020
import React from 'react';
2121
import { useTranslation } from 'react-i18next';
2222
import { graphql, useFragment } from 'react-relay';

react/src/components/AgentList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
BAIAgentTable,
2828
BAIUnmountAfterClose,
2929
} from 'backend.ai-ui';
30-
import _ from 'lodash';
30+
import * as _ from 'lodash-es';
3131
import { parseAsString, useQueryStates } from 'nuqs';
3232
import React, { useState, useDeferredValue } from 'react';
3333
import { useTranslation } from 'react-i18next';

react/src/components/AgentNodeItems/AgentComputePlugins.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Copyright (c) 2015-2026 Lablup Inc. All rights reserved.
44
*/
55
import { BAIDoubleTag, BAITag } from 'backend.ai-ui';
6-
import _ from 'lodash';
6+
import * as _ from 'lodash-es';
77
import { graphql, useFragment } from 'react-relay';
88
import { AgentComputePluginsFragment$key } from 'src/__generated__/AgentComputePluginsFragment.graphql';
99

react/src/components/AgentNodeItems/AgentResources.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
toFixedFloorWithoutTrailingZeros,
1919
useResourceSlotsDetails,
2020
} from 'backend.ai-ui';
21-
import _ from 'lodash';
21+
import * as _ from 'lodash-es';
2222
import { useState } from 'react';
2323
import { useTranslation } from 'react-i18next';
2424
import { graphql, useFragment } from 'react-relay';

0 commit comments

Comments
 (0)