Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/33293-console-eager-closure-setup-pages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@object-ui/console': patch
---

perf(console): the first load no longer downloads the Setup pages, the package form and the view config panel

Clause-②: no
Metadata-protocol: none

Every Console route, a dashboard included, used to download the Packages page with its package form dialog, the permission-set editor, the Setup pages for packaged actions, connector credentials, connector connections, position holders, permission-set assignment and the recycle bin, and the list view's config panel with the Studio form widgets it draws, before the app asked for any data. These now load the first time they are drawn: a Setup page when its entry is opened, the view config panel as a list mounts. The Console's eager closure (`dist/eager-closure.json`) goes from 2,293,387 to 2,163,688 bytes gzipped (−129,699), measured on two builds of the same tree. What each route draws is unchanged; a Setup page shows a one-line loading notice while its code arrives.
67 changes: 58 additions & 9 deletions ui/packages/app-shell/src/services/builtinComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,13 @@
* metadata type.
*/

import { lazy, Suspense } from 'react';
import { lazy, Suspense, type ComponentType } from 'react';
import { registerAppComponent } from './componentRegistry.js';
import { registerMetadataResource } from '../views/metadata-admin/registry.js';
import { PermissionMatrixEditPage } from '../views/metadata-admin/PermissionMatrixEditor.js';
import { PackagesPage } from '../views/metadata-admin/PackagesPage.js';
import { PositionGrantedSetsCell, PositionHolderCountCell } from '../views/metadata-admin/PositionGrantCells.js';
import { PackagedActionsPage } from '../views/setup/PackagedActionsPage.js';
import { ConnectorCredentialsPage } from '../views/setup/ConnectorCredentialsPage.js';
import { CONNECTOR_CREDENTIALS_REF } from '../views/setup/connectorCredentials.js';
import { ConnectorConnectionsPage } from '../views/setup/ConnectorConnectionsPage.js';
import { CONNECTOR_CONNECTIONS_REF } from '../views/setup/connectorConnections.js';
import { PositionHoldersPage } from '../views/setup/PositionHoldersPage.js';
import { PermissionSetAssignmentPage } from '../views/setup/PermissionSetAssignmentPage.js';
import { PERMISSION_SET_ASSIGNMENT_REF, POSITION_HOLDERS_REF } from '../views/setup/peopleAssignments.js';
import { RecycleBinPage } from '../views/setup/RecycleBinPage.js';
import { RECYCLE_BIN_REF } from '../views/setup/recycleBin.js';
import {
isAggregatedViewContainer,
Expand Down Expand Up @@ -106,6 +98,63 @@ function MetadataAdminFallback({ label }: { label: string }) {
return <div className="p-6 text-sm text-muted-foreground">Loading {label}…</div>;
}

/**
* A page registered BY REFERENCE to its module, loaded the first time it is
* drawn (objectstack#33293). Every page below was imported here by value, and
* this module is a side-effect import of the package entry, so each one, with
* everything it imports, was in the console's EAGER closure: on a dashboard
* route the browser downloaded the Packages page, its package form dialog, the
* permission-matrix editor and the Setup assignment pages before it asked for
* data. Measured from `apps/console/dist/eager-closure.json` and the emitted
* chunks' module lists, not from a source search (see the trap above): with
* these registrations lazy, the `PackageFormDialog` and
* `PositionHoldersSection` chunks leave the closure.
*
* The same shape as the two registrations above: the `Suspense` boundary lives
* inside the registered value, so `registerAppComponent` and
* `registerMetadataResource` still receive a component, and no render site
* learns about pending. ⛔ It only defers anything while nothing else in the
* package's eager graph names the page module statically; the barrel's
* `PackagedActionsPage` re-export is tree-shaken today because the console
* imports no such name.
*/
function lazyPage<P extends object>(label: string, load: () => Promise<ComponentType<P>>): ComponentType<P> {
const Page = lazy(() => load().then((component) => ({ default: component })));
function LazyPage(props: P) {
return (
<Suspense fallback={<MetadataAdminFallback label={label} />}>
<Page {...props} />
</Suspense>
);
}
return LazyPage;
}

const PackagesPage = lazyPage('packages', () =>
import('../views/metadata-admin/PackagesPage.js').then((m) => m.PackagesPage),
);
const PermissionMatrixEditPage = lazyPage('permission set', () =>
import('../views/metadata-admin/PermissionMatrixEditor.js').then((m) => m.PermissionMatrixEditPage),
);
const PackagedActionsPage = lazyPage('packaged actions', () =>
import('../views/setup/PackagedActionsPage.js').then((m) => m.PackagedActionsPage),
);
const ConnectorCredentialsPage = lazyPage('connector credentials', () =>
import('../views/setup/ConnectorCredentialsPage.js').then((m) => m.ConnectorCredentialsPage),
);
const ConnectorConnectionsPage = lazyPage('connector connections', () =>
import('../views/setup/ConnectorConnectionsPage.js').then((m) => m.ConnectorConnectionsPage),
);
const PositionHoldersPage = lazyPage('position holders', () =>
import('../views/setup/PositionHoldersPage.js').then((m) => m.PositionHoldersPage),
);
const PermissionSetAssignmentPage = lazyPage('permission set assignments', () =>
import('../views/setup/PermissionSetAssignmentPage.js').then((m) => m.PermissionSetAssignmentPage),
);
const RecycleBinPage = lazyPage('recycle bin', () =>
import('../views/setup/RecycleBinPage.js').then((m) => m.RecycleBinPage),
);

/**
* The Suspense boundary lives INSIDE the registration value, which is the shape
* every other lazy `registerAppComponent` entry already uses
Expand Down
39 changes: 24 additions & 15 deletions ui/packages/app-shell/src/views/ObjectView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ import { useServedViewItems } from '../hooks/useServedViewItems.js';
import { servedObjectLabel, servedObjectPluralLabel } from '../hooks/servedObjectLabel.js';
import type { DataSource } from '@object-ui/types';
import { MetadataPanel, useMetadataInspector } from './MetadataInspector.js';
import { ViewConfigPanel } from './ViewConfigPanel.js';
// objectstack#33293: the view config panel loads with the first list, not with
// the console. Statically, it held the view-variant inspector, `SchemaForm` and
// the Studio form widgets in the EAGER closure, so a dashboard route downloaded
// them too. It is drawn on every list (closed, it draws nothing), so its chunk
// is fetched as the list mounts, before any admin can open it.
const ViewConfigPanel = lazy(() =>
import('./ViewConfigPanel.js').then((m) => ({ default: m.ViewConfigPanel })),
);
import { useMetadataClient } from './metadata-admin/useMetadata.js';
import { dropPublishedViewList } from './metadata-admin/viewListDrop.js';
import { CreateViewDialog } from './CreateViewDialog.js';
Expand Down Expand Up @@ -1369,20 +1376,22 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
showViewConfigPanel && isAdmin ? 'max-w-[280px] opacity-100' : 'max-w-0 opacity-0'
}`}
>
<ViewConfigPanel
open={showViewConfigPanel && isAdmin}
onClose={() => { setShowViewConfigPanel(false); setViewConfigPanelMode('edit'); }}
mode={viewConfigPanelMode}
activeView={activeView}
objectDef={objectDef}
recordCount={recordCount}
onSave={handleViewConfigSave}
onViewUpdate={handleViewUpdate}
onCreate={handleViewCreate}
metadataClient={metadataClient}
dataSource={dataSource}
onAfterChange={() => setRefreshKey(k => k + 1)}
/>
<Suspense fallback={null}>
<ViewConfigPanel
open={showViewConfigPanel && isAdmin}
onClose={() => { setShowViewConfigPanel(false); setViewConfigPanelMode('edit'); }}
mode={viewConfigPanelMode}
activeView={activeView}
objectDef={objectDef}
recordCount={recordCount}
onSave={handleViewConfigSave}
onViewUpdate={handleViewUpdate}
onCreate={handleViewCreate}
metadataClient={metadataClient}
dataSource={dataSource}
onAfterChange={() => setRefreshKey(k => k + 1)}
/>
</Suspense>
</div>
<CreateViewDialog
open={showCreateViewDialog && isAdmin}
Expand Down
Loading