|
15 | 15 | * metadata type. |
16 | 16 | */ |
17 | 17 |
|
18 | | -import { lazy, Suspense } from 'react'; |
| 18 | +import { lazy, Suspense, type ComponentType } from 'react'; |
19 | 19 | import { registerAppComponent } from './componentRegistry.js'; |
20 | 20 | 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'; |
23 | 21 | 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'; |
26 | 22 | import { CONNECTOR_CREDENTIALS_REF } from '../views/setup/connectorCredentials.js'; |
27 | | -import { ConnectorConnectionsPage } from '../views/setup/ConnectorConnectionsPage.js'; |
28 | 23 | 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'; |
31 | 24 | import { PERMISSION_SET_ASSIGNMENT_REF, POSITION_HOLDERS_REF } from '../views/setup/peopleAssignments.js'; |
32 | | -import { RecycleBinPage } from '../views/setup/RecycleBinPage.js'; |
33 | 25 | import { RECYCLE_BIN_REF } from '../views/setup/recycleBin.js'; |
34 | 26 | import { |
35 | 27 | isAggregatedViewContainer, |
@@ -106,6 +98,63 @@ function MetadataAdminFallback({ label }: { label: string }) { |
106 | 98 | return <div className="p-6 text-sm text-muted-foreground">Loading {label}…</div>; |
107 | 99 | } |
108 | 100 |
|
| 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 | + |
109 | 158 | /** |
110 | 159 | * The Suspense boundary lives INSIDE the registration value, which is the shape |
111 | 160 | * every other lazy `registerAppComponent` entry already uses |
|
0 commit comments