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/33581-console-eager-closure-list-and-record.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 object list, the record view and the list view package

Clause-②: no
Metadata-protocol: none

Every Console route, a dashboard included, used to download the object list (the default list and a saved list view), the record view its drawer draws, and `@object-ui/plugin-list` (the list view and the gallery) before the app asked for any data. The object list now loads like the other route pages, its download starting as soon as the route is known; the record view loads the first time a record opens in the drawer; and the `list-view`, `view:list` and `object-gallery` registrations are lazy stubs that load the package the first time a schema names one of them. The Console's eager closure (`dist/eager-closure.json`) goes from 2,165,721 to 2,060,434 bytes gzipped (−105,287). What each route draws is unchanged; a record opened in the drawer shows the detail skeleton while its code arrives.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ import type { Diagnostic } from '@objectstack/sdui-parser';

// The full registration graph — the same pair `dev/manifest-dump.tsx` builds the
// published artifacts from, and the pair every live-path suite in this directory
// reads. `list-view` and the REAL `object-grid` both arrive through it.
// reads. The REAL `object-grid` arrives through it; `list-view` is a lazy stub
// there, so its package is loaded here too, the way `dev/manifest-registry.ts`
// loads it before reading the published manifest.
import '@object-ui/components';
import '../register-plugins';
import '@object-ui/plugin-list';

const OBJECT = 'opportunity';

