Skip to content
Merged
20 changes: 20 additions & 0 deletions .changeset/33581-plugin-form-view-core-subpaths.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@object-ui/plugin-form': patch
'@object-ui/plugin-view': patch
'@object-ui/app-shell': patch
'@object-ui/console': patch
---

perf(console): the first load stops downloading the form and view packages; `@object-ui/plugin-form/core` and `@object-ui/plugin-view/core` publish their pure helpers without registering anything

Clause-②: yes (widening) — two new published `exports` subpaths, `@object-ui/plugin-form/core` and `@object-ui/plugin-view/core`, join what the packages accept; nothing is removed or renamed, and the package roots export the same names as before
Metadata-protocol: none

`@object-ui/plugin-form` and `@object-ui/plugin-view` register their renderers with `ComponentRegistry` when their root entry is evaluated, and each root reaches every surface of its package. A host that imported one pure helper from the root therefore kept the whole package. Each package now publishes a `/core` subpath that registers nothing:

- `@object-ui/plugin-form/core`: `filterSystemFields`, `isAutoGeneratedFieldType`, `isWideFieldType`, `inferColumns`, `containerGridColsFor`, `resolveInlineMode`, `omitServerResolvedDefaults`, `optionListDefault`, `resolveSectionGroupReferences`, `useInitialFieldFocus`, and the parameter types they take (`InlineMode`, `FieldDefaultsSchemaLike`, `OptionListFieldLike`, `ResolveSectionGroupsOptions`).
- `@object-ui/plugin-view/core`: `deriveRecordSurface`, `deriveRecordFlowSurface`, `overlayWidthFor`, `toFilterGroup`, `deriveFieldOptions`, `isImageLikeField`, `isGeoLikeField`, `pickPreferredField`, `KANBAN_GROUP_PREFERRED`, `PRIMARY_DATE_PREFERRED`, `END_DATE_PREFERRED`, and the types `RecordSurface`, `RecordFlowSurface`, `FieldOption`.

The same names stay exported from each package root, unchanged; nothing to migrate. The subpath ships ESM only (`import`), as `@object-ui/plugin-chatbot/core` does.

The console (`@object-ui/console`, and the shell it draws, `@object-ui/app-shell`) takes these helpers from the subpaths, draws the global record form, the action modal's form and a flow's object-form screen through `lazy()`, and registers the tags the two packages register (`object-form`, `view:form`, `embeddable-form`, `object-master-detail-form`, `record:line_items`, `object-view`, `view:simple`, `view-switcher`, `filter-ui`, `sort-ui`) as lazy stubs with the namespaces those registrations declare. Neither package is downloaded on the first load any more; each loads, and registers once, the first time a form or a view is drawn. What every page draws is unchanged; the first record form or action form opened in a session waits for the form chunk before it shows.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import { manifestFromConfigs, validateTree } from '@objectstack/sdui-parser';
import type { Diagnostic, SchemaElement } from '@objectstack/sdui-parser';
import '@object-ui/components';
import '../register-plugins';
// `@object-ui/plugin-form` too: the console registers its tags as lazy stubs
// since its first load stopped carrying the package (objectstack#33581), and
// a stub carries no `inputs`, which is what this manifest is read from.
import '@object-ui/plugin-form';

