Skip to content

Commit e4a91e9

Browse files
lazy routes
1 parent 04d4829 commit e4a91e9

File tree

2 files changed

+53
-24
lines changed

2 files changed

+53
-24
lines changed

client/packages/lowcoder/src/app.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ import { reduxStore } from "redux/store/store";
3333
import { developEnv } from "util/envUtils";
3434
import history from "util/history";
3535
import LazyRoute from "components/LazyRoute";
36-
import AppFromTemplate from "pages/ApplicationV2/AppFromTemplate";
37-
import AppEditor from "pages/editor/AppEditor";
36+
// import AppFromTemplate from "pages/ApplicationV2/AppFromTemplate";
37+
// import AppEditor from "pages/editor/AppEditor";
3838
import { getAntdLocale } from "i18n/antdLocale";
3939
import { ProductLoading } from "components/ProductLoading";
4040
import { language, trans } from "i18n";
4141
import { loadComps } from "comps";
4242
import { initApp } from "util/commonUtils";
43-
import ApplicationHome from "./pages/ApplicationV2";
43+
// import ApplicationHome from "./pages/ApplicationV2";
4444
import { favicon } from "@lowcoder-ee/assets/images";
4545
import { hasQueryParam } from "util/urlUtils";
4646
import { isFetchUserFinished } from "redux/selectors/usersSelectors";
@@ -53,6 +53,9 @@ const LazyUserAuthComp = React.lazy(() => import("pages/userAuth"));
5353
const LazyInviteLanding = React.lazy(() => import("pages/common/inviteLanding"));
5454
const LazyComponentDoc = React.lazy(() => import("pages/ComponentDoc"));
5555
const LazyComponentPlayground = React.lazy(() => import("pages/ComponentPlayground"));
56+
const LazyAppEditor = React.lazy(() => import("pages/editor/AppEditor"));
57+
const LazyAppFromTemplate = React.lazy(() => import("pages/ApplicationV2/AppFromTemplate"));
58+
const LazyApplicationHome = React.lazy(() => import("pages/ApplicationV2"));
5659
const LazyDebugComp = React.lazy(() => import("./debug"));
5760
const LazyDebugNewComp = React.lazy(() => import("./debugNew"));
5861

@@ -124,9 +127,9 @@ class AppIndex extends React.Component<AppIndexProps, any> {
124127
to={APPLICATION_VIEW_URL(this.props.defaultHomePage, "view")}
125128
/>
126129
)}
127-
<Route exact path={IMPORT_APP_FROM_TEMPLATE_URL} component={AppFromTemplate} />
128-
<Route path={APP_EDITOR_URL} component={AppEditor} />
129-
<Route
130+
<LazyRoute exact path={IMPORT_APP_FROM_TEMPLATE_URL} component={LazyAppFromTemplate} />
131+
<LazyRoute path={APP_EDITOR_URL} component={LazyAppEditor} />
132+
<LazyRoute
130133
path={[
131134
ALL_APPLICATIONS_URL,
132135
DATASOURCE_CREATE_URL,
@@ -139,7 +142,7 @@ class AppIndex extends React.Component<AppIndexProps, any> {
139142
SETTING,
140143
]}
141144
// component={ApplicationListPage}
142-
component={ApplicationHome}
145+
component={LazyApplicationHome}
143146
/>
144147
<LazyRoute path={USER_AUTH_URL} component={LazyUserAuthComp} />
145148
<LazyRoute path={ORG_AUTH_LOGIN_URL} component={LazyUserAuthComp} />
@@ -153,7 +156,7 @@ class AppIndex extends React.Component<AppIndexProps, any> {
153156
<>
154157
<LazyRoute path="/debug_comp/:name" component={LazyDebugComp} />
155158
<LazyRoute exact path="/debug_comp" component={LazyDebugComp} />
156-
<Route path="/debug_editor" component={AppEditor} />
159+
<LazyRoute path="/debug_editor" component={LazyAppEditor} />
157160
<LazyRoute path="/debug_new" component={LazyDebugNewComp} />
158161
</>
159162
)}

