Skip to content

Commit dba2847

Browse files
committed
perf(console): Studio en strings and metadata-form strings load with the screens that read them
The default Studio canvas moves to its own module and registers through lazyPage, which moves to services/lazyPage.tsx so every such registration shares one wrapper. The datasource page, the position list's two cells, the create-view dialog and the Pending changes sheet load on first draw. The studio namespace loader gets its own chunk group, so the eager i18n-runtime chunk stops carrying its static en edge. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5ousB2MKFUbJFc3Hwp
1 parent 3c0033f commit dba2847

8 files changed

Lines changed: 394 additions & 264 deletions

File tree

‎ui/apps/console/vite.config.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,16 @@ export default defineConfig({
12351235
// `en` is the namespace's resident fallback and gets its own chunk so
12361236
// its bytes are named in `eager-closure.json` instead of hiding in
12371237
// the runtime's.
1238+
//
1239+
// The loader module (`index.ts`, which imports `en` statically: the
1240+
// synchronous fallback, objectstack#25922) gets a group too, for the
1241+
// marketplace loader's reason below: without one it falls to the
1242+
// eager `i18n-runtime` group, and its static `en` edge put the 64 KB
1243+
// `en` catalogue on every console route, though only the Studio
1244+
// and Setup screens that import `metadata-admin/i18n.ts` read it
1245+
// (objectstack#33582). `includeDependenciesRecursively: false` for
1246+
// the same measured reason as the marketplace loader's.
1247+
{ name: 'i18n-ns-studio', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]studio[\\/]index\.ts$/, priority: 84, includeDependenciesRecursively: false },
12381248
{ name: 'i18n-ns-studio-en', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]studio[\\/]en\.ts$/, priority: 84 },
12391249
{ name: 'i18n-ns-studio-zh', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]studio[\\/]zh\.ts$/, priority: 84 },
12401250
//

‎ui/packages/app-shell/src/preview/DraftPreviewBar.tsx‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,22 @@
1414
* keeps a read-only preview from ever being confused with the live app.
1515
*/
1616

17-
import { useEffect, useMemo, useState } from 'react';
17+
import { lazy, Suspense, useEffect, useMemo, useState } from 'react';
1818
import { useLocation, useNavigate, useParams } from 'react-router-dom';
1919
import { Eye, X, Rocket, GitCompareArrows, Sparkles } from 'lucide-react';
2020
import { Button, cn } from '@object-ui/components';
2121
import { useObjectTranslation } from '@object-ui/i18n';
2222
import { usePreviewDrafts, markPreviewExit, PREVIEW_QUERY_FLAG } from './PreviewModeContext.js';
2323
import { usePendingDrafts } from './usePendingDrafts.js';
2424
import { usePublishAllDrafts } from './usePublishAllDrafts.js';
25-
import { DraftChangesPanel } from './DraftChangesPanel.js';
25+
// objectstack#33582: the Pending changes sheet loads with the bar, not with the
26+
// console. The bar is in every route's EAGER graph (`ConsoleLayout`), and the
27+
// sheet, closed until asked for, held the metadata form strings and the object
28+
// field reader there by value. Drawn only in preview mode, the bar fetches it
29+
// as it appears, before anyone can open it.
30+
const DraftChangesPanel = lazy(() =>
31+
import('./DraftChangesPanel.js').then((m) => ({ default: m.DraftChangesPanel })),
32+
);
2633
import { draftSurfaceOf, draftsOnSurface } from './draftSurface.js';
2734

2835
export function DraftPreviewBar() {
@@ -182,7 +189,9 @@ export function DraftPreviewBar() {
182189
: t('preview.draftBar.publishCta', { defaultValue: 'Publish to see it live' })}
183190
</Button>
184191
</div>
185-
<DraftChangesPanel open={changesOpen} onOpenChange={setChangesOpen} />
192+
<Suspense fallback={null}>
193+
<DraftChangesPanel open={changesOpen} onOpenChange={setChangesOpen} />
194+
</Suspense>
186195
</>
187196
)}
188197
</div>

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

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
* metadata type.
1616
*/
1717