Expand Down
1 change: 1 addition & 0 deletions ui/apps/console/src/__tests__/public-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const EXPECTED_UNIMPLEMENTED: string[] = [];
* plugins below, move that tag out of this list — it is still covered.
*/
const EXPECTED_LAZY = [
'list-view',
'object-kanban',
'object-calendar',
'object-gantt',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ import '@object-ui/plugin-tree';
import '@object-ui/plugin-map';
import '@object-ui/plugin-gantt';
import '@object-ui/plugin-timeline';
// The same remedy for `list-view`, which the console registers as a lazy stub
// since its first load stopped carrying `@object-ui/plugin-list`
// (objectstack#33581): without this import the block leaves `covered`.
import '@object-ui/plugin-list';

/** This block's spec props schema, or `undefined` when this pin has none. */
const specSchema = (type: string): unknown => (ComponentPropsMap as Record<string, unknown>)[type];
Expand Down
23 changes: 20 additions & 3 deletions ui/apps/console/src/register-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

import { ComponentRegistry } from '@object-ui/core';

// Eager imports — core views needed on most pages. These are cheap (no heavy
// 3rd-party deps) so paying their cost upfront is the right tradeoff.
// Eager imports — core views the console shell itself imports by name today
// (the shell's own helpers and record surfaces reach these four packages'
// entries), so a lazy stub here would move nothing out of the first load.
import '@object-ui/plugin-grid';
import '@object-ui/plugin-form';
import '@object-ui/plugin-view';
import '@object-ui/plugin-list';
import '@object-ui/plugin-detail';

// Lazy plugins — registered as deferred loaders. The first time the
Expand All @@ -42,6 +42,23 @@ import '@object-ui/plugin-detail';
// A lazily-registered tag is still a full member of the public contract:
// `getPublicConfigs()` resolves these stubs, so `kind:'react'` pages get them
// in scope before the chunk loads (objectui#2953).
// The list view and the gallery: nothing on the first load imports
// `@object-ui/plugin-list` by name, so each tag it registers is a stub that
// loads the package the first time a schema names it.
ComponentRegistry.registerLazy('list-view', () => import('@object-ui/plugin-list'), {
namespace: 'plugin-list',
category: 'Views',
});
ComponentRegistry.registerLazy('list', () => import('@object-ui/plugin-list'), {
namespace: 'view',
skipFallback: true,
category: 'view',
});
ComponentRegistry.registerLazy('object-gallery', () => import('@object-ui/plugin-list'), {
namespace: 'plugin-list',
category: 'view',
});

ComponentRegistry.registerLazy('object-map', () => import('@object-ui/plugin-map'), {
namespace: 'plugin-map',
category: 'view',
Expand Down
14 changes: 10 additions & 4 deletions ui/packages/app-shell/src/console/AppContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ import { ErrorBoundary } from '../chrome/ErrorBoundary.js';
import { LoadingScreen } from '../chrome/LoadingScreen.js';
import { BackToHomeButton, NotFoundState } from '../components/NotFoundState.js';
import { RedirectWithSplash } from '../chrome/RedirectWithSplash.js';
import { ObjectView } from '../views/ObjectView.js';
// objectui#13052 — on its own line: the line above is the eager-walk control
// `scripts/__tests__/vite-declared-lazy-views.test.ts` reads verbatim.
import { ObjectNotFoundState } from '../views/ObjectView.js';
// `ObjectNotFoundState` from its own module, not through `ObjectView`: the
// object list is a lazy route element below, and a by-value import of its
// module here would hold the whole list (and the grid it draws) eager.
import { ObjectNotFoundState } from '../views/objectViewChrome.js';
import { KeyboardShortcutsDialog } from '../chrome/KeyboardShortcutsDialog.js';
import { OnboardingWalkthrough } from '../chrome/OnboardingWalkthrough.js';
import { RouteFader } from '../chrome/RouteFader.js';
Expand Down Expand Up @@ -138,6 +138,10 @@ const SearchResultsPage = routeChunk.lazy(() => import('../views/SearchResultsPa
const RecordFormPage = routeChunk.lazy(() => import('../views/RecordFormPage.js').then(m => m.RecordFormPage));
const ComponentNavView = routeChunk.lazy(() => import('../views/ComponentNavView.js').then(m => m.ComponentNavView));
const ObjectDataPage = routeChunk.lazy(() => import('../views/ObjectDataPage.js').then(m => m.ObjectDataPage));
// The object list (the default list and a saved list view): a route element
// like the rest, so a first load that opens a dashboard or a page does not
// download the list, its record pane and the grid they draw.
const ObjectView = routeChunk.lazy(() => import('../views/ObjectView.js').then(m => m.ObjectView));

// Metadata admin — mounted under /apps/:app/metadata for the datasource
// alone (objectstack ADR-0146 D1): every other type's URL there opens Studio's
Expand Down Expand Up @@ -165,6 +169,8 @@ const MarketplacePackagePage = routeChunk.lazy(() => import('./marketplace/Marke
* them). A path not listed renders an eagerly bundled element.
*/
const APP_ROUTE_CHUNKS: ReadonlyArray<{ path: string; chunk: { preload: () => Promise<unknown> } }> = [
{ path: ':objectName', chunk: ObjectView },
{ path: ':objectName/view/:viewId', chunk: ObjectView },
{ path: ':objectName/new', chunk: RecordFormPage },
{ path: ':objectName/data', chunk: ObjectDataPage },
{ path: ':objectName/record/:recordId', chunk: RecordDetailView },
Expand Down
26 changes: 16 additions & 10 deletions ui/packages/app-shell/src/views/objectViewRecordOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@
* and its counter names the list's view (`stepScope`).
*/

import type { ReactNode } from 'react';
import { lazy, Suspense, type ReactNode } from 'react';
import type { NavigationOverlayMode } from '@object-ui/components';
import { RecordDetailView } from './RecordDetailView.js';
import { SkeletonDetail } from '../skeletons/index.js';
import { RecordStackDrawer, useRecordDrawerStack } from './recordDrawerStack.js';
import type { useObjectViewRecordNavigation } from './objectViewRecordNavigation.js';
import type { ConsoleObjectViewProps } from './ObjectView.js';

type RecordNavigation = ReturnType<typeof useObjectViewRecordNavigation>;

// The record view is fetched the first time a record opens here, not with the
// list: a list that never opens a record never downloads it.
const RecordDetailView = lazy(() => import('./RecordDetailView.js').then((m) => ({ default: m.RecordDetailView })));

export function ObjectViewRecordOverlay({
navOverlay,
mode,
Expand Down Expand Up @@ -74,14 +78,16 @@ export function ObjectViewRecordOverlay({
storageKey={`drawer-width:${objectDef.name}`}
objects={objects}
renderRecord={(level) => (
<RecordDetailView
dataSource={dataSource}
objects={objects}
onEdit={onEdit}
objectNameOverride={level.objectName}
recordIdOverride={level.recordId}
embedded
/>
<Suspense fallback={<SkeletonDetail />}>
<RecordDetailView
dataSource={dataSource}
objects={objects}
onEdit={onEdit}
objectNameOverride={level.objectName}
recordIdOverride={level.recordId}
embedded
/>
</Suspense>
)}
/>
);
Expand Down
54 changes: 43 additions & 11 deletions ui/scripts/__tests__/vite-declared-lazy-views.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { attachedDocs } from './helpers/attached-docs';
import {
APP_CONTENT_PATH,
DECLARED_LAZY_VIEWS_STILL_EAGER,
DECLARED_LAZY_VIEWS_WITH_SIDE_EFFECTS,
EAGER_WALK_CONTROL,
bareSideEffectImport,
declaredSideEffectful,
Expand Down Expand Up @@ -53,6 +54,28 @@ describe('DECLARED_LAZY_VIEWS_STILL_EAGER', () => {
});
});

describe('DECLARED_LAZY_VIEWS_WITH_SIDE_EFFECTS', () => {
it('is sorted, free of duplicates, and names declared-lazy files that exist', () => {
const entries = [...DECLARED_LAZY_VIEWS_WITH_SIDE_EFFECTS];
expect(entries).toEqual([...new Set(entries)]);
expect(entries).toEqual([...entries].sort());
const declared = parseDeclaredLazyViews(read(APP_CONTENT_PATH));
for (const entry of entries) {
expect(fs.existsSync(path.join(REPO_ROOT, entry)), entry).toBe(true);
expect(declared, `${entry} is listed but no longer declared lazy`).toContain(entry);
}
});

it('lists only views that really carry a side effect, and none the eager ledger pins', () => {
// The plugin refuses a stale entry at build time; this is the same claim
// read from the sources, so a pure view cannot sit here undeclared.
for (const entry of DECLARED_LAZY_VIEWS_WITH_SIDE_EFFECTS) {
expect(bareSideEffectImport(read(entry)), entry).not.toBeNull();
expect(DECLARED_LAZY_VIEWS_STILL_EAGER, entry).not.toContain(entry);
}
});
});

describe('parseDeclaredLazyViews', () => {
it('finds every relative module AppContent declares, resolved to real files', () => {
const declared = parseDeclaredLazyViews(read(APP_CONTENT_PATH));
Expand All @@ -61,15 +84,16 @@ describe('parseDeclaredLazyViews', () => {
// vacuously. Eight single-file route views (objectui#6535), the
// metadata-admin directory barrel that six declarations share, and the two
// marketplace pages (objectui#6681 measured three; objectui#12733 retired the
// Installed Apps one), and the app's report index (objectui#13020) = twelve
// distinct files.
expect(declared).toHaveLength(12);
// Installed Apps one), the app's report index (objectui#13020) and the
// object list (objectstack#33581) = thirteen distinct files.
expect(declared).toHaveLength(13);
for (const view of declared) {
expect(fs.existsSync(path.join(REPO_ROOT, view)), view).toBe(true);
}
expect(declared).toContain('packages/app-shell/src/views/ObjectDataPage.tsx');
expect(declared).toContain('packages/app-shell/src/views/ComponentNavView.tsx');
expect(declared).toContain('packages/app-shell/src/views/AppReportIndexView.tsx');
expect(declared).toContain('packages/app-shell/src/views/ObjectView.tsx');
// The three surfaces objectui#6535 deliberately looked away from and
// objectui#6681 measured. Named individually: a bare length assertion goes
// on passing if the widened matcher swaps one surface for another.
Expand Down Expand Up @@ -147,8 +171,9 @@ describe('bareSideEffectImport', () => {

it('agrees with the real sources: every unpinned declared view is pure', () => {
// The plugin declares `moduleSideEffects: false` for exactly the declared
// views it has NOT pinned, so this is the claim it makes about this repo.
const pinned = new Set(DECLARED_LAZY_VIEWS_STILL_EAGER);
// views it has neither pinned nor listed as side-effectful, so this is the
// claim it makes about this repo.
const pinned = new Set([...DECLARED_LAZY_VIEWS_STILL_EAGER, ...DECLARED_LAZY_VIEWS_WITH_SIDE_EFFECTS]);
const declared = parseDeclaredLazyViews(read(APP_CONTENT_PATH));
const unpinned = declared.filter((view) => !pinned.has(view));
expect(unpinned.length).toBeGreaterThan(0);
Expand Down Expand Up @@ -254,7 +279,7 @@ describe('EAGER_WALK_CONTROL', () => {
// means anything while AppContent still imports it outside a `lazy()`.
expect(fs.existsSync(path.join(REPO_ROOT, EAGER_WALK_CONTROL))).toBe(true);
const appContent = read(APP_CONTENT_PATH);
expect(appContent).toContain("import { ObjectView } from '../views/ObjectView.js';");
expect(appContent).toContain("import { ConsoleLayout } from '../layout/ConsoleLayout.js';");
expect(parseDeclaredLazyViews(appContent)).not.toContain(EAGER_WALK_CONTROL);
});
});
Expand Down Expand Up @@ -366,19 +391,22 @@ describe('the prose attached to the exported constants (objectui#7289)', () => {
APP_CONTENT_PATH,
EAGER_WALK_CONTROL,
DECLARED_LAZY_VIEWS_STILL_EAGER,
DECLARED_LAZY_VIEWS_WITH_SIDE_EFFECTS,
} as const;

it('locates the block attached to each constant, and only that block', () => {
const appContent = attachedDocs(source, 'APP_CONTENT_PATH');
const control = attachedDocs(source, 'EAGER_WALK_CONTROL');
const ledger = attachedDocs(source, 'DECLARED_LAZY_VIEWS_STILL_EAGER');
const sideEffectful = attachedDocs(source, 'DECLARED_LAZY_VIEWS_WITH_SIDE_EFFECTS');

// Controls that MUST hit: a phrase verified to be inside each attached
// block. A locator that quietly found the wrong span would pass every pin
// below by scanning prose that says nothing about these constants.
expect(appContent.prose).toContain('declarations are the subject');
expect(control.prose).toContain('The positive control for the eager walk');
expect(ledger.prose).toContain('Deleting a line is a MEASUREMENT');
expect(sideEffectful.prose).toContain('never declares');

// ...and the neighbours are not swept in. These three declarations sit
// consecutively with nothing but their own blocks between them, so an
Expand All @@ -388,11 +416,14 @@ describe('the prose attached to the exported constants (objectui#7289)', () => {
expect(control.prose).not.toContain('declarations are the subject');
expect(ledger.prose).not.toContain('The positive control for the eager walk');
expect(ledger.prose).not.toContain('Pull the modules out of');
expect(ledger.prose).not.toContain('never declares');
expect(sideEffectful.prose).not.toContain('Deleting a line is a MEASUREMENT');
expect(sideEffectful.prose).not.toContain('Pull the modules out of');

// The code is not prose. Without this the positive pin below would be
// satisfiable by the ledger's own entry line.
expect(ledger.code).toContain("'packages/app-shell/src/views/RecordDetailView.tsx'");
expect(ledger.prose).not.toContain("'packages/app-shell/src/views/RecordDetailView.tsx'");
expect(sideEffectful.code).toContain("'packages/app-shell/src/views/RecordDetailView.tsx'");
expect(sideEffectful.prose).not.toContain("'packages/app-shell/src/views/RecordDetailView.tsx'");
});

/**
Expand All @@ -410,8 +441,8 @@ describe('the prose attached to the exported constants (objectui#7289)', () => {

/**
* What each constant carries AS DATA, recorded so the pin above cannot go
* vacuous in silence. The two controls carry exactly themselves; the ledger
* carries one entry.
* vacuous in silence. The two controls carry exactly themselves; the eager
* ledger is empty and the side-effectful one carries one entry.
*
* ⚠️ The ledger EMPTYING is a win, not a failure — the block above this
* declaration says it in as many words ("Deleting a line is a MEASUREMENT,
Expand All @@ -424,6 +455,7 @@ describe('the prose attached to the exported constants (objectui#7289)', () => {
it('records what each constant carries as data, so the pin cannot go vacuous', () => {
expect(pathsCarriedBy(APP_CONTENT_PATH)).toEqual([APP_CONTENT_PATH]);
expect(pathsCarriedBy(EAGER_WALK_CONTROL)).toEqual([EAGER_WALK_CONTROL]);
expect(pathsCarriedBy(DECLARED_LAZY_VIEWS_STILL_EAGER)).toHaveLength(1);
expect(pathsCarriedBy(DECLARED_LAZY_VIEWS_STILL_EAGER)).toEqual([]);
expect(pathsCarriedBy(DECLARED_LAZY_VIEWS_WITH_SIDE_EFFECTS)).toHaveLength(1);
});
});
Loading
Loading