const manifest = manifestFromConfigs(
ComponentRegistry.getPublicConfigs() as unknown as Parameters<typeof manifestFromConfigs>[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import { manifestFromConfigs, validateTree } from '@objectstack/sdui-parser';
import type { Diagnostic, SchemaElement } from '@objectstack/sdui-parser';
import '@object-ui/components';
import '../register-plugins';
// `@object-ui/plugin-form` too: the console registers its tags as lazy stubs
// since its first load stopped carrying the package (objectstack#33581), and
// a stub carries no `inputs`, which is what this manifest is read from.
import '@object-ui/plugin-form';

const manifest = manifestFromConfigs(
ComponentRegistry.getAllConfigs() as unknown as Parameters<typeof manifestFromConfigs>[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import { manifestFromConfigs, validateTree } from '@objectstack/sdui-parser';
import type { Diagnostic, SchemaElement } from '@objectstack/sdui-parser';
import '@object-ui/components';
import '../register-plugins';
// `@object-ui/plugin-form` too: the console registers its tags as lazy stubs
// since its first load stopped carrying the package (objectstack#33581), and
// a stub carries no `inputs`, which is what this manifest is read from.
import '@object-ui/plugin-form';

const manifest = manifestFromConfigs(
ComponentRegistry.getPublicConfigs() as unknown as Parameters<typeof manifestFromConfigs>[0],
Expand Down
5 changes: 5 additions & 0 deletions ui/apps/console/src/__tests__/public-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ import { ComponentPropsMap } from '@objectstack/spec/ui';
import '@object-ui/components';
// … and the console's own plugin layer, from the module main.tsx boots from.
import '../register-plugins';
// `@object-ui/plugin-form` too: the console registers its tags as lazy stubs
// since its first load stopped carrying the package (objectstack#33581), and
// the reverse direction below reads `record:line_items`'s `inputs`, which a
// stub does not carry. `EXPECTED_LAZY` therefore stays the list it was.
import '@object-ui/plugin-form';

/**
* Every curated tag the console makes available, in `PUBLIC_BLOCKS` order.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ import {
// binding-reach probe: a hand-copied list would agree with itself.
import '@object-ui/components';
import '../register-plugins';
// `@object-ui/plugin-form` too: the console registers its tags as lazy stubs
// since its first load stopped carrying the package (objectstack#33581), and
// this probe renders `record:line_items` synchronously, through its real renderer.
import '@object-ui/plugin-form';

/** The object every probed block is mounted against. */
const PROBE_OBJECT = 'probe_object__c';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ import {
// test/hook timeout (AGENTS.md §测试纪律, objectui#3010).
import '@object-ui/components';
import '../register-plugins';
// `@object-ui/plugin-form` too: the console registers its tags as lazy stubs
// since its first load stopped carrying the package (objectstack#33581), and
// a stub carries no `inputs`, so without this import the three form blocks
// leave `covered`.
import '@object-ui/plugin-form';

// ── objectui#8176: the blocks `register-plugins` alone cannot show this gate ──
//
Expand Down
2 changes: 1 addition & 1 deletion ui/apps/console/src/components/FormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ import {
omitServerResolvedDefaults,
optionListDefault,
resolveSectionGroupReferences,
} from '@object-ui/plugin-form';
} from '@object-ui/plugin-form/core';
// ADR-0059's published door for a host that renders field widgets OUTSIDE the
// form renderer: `resolveFormWidgetType` + `getLazyFieldWidget` hand back the
// very component `@object-ui/fields` registers for the form, so a host built on
Expand Down
39 changes: 36 additions & 3 deletions ui/apps/console/src/register-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
import { ComponentRegistry } from '@object-ui/core';

// Eager imports — core views the console shell itself imports by name today
// (the shell's own helpers and record surfaces reach these four packages'
// (the shell's own helpers and record surfaces reach these two 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-detail';

// Lazy plugins — registered as deferred loaders. The first time the
Expand Down Expand Up @@ -59,6 +57,41 @@ ComponentRegistry.registerLazy('object-gallery', () => import('@object-ui/plugin
category: 'view',
});

// The form and the object view: the shell takes their pure helpers from the
// side-effect-free `/core` subpaths and draws their components behind
// `lazy()`, so nothing on the first load imports either entry. Each tag the
// entry registers is a stub with the namespace, `skipFallback` and category
// that registration declares; the first schema naming one loads the package,
// whose own registrations then replace every stub of it, once.
for (const variant of ['object-form', 'embeddable-form', 'object-master-detail-form']) {
ComponentRegistry.registerLazy(variant, () => import('@object-ui/plugin-form'), {
namespace: 'plugin-form',
category: 'plugin',
});
}
ComponentRegistry.registerLazy('form', () => import('@object-ui/plugin-form'), {
namespace: 'view',
skipFallback: true,
category: 'view',
});
ComponentRegistry.registerLazy('line_items', () => import('@object-ui/plugin-form'), {
namespace: 'record',
skipFallback: true,
category: 'record',
});
for (const variant of ['object-view', 'view:simple']) {
ComponentRegistry.registerLazy(variant, () => import('@object-ui/plugin-view'), {
namespace: 'plugin-view',
category: 'view',
});
}
for (const variant of ['view-switcher', 'filter-ui', 'sort-ui']) {
ComponentRegistry.registerLazy(variant, () => import('@object-ui/plugin-view'), {
namespace: 'view',
category: 'view',
});
}

ComponentRegistry.registerLazy('object-map', () => import('@object-ui/plugin-map'), {
namespace: 'plugin-map',
category: 'view',
Expand Down
26 changes: 26 additions & 0 deletions ui/apps/console/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ const workspaceAliases: Record<string, string> = {
'@object-ui/layout': path.resolve(import.meta.dirname, '../../packages/layout/src'),
'@object-ui/plugin-dashboard': path.resolve(import.meta.dirname, '../../packages/plugin-dashboard/src'),
'@object-ui/plugin-report': path.resolve(import.meta.dirname, '../../packages/plugin-report/src'),
'@object-ui/plugin-form/core': path.resolve(import.meta.dirname, '../../packages/plugin-form/src/core.ts'),
'@object-ui/plugin-form': path.resolve(import.meta.dirname, '../../packages/plugin-form/src'),
'@object-ui/plugin-grid': path.resolve(import.meta.dirname, '../../packages/plugin-grid/src'),
'@object-ui/react': path.resolve(import.meta.dirname, '../../packages/react/src'),
Expand Down Expand Up @@ -661,6 +662,7 @@ const workspaceAliases: Record<string, string> = {
'@object-ui/plugin-markdown': path.resolve(import.meta.dirname, '../../packages/plugin-markdown/src'),
'@object-ui/plugin-timeline': path.resolve(import.meta.dirname, '../../packages/plugin-timeline/src'),
'@object-ui/plugin-tree': path.resolve(import.meta.dirname, '../../packages/plugin-tree/src'),
'@object-ui/plugin-view/core': path.resolve(import.meta.dirname, '../../packages/plugin-view/src/core.ts'),
'@object-ui/plugin-view': path.resolve(import.meta.dirname, '../../packages/plugin-view/src'),
'@object-ui/plugin-designer': path.resolve(import.meta.dirname, '../../packages/plugin-designer/src'),
};
Expand Down Expand Up @@ -1523,6 +1525,30 @@ export default defineConfig({
{ name: 'plugin-calendar', test: /[\\/]packages[\\/]plugin-calendar[\\/]/, priority: 70 },
{ name: 'plugin-kanban', test: /[\\/]packages[\\/]plugin-kanban[\\/]/, priority: 70 },
//
// ## The form and view helpers stay out of their plugin chunks
//
// The console shell is eager and imports pure helpers through
// `@object-ui/plugin-form/core` and `@object-ui/plugin-view/core`.
// Left to the `plugin-form` / `plugin-view` groups above, those
// modules would be co-tenants of the renderers and pull each whole
// chunk back into every first load, the mechanism the chatbot group
// below names. Each group takes exactly the modules its `core.ts`
// reaches inside its package, for the reason `types-zod` above gives
// for `includeDependenciesRecursively: false`. ⛔ A module added to a
// `core.ts` closure belongs in its list.
{
name: 'plugin-form-core',
test: /[\\/]packages[\\/]plugin-form[\\/]src[\\/](core|autoLayout|sanitize|deriveMasterDetail|schemaDefaults|sectionGroups|fieldGroups|initialFieldFocus)\.tsx?$/,
priority: 71,
includeDependenciesRecursively: false,
},
{
name: 'plugin-view-core',
test: /[\\/]packages[\\/]plugin-view[\\/]src[\\/](core|recordSurface|config[\\/]view-config-utils)\.tsx?$/,
priority: 71,
includeDependenciesRecursively: false,
},
//
// ## The chatbot's side-effect-free half stays out of its chunk (objectui#13410)
//
// The console shell is eager and imports the agent catalog hook and a
Expand Down
152 changes: 152 additions & 0 deletions ui/packages/app-shell/src/__tests__/pluginCoreSubpaths-33581.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/**
* ObjectUI
* Copyright (c) 2024-present ObjectStack Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* The console shell takes the form and view helpers from the side-effect-free
* `/core` subpaths, never from the package entries (objectstack#33581).
*
* `@object-ui/plugin-form` and `@object-ui/plugin-view` register their
* renderers when their entry is evaluated, and each entry reaches every surface
* of its package. A named import of one pure helper from an entry, in any
* module the first load reaches, puts the whole package back into every first
* load; nothing else says so, because the console's eager-closure budget is far
* coarser than one plugin chunk.
*
* Two pins:
* - no shell or console source imports, from an entry, a value name its
* `/core` subpath exports (the names are read from the subpath itself, so a
* helper added there is covered the day it is added);
* - the always-eager shell modules that draw a form or a view import nothing
* from either entry by value: their components load through `lazy()`
* (`views/lazyFormSurfaces.tsx`) or through the console's lazy stubs.
*
* ⚠ A SOURCE SCAN: it reads import declarations, not the bundle. The built
* graph is the console's `dist/eager-closure.json`; this file keeps the edges
* that graph was measured on from coming back one import at a time.
*/

import { describe, it, expect } from 'vitest';
import { readFileSync, readdirSync, statSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import * as formCore from '@object-ui/plugin-form/core';
import * as viewCore from '@object-ui/plugin-view/core';
// @ts-expect-error — plain-JS shared helper, intentionally untyped (`allowJs: false`)
import { maskComments } from '../../../../scripts/js-comment-mask.mjs';

const mask: (source: string) => string = maskComments;

const here = path.dirname(fileURLToPath(import.meta.url));
const SHELL_SRC = path.resolve(here, '..');
const CONSOLE_SRC = path.resolve(here, '../../../../apps/console/src');

const ENTRIES = {
'@object-ui/plugin-form': new Set(Object.keys(formCore)),
'@object-ui/plugin-view': new Set(Object.keys(viewCore)),
} as const;
type Entry = keyof typeof ENTRIES;

function sourceFiles(dir: string): string[] {
const out: string[] = [];
for (const name of readdirSync(dir)) {
const full = path.join(dir, name);
if (statSync(full).isDirectory()) {
if (name === '__tests__' || name === '__mocks__' || name === 'node_modules') continue;
out.push(...sourceFiles(full));
} else if (/\.(ts|tsx)$/.test(name) && !/\.(test|spec)\.tsx?$/.test(name) && !name.endsWith('.d.ts')) {
out.push(full);
}
}
return out;
}

interface EntryImport {
file: string;
entry: Entry;
/** Value names; `null` for a bare side-effect import. */
values: string[] | null;
}

const IMPORT_RE = /\bimport\s+(type\s+)?([\s\S]*?)\s*from\s*['"]([^'"]+)['"]|\bimport\s+['"]([^'"]+)['"]/g;

function entryImports(file: string): EntryImport[] {
const source = mask(readFileSync(file, 'utf8'));
const found: EntryImport[] = [];
for (const m of source.matchAll(IMPORT_RE)) {
const specifier = (m[3] ?? m[4]) as string;
if (!(specifier in ENTRIES)) continue;
const entry = specifier as Entry;
if (m[4]) { found.push({ file, entry, values: null }); continue; }
if (m[1]) continue; // `import type { … }` is erased
const clause = m[2] as string;
const named = /\{([\s\S]*)\}/.exec(clause)?.[1] ?? '';
const values = named
.split(',')
.map((s) => s.trim())
.filter((s) => s !== '' && !s.startsWith('type '))
.map((s) => s.split(/\s+as\s+/)[0] as string);
const defaultOrNs = clause.replace(/\{[\s\S]*\}/, '').replace(/,/g, '').trim();
if (defaultOrNs !== '') values.push(defaultOrNs);
found.push({ file, entry, values });
}
return found;
}

const FILES = [...sourceFiles(SHELL_SRC), ...sourceFiles(CONSOLE_SRC)];
const rel = (file: string) => path.relative(path.resolve(here, '../../../..'), file).split(path.sep).join('/');

describe('the form and view helpers come from the /core subpaths (objectstack#33581)', () => {
it('reads real subpaths and a real tree (floors)', () => {
// The helpers the console shell measured on: each subpath must still carry them.
for (const name of ['filterSystemFields', 'isAutoGeneratedFieldType', 'useInitialFieldFocus', 'resolveInlineMode']) {
expect(ENTRIES['@object-ui/plugin-form'].has(name), name).toBe(true);
}
for (const name of ['deriveRecordSurface', 'deriveRecordFlowSurface', 'overlayWidthFor', 'toFilterGroup']) {
expect(ENTRIES['@object-ui/plugin-view'].has(name), name).toBe(true);
}
expect(FILES.length).toBeGreaterThan(500);
// The scan must see the subpath imports it protects, or it is reading nothing.
const coreImporters = FILES.filter((f) => /from\s*['"]@object-ui\/plugin-(form|view)\/core['"]/.test(readFileSync(f, 'utf8')));
expect(coreImporters.length).toBeGreaterThanOrEqual(10);
});

it('no shell or console source imports a /core helper from a package entry', () => {
const offenders: string[] = [];
for (const file of FILES) {
for (const { entry, values } of entryImports(file)) {
for (const name of values ?? []) {
if (ENTRIES[entry].has(name)) offenders.push(`${rel(file)}: ${name} from '${entry}' (use '${entry}/core')`);
}
}
}
expect(offenders).toEqual([]);
});

it('the always-eager modules that draw a form or a view import neither entry by value', () => {
const EAGER = [
'packages/app-shell/src/console/AppContent.tsx',
'packages/app-shell/src/hooks/useActionModal.tsx',
'packages/app-shell/src/views/ScreenView.tsx',
'packages/app-shell/src/views/lazyFormSurfaces.tsx',
'packages/app-shell/src/providers/MetadataProvider.tsx',
'packages/app-shell/src/views/ActionParamDialog.tsx',
'packages/app-shell/src/views/recordDrawerStack.tsx',
'packages/app-shell/src/views/userFilterUrlState.ts',
'apps/console/src/components/FormPage.tsx',
'apps/console/src/register-plugins.ts',
];
const offenders: string[] = [];
for (const r of EAGER) {
const file = path.resolve(here, '../../../..', r);
for (const { entry, values } of entryImports(file)) {
offenders.push(`${r}: ${values === null ? 'bare import' : values.join(', ')} from '${entry}'`);
}
}
expect(offenders).toEqual([]);
});
});
Loading
Loading