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/33582-console-eager-closure-studio-strings.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 Studio designer strings and the metadata form strings

Clause-②: no
Metadata-protocol: none

Every Console route, a dashboard included, used to download the Studio designer's English strings (64 KB gzipped) and the metadata form strings before the app asked for any data, though only Studio and Setup screens draw them. They were held there by five components the Console registers or mounts at load: the Studio canvas's default object grid, the Setup datasources page, the position list's holder and permission-set cells, a list's "Create view" dialog and the preview bar's "Pending changes" sheet. Each now loads the first time it is drawn, and the Studio strings' loader gets its own chunk. English stays the strings' synchronous fallback once a Studio or Setup screen has loaded. The Console's eager closure (`dist/eager-closure.json`) goes from 2,165,707 to 2,058,468 bytes gzipped (−107,239), measured on two builds of the same tree. What each screen draws is unchanged; the datasources page shows a one-line loading notice while its code arrives.
10 changes: 10 additions & 0 deletions ui/apps/console/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,16 @@ export default defineConfig({
// `en` is the namespace's resident fallback and gets its own chunk so
// its bytes are named in `eager-closure.json` instead of hiding in
// the runtime's.
//
// The loader module (`index.ts`, which imports `en` statically: the
// synchronous fallback, objectstack#25922) gets a group too, for the
// marketplace loader's reason below: without one it falls to the
// eager `i18n-runtime` group, and its static `en` edge put the 64 KB
// `en` catalogue on every console route, though only the Studio
// and Setup screens that import `metadata-admin/i18n.ts` read it
// (objectstack#33582). `includeDependenciesRecursively: false` for
// the same measured reason as the marketplace loader's.
{ name: 'i18n-ns-studio', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]studio[\\/]index\.ts$/, priority: 84, includeDependenciesRecursively: false },
{ name: 'i18n-ns-studio-en', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]studio[\\/]en\.ts$/, priority: 84 },
{ name: 'i18n-ns-studio-zh', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]studio[\\/]zh\.ts$/, priority: 84 },
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const OBJECTS_READERS: Record<string, { kind: Kind; why: string }> = {
kind: 'off',
why: "Studio: the object's view labels New view refuses to reuse, the read the list-view panel made before the switcher moved into the header (objectstack#30046)",
},
'packages/app-shell/src/views/studio-design/studio-canvas-preview.tsx': { kind: 'off', why: 'Studio' },
'packages/app-shell/src/views/studio-design/studio-object-records-canvas.tsx': { kind: 'off', why: 'Studio' },
'packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx': {
kind: 'off',
why: "Studio: the Data pillar's Form tab asks selectRecordFormView which form view the app opens, over the served objects (objectstack#30057)",
Expand Down
15 changes: 12 additions & 3 deletions ui/packages/app-shell/src/preview/DraftPreviewBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@
* keeps a read-only preview from ever being confused with the live app.
*/

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

export function DraftPreviewBar() {
Expand Down Expand Up @@ -182,7 +189,9 @@ export function DraftPreviewBar() {
: t('preview.draftBar.publishCta', { defaultValue: 'Publish to see it live' })}
</Button>
</div>
<DraftChangesPanel open={changesOpen} onOpenChange={setChangesOpen} />
<Suspense fallback={null}>
<DraftChangesPanel open={changesOpen} onOpenChange={setChangesOpen} />
</Suspense>
</>
)}
</div>
Expand Down
64 changes: 29 additions & 35 deletions ui/packages/app-shell/src/services/builtinComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* metadata type.
*/