client/packages/lowcoder/src/pages/ApplicationV2/index.tsx

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,52 @@ import {
3434
import React, { useEffect, useState } from "react";
3535
import { fetchAllApplications, fetchHomeData } from "redux/reduxActions/applicationActions";
3636
import { getHomeOrg, normalAppListSelector } from "redux/selectors/applicationSelector";
37-
import { DatasourceHome } from "../datasource";
37+
// import { DatasourceHome } from "../datasource";
3838
import { clearStyleEval, evalStyle } from "lowcoder-core";
39-
import { QueryLibraryEditor } from "../queryLibrary/QueryLibraryEditor";
39+
// import { QueryLibraryEditor } from "../queryLibrary/QueryLibraryEditor";
4040
import { ProductLoading } from "components/ProductLoading";
4141
import { Layout } from "../../components/layout/Layout";
42-
import { HomeView } from "./HomeView";
42+
// import { HomeView } from "./HomeView";
4343
import styled, { css } from "styled-components";
4444
import history from "../../util/history";
45-
import { FolderView } from "./FolderView";
46-
import { TrashView } from "./TrashView";
45+
// import { FolderView } from "./FolderView";
46+
// import { TrashView } from "./TrashView";
4747
import { SideBarItemType } from "../../components/layout/SideBarSection";
48-
import { RootFolderListView } from "./RootFolderListView";
48+
// import { RootFolderListView } from "./RootFolderListView";
4949
import InviteDialog from "../common/inviteDialog";
5050
import { fetchFolderElements, updateFolder } from "../../redux/reduxActions/folderActions";
51-
import { ModuleView } from "./ModuleView";
51+
// import { ModuleView } from "./ModuleView";
5252
import { useCreateFolder } from "./useCreateFolder";
5353
import { trans } from "../../i18n";
5454
import { foldersSelector } from "../../redux/selectors/folderSelector";
55-
import Setting from "pages/setting";
55+
// import Setting from "pages/setting";
5656
import { TypographyText } from "../../components/TypographyText";
5757
import { messageInstance } from "lowcoder-design";
5858

59+
const LazyFolderView = React.lazy(
60+
() => import("./FolderView").then(module => ({default: module.FolderView}))
61+
);
62+
const LazyRootFolderListView = React.lazy(
63+
() => import("./RootFolderListView").then(module => ({default: module.RootFolderListView}))
64+
);
65+
const LazyTrashView = React.lazy(
66+
() => import("./TrashView").then(module => ({default: module.TrashView}))
67+
);
68+
const LazyModuleView = React.lazy(
69+
() => import("./ModuleView").then(module => ({default: module.ModuleView}))
70+
);
71+
const LazyHomeView = React.lazy(
72+
() => import("./HomeView").then(module => ({default: module.HomeView}))
73+
);
74+
const LazyDatasourceHome = React.lazy(
75+
() => import("../datasource").then(module => ({default: module.DatasourceHome}))
76+
);
77+
const LazyQueryLibraryEditor = React.lazy(
78+
() => import("../queryLibrary/QueryLibraryEditor").then(module => ({default: module.QueryLibraryEditor}))
79+
);
80+
const LazySetting = React.lazy(() => import("pages/setting"));
81+
82+
5983
const TabLabel = styled.div`
6084
font-weight: 500;
6185
`;
@@ -298,7 +322,8 @@ export default function ApplicationHome() {
298322
),
299323
routePath: FOLDER_URL,
300324
routePathExact: false,
301-
routeComp: FolderView,
325+
// routeComp: FolderView,
326+
routeComp: LazyFolderView,
302327
icon: FolderIcon,
303328
size: "small",
304329
onClick: (currentPath) => currentPath !== path && history.push(path),
@@ -313,7 +338,7 @@ export default function ApplicationHome() {
313338
<MoreFoldersWrapper $selected={Boolean(props.selected)}>{trans("more")}</MoreFoldersWrapper>
314339
),
315340
routePath: FOLDERS_URL,
316-
routeComp: RootFolderListView,
341+
routeComp: LazyRootFolderListView,
317342
icon: MoreFoldersIcon,
318343
size: "small",
319344
},
@@ -336,14 +361,14 @@ export default function ApplicationHome() {
336361
{
337362
text: <TabLabel>{trans("home.allApplications")}</TabLabel>,
338363
routePath: ALL_APPLICATIONS_URL,
339-
routeComp: HomeView,
364+
routeComp: LazyHomeView,
340365
icon: ({ selected, ...otherProps }) =>
341366
selected ? <HomeActiveIcon {...otherProps} /> : <HomeIcon {...otherProps} />,
342367
},
343368
{
344369
text: <TabLabel>{trans("home.modules")}</TabLabel>,
345370
routePath: MODULE_APPLICATIONS_URL,
346-
routeComp: ModuleView,
371+
routeComp: LazyModuleView,
347372
icon: ({ selected, ...otherProps }) =>
348373
selected ? (
349374
<HomeModuleActiveIcon {...otherProps} />
@@ -355,7 +380,8 @@ export default function ApplicationHome() {
355380
{
356381
text: <TabLabel>{trans("home.trash")}</TabLabel>,
357382
routePath: TRASH_URL,
358-
routeComp: TrashView,
383+
// routeComp: TrashView,
384+
routeComp: LazyTrashView,
359385
icon: ({ selected, ...otherProps }) =>
360386
selected ? (
361387
<RecyclerActiveIcon {...otherProps} />
@@ -388,7 +414,7 @@ export default function ApplicationHome() {
388414
{
389415
text: <TabLabel>{trans("home.queryLibrary")}</TabLabel>,
390416
routePath: QUERY_LIBRARY_URL,
391-
routeComp: QueryLibraryEditor,
417+
routeComp: LazyQueryLibraryEditor,
392418
icon: ({ selected, ...otherProps }) =>
393419
selected ? (
394420
<HomeQueryLibraryActiveIcon {...otherProps} />
@@ -401,7 +427,7 @@ export default function ApplicationHome() {
401427
text: <TabLabel>{trans("home.datasource")}</TabLabel>,
402428
routePath: DATASOURCE_URL,
403429
routePathExact: false,
404-
routeComp: DatasourceHome,
430+
routeComp: LazyDatasourceHome,
405431
icon: ({ selected, ...otherProps }) =>
406432
selected ? (
407433
<HomeDataSourceActiveIcon {...otherProps} />
@@ -415,7 +441,7 @@ export default function ApplicationHome() {
415441
text: <TabLabel>{trans("settings.title")}</TabLabel>,
416442
routePath: SETTING,
417443
routePathExact: false,
418-
routeComp: Setting,
444+
routeComp: LazySetting,
419445
icon: ({ selected, ...otherProps }) =>
420446
selected ? (
421447
<HomeSettingsActiveIcon {...otherProps} />

0 commit comments

Comments
 (0)