Skip to content

Commit 2b3e314

Browse files
committed
perf(console): load the Setup pages and the view config panel on demand
The Setup and metadata pages registered in builtinComponents.tsx were imported by value, and ObjectView imported ViewConfigPanel statically, so the Packages page, its form dialog, the permission-matrix editor, SchemaForm and the Studio form widgets were all in the console's eager closure on every route. Each now loads behind lazy() with its Suspense boundary inside the registered value or around the panel. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5mmCUzPNeT1C9cHRtT
1 parent e3f0cfd commit 2b3e314

2 files changed

Lines changed: 82 additions & 24 deletions

File tree

‎ui/packages/app-shell/src/services/builtinComponents.tsx‎

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,13 @@
1515
* metadata type.
1616
*/
1717

18-
import { lazy, Suspense } from 'react';
18+
import { lazy, Suspense, type ComponentType } from 'react';
1919
import { registerAppComponent } from './componentRegistry.js';
2020
import { registerMetadataResource } from '../views/metadata-admin/registry.js';
21-
import { PermissionMatrixEditPage } from '../views/metadata-admin/PermissionMatrixEditor.js';
22-
import { PackagesPage } from '../views/metadata-admin/PackagesPage.js';
2321
import { PositionGrantedSetsCell, PositionHolderCountCell } from '../views/metadata-admin/PositionGrantCells.js';
24-
import { PackagedActionsPage } from '../views/setup/PackagedActionsPage.js';
25-
import { ConnectorCredentialsPage } from '../views/setup/ConnectorCredentialsPage.js';
2622
import { CONNECTOR_CREDENTIALS_REF } from '../views/setup/connectorCredentials.js';
27-
import { ConnectorConnectionsPage } from '../views/setup/ConnectorConnectionsPage.js';
2823
import { CONNECTOR_CONNECTIONS_REF } from '../views/setup/connectorConnections.js';
29-
import { PositionHoldersPage } from '../views/setup/PositionHoldersPage.js';
30-
import { PermissionSetAssignmentPage } from '../views/setup/PermissionSetAssignmentPage.js';
3124
import { PERMISSION_SET_ASSIGNMENT_REF, POSITION_HOLDERS_REF } from '../views/setup/peopleAssignments.js';
32-
import { RecycleBinPage } from '../views/setup/RecycleBinPage.js';
3325
import { RECYCLE_BIN_REF } from '../views/setup/recycleBin.js';
3426
import {
3527
isAggregatedViewContainer,
@@ -106,6 +98,63 @@ function MetadataAdminFallback({ label }: { label: string }) {
10698
return <div className="p-6 text-sm text-muted-foreground">Loading {label}…</div>;
10799
}
108100

101+
/**
102+
* A page registered BY REFERENCE to its module, loaded the first time it is
103+
* drawn (objectstack#33293). Every page below was imported here by value, and
104+
* this module is a side-effect import of the package entry, so each one, with
105+
* everything it imports, was in the console's EAGER closure: on a dashboard
106+
* route the browser downloaded the Packages page, its package form dialog, the
107+
* permission-matrix editor and the Setup assignment pages before it asked for
108+
* data. Measured from `apps/console/dist/eager-closure.json` and the emitted
109+
* chunks' module lists, not from a source search (see the trap above): with
110+
* these registrations lazy, the `PackageFormDialog` and
111+
* `PositionHoldersSection` chunks leave the closure.
112+
*
113+
* The same shape as the two registrations above: the `Suspense` boundary lives
114+
* inside the registered value, so `registerAppComponent` and
115+
* `registerMetadataResource` still receive a component, and no render site
116+
* learns about pending. ⛔ It only defers anything while nothing else in the
117+
* package's eager graph names the page module statically; the barrel's
118+
* `PackagedActionsPage` re-export is tree-shaken today because the console
119+
* imports no such name.
120+
*/
121+
function lazyPage<P extends object>(label: string, load: () => Promise<ComponentType<P>>): ComponentType<P> {
122+
const Page = lazy(() => load().then((component) => ({ default: component })));
123+
function LazyPage(props: P) {
124+
return (
125+
<Suspense fallback={<MetadataAdminFallback label={label} />}>
126+
<Page {...props} />
127+
</Suspense>
128+
);
129+
}
130+
return LazyPage;
131+
}
132+
133+
const PackagesPage = lazyPage('packages', () =>
134+
import('../views/metadata-admin/PackagesPage.js').then((m) => m.PackagesPage),
135+
);
136+
const PermissionMatrixEditPage = lazyPage('permission set', () =>
137+
import('../views/metadata-admin/PermissionMatrixEditor.js').then((m) => m.PermissionMatrixEditPage),
138+
);
139+
const PackagedActionsPage = lazyPage('packaged actions', () =>
140+
import('../views/setup/PackagedActionsPage.js').then((m) => m.PackagedActionsPage),
141+
);
142+
const ConnectorCredentialsPage = lazyPage('connector credentials', () =>
143+
import('../views/setup/ConnectorCredentialsPage.js').then((m) => m.ConnectorCredentialsPage),
144+
);
145+
const ConnectorConnectionsPage = lazyPage('connector connections', () =>
146+
import('../views/setup/ConnectorConnectionsPage.js').then((m) => m.ConnectorConnectionsPage),
147+
);
148+
const PositionHoldersPage = lazyPage('position holders', () =>
149+
import('../views/setup/PositionHoldersPage.js').then((m) => m.PositionHoldersPage),
150+
);
151+
const PermissionSetAssignmentPage = lazyPage('permission set assignments', () =>
152+
import('../views/setup/PermissionSetAssignmentPage.js').then((m) => m.PermissionSetAssignmentPage),
153+
);
154+
const RecycleBinPage = lazyPage('recycle bin', () =>
155+
import('../views/setup/RecycleBinPage.js').then((m) => m.RecycleBinPage),
156+
);
157+
109158
/**
110159
* The Suspense boundary lives INSIDE the registration value, which is the shape
111160
* every other lazy `registerAppComponent` entry already uses

‎ui/packages/app-shell/src/views/ObjectView.tsx‎

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ import { useServedViewItems } from '../hooks/useServedViewItems.js';
2828
import { servedObjectLabel, servedObjectPluralLabel } from '../hooks/servedObjectLabel.js';
2929
import type { DataSource } from '@object-ui/types';
3030
import { MetadataPanel, useMetadataInspector } from './MetadataInspector.js';
31-
import { ViewConfigPanel } from './ViewConfigPanel.js';
31+
// objectstack#33293: the view config panel loads with the first list, not with
32+
// the console. Statically, it held the view-variant inspector, `SchemaForm` and
33+
// the Studio form widgets in the EAGER closure, so a dashboard route downloaded
34+
// them too. It is drawn on every list (closed, it draws nothing), so its chunk
35+
// is fetched as the list mounts, before any admin can open it.
36+
const ViewConfigPanel = lazy(() =>
37+
import('./ViewConfigPanel.js').then((m) => ({ default: m.ViewConfigPanel })),
38+
);
3239
import { useMetadataClient } from './metadata-admin/useMetadata.js';
3340
import { dropPublishedViewList } from './metadata-admin/viewListDrop.js';
3441
import { CreateViewDialog } from './CreateViewDialog.js';
@@ -1369,20 +1376,22 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
13691376
showViewConfigPanel && isAdmin ? 'max-w-[280px] opacity-100' : 'max-w-0 opacity-0'
13701377
}`}
13711378
>
1372-
<ViewConfigPanel
1373-
open={showViewConfigPanel && isAdmin}
1374-
onClose={() => { setShowViewConfigPanel(false); setViewConfigPanelMode('edit'); }}
1375-
mode={viewConfigPanelMode}
1376-
activeView={activeView}
1377-
objectDef={objectDef}
1378-
recordCount={recordCount}
1379-
onSave={handleViewConfigSave}
1380-
onViewUpdate={handleViewUpdate}
1381-
onCreate={handleViewCreate}
1382-
metadataClient={metadataClient}
1383-
dataSource={dataSource}
1384-
onAfterChange={() => setRefreshKey(k => k + 1)}
1385-
/>
1379+
<Suspense fallback={null}>
1380+
<ViewConfigPanel
1381+
open={showViewConfigPanel && isAdmin}
1382+
onClose={() => { setShowViewConfigPanel(false); setViewConfigPanelMode('edit'); }}
1383+
mode={viewConfigPanelMode}
1384+
activeView={activeView}
1385+
objectDef={objectDef}
1386+
recordCount={recordCount}
1387+
onSave={handleViewConfigSave}
1388+
onViewUpdate={handleViewUpdate}
1389+
onCreate={handleViewCreate}
1390+
metadataClient={metadataClient}
1391+
dataSource={dataSource}
1392+
onAfterChange={() => setRefreshKey(k => k + 1)}
1393+
/>
1394+
</Suspense>
13861395
</div>
13871396
<CreateViewDialog
13881397
open={showCreateViewDialog && isAdmin}

0 commit comments

Comments
 (0)