import { lazy, Suspense, type ComponentType } from 'react';
import { lazy, Suspense } from 'react';
import { registerAppComponent } from './componentRegistry.js';
import { lazyPage, LazyPageFallback as MetadataAdminFallback } from './lazyPage.js';
import { registerMetadataResource } from '../views/metadata-admin/registry.js';
import { PositionGrantedSetsCell, PositionHolderCountCell } from '../views/metadata-admin/PositionGrantCells.js';
import { CONNECTOR_CREDENTIALS_REF } from '../views/setup/connectorCredentials.js';
import { CONNECTOR_CONNECTIONS_REF } from '../views/setup/connectorConnections.js';
import { PERMISSION_SET_ASSIGNMENT_REF, POSITION_HOLDERS_REF } from '../views/setup/peopleAssignments.js';
Expand Down Expand Up @@ -94,42 +94,22 @@ const MetadataResourceRouter = lazy(() =>
import('../views/metadata-admin/index.js').then((m) => ({ default: m.MetadataResourceRouter })),
);

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.
* Pages registered BY REFERENCE to their module, loaded the first time they are
* drawn (objectstack#33293), through the one wrapper `./lazyPage.tsx`, whose
* header says why. 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.
* ⛔ 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),
);
Expand All @@ -154,6 +134,20 @@ const PermissionSetAssignmentPage = lazyPage('permission set assignments', () =>
const RecycleBinPage = lazyPage('recycle bin', () =>
import('../views/setup/RecycleBinPage.js').then((m) => m.RecycleBinPage),
);
/**
* The position list's two served cells (objectstack#33582): by value they held
* `metadata-admin/i18n.ts`, and with it the Studio `en` string namespace, in the
* eager closure. A cell draws nothing until its module lands (no page-sized
* loading line inside a table cell); every cell shares the one load.
*/
const PositionHolderCountCell = lazyPage('position holders', () =>
import('../views/metadata-admin/PositionGrantCells.js').then((m) => m.PositionHolderCountCell),
null,
);
const PositionGrantedSetsCell = lazyPage('position permission sets', () =>
import('../views/metadata-admin/PositionGrantCells.js').then((m) => m.PositionGrantedSetsCell),
null,
);

/**
* The Suspense boundary lives INSIDE the registration value, which is the shape
Expand Down
53 changes: 53 additions & 0 deletions ui/packages/app-shell/src/services/lazyPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* A component registered BY REFERENCE to its module, loaded the first time it
* is drawn (objectstack#33293, objectstack#33582).
*
* The package entry imports its registration modules for their side effects
* (`services/builtinComponents.tsx`, `views/metadata-admin/register-builtins.ts`,
* `views/studio-design/studio-canvas-preview.tsx`), so a component one of them
* registers BY VALUE is, with everything it imports, in the console's EAGER
* closure: every route downloads it before it asks for data, though only the
* page that draws it reads it. Registering the value this returns instead keeps
* the module behind a dynamic `import()` until the component first renders.
*
* The `Suspense` boundary lives INSIDE the returned component, so the registry
* that receives it still receives a component, and no render site learns about
* pending. ⛔ It only defers anything while nothing else in the package's eager
* graph names the module statically: measure from
* `apps/console/dist/eager-closure.json` and the emitted chunks' module lists,
* never from a source search (see the trap note in `builtinComponents.tsx`).
*
* One wrapper for every such registration; ⛔ do not grow a second one.
*/

import { lazy, Suspense, type ComponentType, type ReactNode } from 'react';

/** The default while a page's module loads: one muted line naming the page. */
export function LazyPageFallback({ label }: { label: string }) {
return <div className="p-6 text-sm text-muted-foreground">Loading {label}…</div>;
}

/**
* Wrap `load` as a component that loads its module on first render.
*
* `fallback` replaces the page-sized loading line where the component is not a
* page, e.g. a list cell, which draws nothing until its module lands.
*/
export function lazyPage<P extends object>(
label: string,
load: () => Promise<ComponentType<P>>,
fallback?: ReactNode,
): ComponentType<P> {
const Page = lazy(() => load().then((component) => ({ default: component })));
const shown = fallback === undefined ? <LazyPageFallback label={label} /> : fallback;
function LazyPage(props: P) {
return (
<Suspense fallback={shown}>
<Page {...props} />
</Suspense>
);
}
return LazyPage;
}
23 changes: 15 additions & 8 deletions ui/packages/app-shell/src/views/ObjectView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ const ViewConfigPanel = lazy(() =>
);
import { useMetadataClient } from './metadata-admin/useMetadata.js';
import { dropPublishedViewList } from './metadata-admin/viewListDrop.js';
import { CreateViewDialog } from './CreateViewDialog.js';
// objectstack#33582: the create-view dialog loads with the first list, as the
// view config panel above does. Statically, it held the dataset catalogue and,
// through it, the Studio `en` string namespace in the EAGER closure.
const CreateViewDialog = lazy(() =>
import('./CreateViewDialog.js').then((m) => ({ default: m.CreateViewDialog })),
);
import {
usePreviewDrafts,
} from '../preview/PreviewModeContext.js';
Expand Down Expand Up @@ -1396,13 +1401,15 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
/>
</Suspense>
</div>
<CreateViewDialog
open={showCreateViewDialog && isAdmin}
onOpenChange={setShowCreateViewDialog}
existingLabels={views.map((v: any) => v.label).filter(Boolean)}
objectDef={objectDef}
onCreate={(cfg) => handleViewCreate(cfg)}
/>
<Suspense fallback={null}>
<CreateViewDialog
open={showCreateViewDialog && isAdmin}
onOpenChange={setShowCreateViewDialog}
existingLabels={views.map((v: any) => v.label).filter(Boolean)}
objectDef={objectDef}
onCreate={(cfg) => handleViewCreate(cfg)}
/>
</Suspense>
<PersonalViewNameDialog
open={!!personalViewDialog}
onOpenChange={(open) => { if (!open) setPersonalViewDialog(null); }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@
*/

import { registerMetadataResource } from '../registry.js';
import { DatasourceResourcePage } from './DatasourceResourcePage.js';
import { lazyPage } from '../../../services/lazyPage.js';

/**
* Registered by reference to its module (objectstack#33582): this module runs
* at load (`register-builtins.ts` is a side-effect import of the package
* entry), so the page by value held it, `metadata-admin/i18n.ts` with the
* Studio `en` string namespace, and the JSON-schema field reader in the
* console's eager closure, on every route.
*/
const DatasourceResourcePage = lazyPage<{ type: string }>('datasources', () =>
import('./DatasourceResourcePage.js').then((m) => m.DatasourceResourcePage),
);

let registered = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ import {
StudioObjectRecordsCanvas,
} from './studio-canvas-preview';
import type { StudioCanvasListView } from './studio-canvas-preview';
// The grid's own module: the registry above holds it behind a lazy wrapper of
// the same name (objectstack#33582), so the grid's behaviour is pinned on the
// module's component, and the wrapper by the lazy-registration block below.
import { StudioObjectRecordsCanvas as ObjectRecordsCanvas } from './studio-object-records-canvas';

describe('studio-canvas-preview registry', () => {
it('ships a built-in default for `object` (the records grid)', () => {
Expand Down Expand Up @@ -104,7 +108,7 @@ describe('navEntryListTarget — the runtime reading of an object entry (objectu
});
});

describe('StudioObjectRecordsCanvas — renders the entry it is open on (objectui#11774)', () => {
describe('the default object canvas — renders the entry it is open on (objectui#11774)', () => {
/** Stands in for `plugin-view`'s `object-view`, recording the schema it is handed. */
function ObjectViewRecorder({ schema }: { schema: Record<string, unknown> }) {
return <pre data-testid="object-view-schema">{JSON.stringify(schema)}</pre>;
Expand Down Expand Up @@ -134,7 +138,7 @@ describe('StudioObjectRecordsCanvas — renders the entry it is open on (objectu
render(
<MetadataCtx.Provider value={METADATA}>
<StudioCanvasNavEntryContext.Provider value={entry}>
<StudioObjectRecordsCanvas type="object" name="showcase_task" draft={{}} />
<ObjectRecordsCanvas type="object" name="showcase_task" draft={{}} />
</StudioCanvasNavEntryContext.Provider>
</MetadataCtx.Provider>,
);
Expand Down Expand Up @@ -177,7 +181,7 @@ describe('StudioObjectRecordsCanvas — renders the entry it is open on (objectu
* it is editing: the panel's buffer, handed over through
* `StudioCanvasListViewContext` (beside the published props, like the entry).
*/
describe('StudioObjectRecordsCanvas — shows the list view its panel edits (objectui#11823)', () => {
describe('the default object canvas — shows the list view its panel edits (objectui#11823)', () => {
function ObjectViewRecorder({ schema }: { schema: Record<string, unknown> }) {
return <pre data-testid="object-view-schema">{JSON.stringify(schema)}</pre>;
}
Expand Down Expand Up @@ -212,7 +216,7 @@ describe('StudioObjectRecordsCanvas — shows the list view its panel edits (obj
<MetadataCtx.Provider value={METADATA}>
<StudioCanvasNavEntryContext.Provider value={entry}>
<StudioCanvasListViewContext.Provider value={edited}>
<StudioObjectRecordsCanvas type="object" name="showcase_task" draft={{}} />
<ObjectRecordsCanvas type="object" name="showcase_task" draft={{}} />
</StudioCanvasListViewContext.Provider>
</StudioCanvasNavEntryContext.Provider>
</MetadataCtx.Provider>,
Expand Down Expand Up @@ -254,3 +258,53 @@ describe('StudioObjectRecordsCanvas — shows the list view its panel edits (obj
});
});
});

/**
* objectstack#33582 — the registered `object` default is a lazy wrapper of the
* grid's module, not the module's component: the registry module is imported
* by the package entry at load, so a by-value default held the grid and the
* designer strings in the console's eager closure. Drawn through the registry,
* as `StudioDesignSurface` draws it, the wrapper shows its loading line, then
* the grid with the schema the module's own component renders.
*/
describe('the registered object default loads the grid on first draw (objectstack#33582)', () => {
function ObjectViewRecorder({ schema }: { schema: Record<string, unknown> }) {
return <pre data-testid="object-view-schema">{JSON.stringify(schema)}</pre>;
}
const METADATA: MetadataContextValue = {
apps: [],
objects: [{ name: 'showcase_task', label: 'Task' }],
dashboards: [],
reports: [],
pages: [],
loading: false,
error: null,
refresh: async () => {},
invalidate: () => {},
ensureType: async () => [],
getItem: async () => null,
getItemsByType: () => [],
};

beforeAll(() => {
ComponentRegistry.register('object-view', ObjectViewRecorder as never, { namespace: 'plugin-view' });
});
afterEach(cleanup);

it('the default is the wrapper, not the grid module\'s own component', () => {
expect(getStudioCanvasPreview('object')).toBe(StudioObjectRecordsCanvas);
expect(StudioObjectRecordsCanvas).not.toBe(ObjectRecordsCanvas);
});

it('drawn through the registry, it loads and draws the grid', async () => {
const Canvas = getStudioCanvasPreview('object')!;
render(
<MetadataCtx.Provider value={METADATA}>
<Canvas type="object" name="showcase_task" draft={{}} />
</MetadataCtx.Provider>,
);
const grid = await screen.findByTestId('object-view-schema');
expect(JSON.parse(grid.textContent ?? 'null')).toEqual({ type: 'object-view', objectName: 'showcase_task' });
expect(screen.queryByText('Loading studio canvas…')).toBeNull();
});
});
Loading
Loading