18-
import { lazy, Suspense, type ComponentType } from 'react';
18+
import { lazy, Suspense } from 'react';
1919
import { registerAppComponent } from './componentRegistry.js';
20+
import { lazyPage, LazyPageFallback as MetadataAdminFallback } from './lazyPage.js';
2021
import { registerMetadataResource } from '../views/metadata-admin/registry.js';
21-
import { PositionGrantedSetsCell, PositionHolderCountCell } from '../views/metadata-admin/PositionGrantCells.js';
2222
import { CONNECTOR_CREDENTIALS_REF } from '../views/setup/connectorCredentials.js';
2323
import { CONNECTOR_CONNECTIONS_REF } from '../views/setup/connectorConnections.js';
2424
import { PERMISSION_SET_ASSIGNMENT_REF, POSITION_HOLDERS_REF } from '../views/setup/peopleAssignments.js';
@@ -94,42 +94,22 @@ const MetadataResourceRouter = lazy(() =>
9494
import('../views/metadata-admin/index.js').then((m) => ({ default: m.MetadataResourceRouter })),
9595
);
9696

97-
function MetadataAdminFallback({ label }: { label: string }) {
98-
return <div className="p-6 text-sm text-muted-foreground">Loading {label}…</div>;
99-
}
100-
10197
/**
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.
98+
* Pages registered BY REFERENCE to their module, loaded the first time they are
99+
* drawn (objectstack#33293), through the one wrapper `./lazyPage.tsx`, whose
100+
* header says why. Every page below was imported here by value, and this module
101+
* is a side-effect import of the package entry, so each one, with everything it
102+
* imports, was in the console's EAGER closure: on a dashboard route the browser
103+
* downloaded the Packages page, its package form dialog, the permission-matrix
104+
* editor and the Setup assignment pages before it asked for data. Measured from
105+
* `apps/console/dist/eager-closure.json` and the emitted chunks' module lists,
106+
* not from a source search (see the trap above): with these registrations lazy,
107+
* the `PackageFormDialog` and `PositionHoldersSection` chunks leave the closure.
112108
*
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.
109+
* ⛔ It only defers anything while nothing else in the package's eager graph
110+
* names the page module statically; the barrel's `PackagedActionsPage`
111+
* re-export is tree-shaken today because the console imports no such name.
120112
*/
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-
133113
const PackagesPage = lazyPage('packages', () =>
134114
import('../views/metadata-admin/PackagesPage.js').then((m) => m.PackagesPage),
135115
);
@@ -154,6 +134,20 @@ const PermissionSetAssignmentPage = lazyPage('permission set assignments', () =>
154134
const RecycleBinPage = lazyPage('recycle bin', () =>
155135
import('../views/setup/RecycleBinPage.js').then((m) => m.RecycleBinPage),
156136
);
137+
/**
138+
* The position list's two served cells (objectstack#33582): by value they held
139+
* `metadata-admin/i18n.ts`, and with it the Studio `en` string namespace, in the
140+
* eager closure. A cell draws nothing until its module lands (no page-sized
141+
* loading line inside a table cell); every cell shares the one load.
142+
*/
143+
const PositionHolderCountCell = lazyPage('position holders', () =>
144+
import('../views/metadata-admin/PositionGrantCells.js').then((m) => m.PositionHolderCountCell),
145+
null,
146+
);
147+
const PositionGrantedSetsCell = lazyPage('position permission sets', () =>
148+
import('../views/metadata-admin/PositionGrantCells.js').then((m) => m.PositionGrantedSetsCell),
149+
null,
150+
);
157151

158152
/**
159153
* The Suspense boundary lives INSIDE the registration value, which is the shape
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* A component registered BY REFERENCE to its module, loaded the first time it
5+
* is drawn (objectstack#33293, objectstack#33582).
6+
*
7+
* The package entry imports its registration modules for their side effects
8+
* (`services/builtinComponents.tsx`, `views/metadata-admin/register-builtins.ts`,
9+
* `views/studio-design/studio-canvas-preview.tsx`), so a component one of them
10+
* registers BY VALUE is, with everything it imports, in the console's EAGER
11+
* closure: every route downloads it before it asks for data, though only the
12+
* page that draws it reads it. Registering the value this returns instead keeps
13+
* the module behind a dynamic `import()` until the component first renders.
14+
*
15+
* The `Suspense` boundary lives INSIDE the returned component, so the registry
16+
* that receives it still receives a component, and no render site learns about
17+
* pending. ⛔ It only defers anything while nothing else in the package's eager
18+
* graph names the module statically: measure from
19+
* `apps/console/dist/eager-closure.json` and the emitted chunks' module lists,
20+
* never from a source search (see the trap note in `builtinComponents.tsx`).
21+
*
22+
* One wrapper for every such registration; ⛔ do not grow a second one.
23+
*/
24+
25+
import { lazy, Suspense, type ComponentType, type ReactNode } from 'react';
26+
27+
/** The default while a page's module loads: one muted line naming the page. */
28+
export function LazyPageFallback({ label }: { label: string }) {
29+
return <div className="p-6 text-sm text-muted-foreground">Loading {label}…</div>;
30+
}
31+
32+
/**
33+
* Wrap `load` as a component that loads its module on first render.
34+
*
35+
* `fallback` replaces the page-sized loading line where the component is not a
36+
* page, e.g. a list cell, which draws nothing until its module lands.
37+
*/
38+
export function lazyPage<P extends object>(
39+
label: string,
40+
load: () => Promise<ComponentType<P>>,
41+
fallback?: ReactNode,
42+
): ComponentType<P> {
43+
const Page = lazy(() => load().then((component) => ({ default: component })));
44+
const shown = fallback === undefined ? <LazyPageFallback label={label} /> : fallback;
45+
function LazyPage(props: P) {
46+
return (
47+
<Suspense fallback={shown}>
48+
<Page {...props} />
49+
</Suspense>
50+
);
51+
}
52+
return LazyPage;
53+
}

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ const ViewConfigPanel = lazy(() =>
3838
);
3939
import { useMetadataClient } from './metadata-admin/useMetadata.js';
4040
import { dropPublishedViewList } from './metadata-admin/viewListDrop.js';
41-
import { CreateViewDialog } from './CreateViewDialog.js';
41+
// objectstack#33582: the create-view dialog loads with the first list, as the
42+
// view config panel above does. Statically, it held the dataset catalogue and,
43+
// through it, the Studio `en` string namespace in the EAGER closure.
44+
const CreateViewDialog = lazy(() =>
45+
import('./CreateViewDialog.js').then((m) => ({ default: m.CreateViewDialog })),
46+
);
4247
import {
4348
usePreviewDrafts,
4449
} from '../preview/PreviewModeContext.js';
@@ -1396,13 +1401,15 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
13961401
/>
13971402
</Suspense>
13981403
</div>
1399-
<CreateViewDialog
1400-
open={showCreateViewDialog && isAdmin}
1401-
onOpenChange={setShowCreateViewDialog}
1402-
existingLabels={views.map((v: any) => v.label).filter(Boolean)}
1403-
objectDef={objectDef}
1404-
onCreate={(cfg) => handleViewCreate(cfg)}
1405-
/>
1404+
<Suspense fallback={null}>
1405+
<CreateViewDialog
1406+
open={showCreateViewDialog && isAdmin}
1407+
onOpenChange={setShowCreateViewDialog}
1408+
existingLabels={views.map((v: any) => v.label).filter(Boolean)}
1409+
objectDef={objectDef}
1410+
onCreate={(cfg) => handleViewCreate(cfg)}
1411+
/>
1412+
</Suspense>
14061413
<PersonalViewNameDialog
14071414
open={!!personalViewDialog}
14081415
onOpenChange={(open) => { if (!open) setPersonalViewDialog(null); }}

‎ui/packages/app-shell/src/views/metadata-admin/datasource/register.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@
1616
*/
1717

1818
import { registerMetadataResource } from '../registry.js';
19-
import { DatasourceResourcePage } from './DatasourceResourcePage.js';
19+
import { lazyPage } from '../../../services/lazyPage.js';
20+
21+
/**
22+
* Registered by reference to its module (objectstack#33582): this module runs
23+
* at load (`register-builtins.ts` is a side-effect import of the package
24+
* entry), so the page by value held it, `metadata-admin/i18n.ts` with the
25+
* Studio `en` string namespace, and the JSON-schema field reader in the
26+
* console's eager closure, on every route.
27+
*/
28+
const DatasourceResourcePage = lazyPage('datasources', () =>
29+
import('./DatasourceResourcePage.js').then((m) => m.DatasourceResourcePage),
30+
);
2031

2132
let registered = false;
2233

0 commit comments

Comments
 (0)