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
16 changes: 16 additions & 0 deletions .changeset/33581-plugin-detail-core-subpath.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@object-ui/plugin-detail': patch
'@object-ui/app-shell': patch
'@object-ui/console': patch
---

perf(console): the first load stops downloading the grid and detail packages; `@object-ui/plugin-detail/core` publishes the detail helpers without registering anything

Clause-②: yes (widening) — one new published `exports` subpath, `@object-ui/plugin-detail/core`, joins what the package accepts; nothing is removed or renamed, and the package root exports the same names as before
Metadata-protocol: none

`@object-ui/plugin-detail` registers its detail and record-page renderers with `ComponentRegistry` when its root entry is evaluated, and the root reaches every detail surface (and, in the console's build, the grid it draws with). A host that imported one pure helper from the root therefore kept the whole package. The package now publishes a `/core` subpath that registers nothing: `isRefusedFeedRead`, `relatedListEntryNames`, `RELATED_ARRANGEMENT_RECORD_VERSION`, `relatedArrangementFromRecord`, `relatedArrangementToRecord`, `deriveFieldGroupDetailSections`, `deriveHighlightFields`, `resolveDetailSections`, `isWideFieldType`, `prefetchRelatedCounts`, `relatedCountTargetsIn`, `COMPACT_RELATED_ROWS`, `normalizeRelatedListSort`, `seedQueueClaimDecision`, `seedRecordFieldAccess`, `seedRecordVerdict`, and the type `RelatedArrangement`.

The same names stay exported from the package root, unchanged; nothing to migrate. The subpath ships ESM only (`import`), as the other `/core` subpaths do. The package's ESM build now emits one file per source module (`dist/index.js`, `dist/core.js` and the modules they import), so the record-page caches a `/core` seed writes are the ones the root's hooks read; the UMD build (`dist/index.umd.cjs`) is unchanged.

The console (`@object-ui/console`, and the shell it draws, `@object-ui/app-shell`) takes these helpers from the subpath, draws the record pointer card's key fields and the approval decision's child tables through `lazy()`, loads the dev-only row-actions page lazily, and registers the tags the grid and detail packages register (`object-grid`, `view:grid`, `detail-view`, `detail-section`, `view:detail`, and the eleven `record:` blocks `details`, `related_list`, `highlights`, `activity`, `chatter`, `discussion`, `path`, `quick_actions`, `history`, `reference_rail`, `alert`) as lazy stubs with the namespaces those registrations declare. Neither package is downloaded on the first load any more; the list and record routes load them with their own route chunks, and any other surface loads them, and registers once, the first time it draws a grid or a detail block. What every page draws is unchanged.
6 changes: 4 additions & 2 deletions ui/apps/console/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { DevMasterDetail } from './dev/DevMasterDetail';
import { DevLists } from './dev/DevLists';
import { DevModal } from './dev/DevModal';
import { DevLookup } from './dev/DevLookup';
import { DevRowActions } from './dev/DevRowActions';
import {
AiAddressRedirect,
ConsoleShell,
Expand Down Expand Up @@ -102,6 +101,9 @@ const DocPage = lazy(() => import('./pages/DocPage'));
* body loads the chat UI when it first renders.
*/
const SharedRecordPage = lazy(() => import('./pages/SharedRecordPage'));
// Dev-only page drawn with `ObjectGrid`: lazy, so the grid package stays off
// every first load.
const DevRowActions = lazy(() => import('./dev/DevRowActions'));

const SERVER_URL = import.meta.env.VITE_SERVER_URL || '';
const AUTH_URL = `${SERVER_URL}/api/v1/auth`;
Expand Down Expand Up @@ -481,7 +483,7 @@ export function App() {
{/* Dev-only: row-action inline-overflow (multiple primary actions). */}
<Route path="/dev/row-actions" element={
<ProtectedRoute>
<DevRowActions />
<Suspense fallback={<LoadingScreen />}><DevRowActions /></Suspense>
</ProtectedRoute>
} />
<Route path="/organizations" element={
Expand Down
55 changes: 49 additions & 6 deletions ui/apps/console/src/register-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@

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 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-detail';

// Lazy plugins — registered as deferred loaders. The first time the
// SchemaRenderer encounters one of these `type` values, the plugin module is
// imported on-demand (and its top-level `ComponentRegistry.register()` calls
Expand Down Expand Up @@ -92,6 +86,55 @@ for (const variant of ['view-switcher', 'filter-ui', 'sort-ui']) {
});
}

// The grid and the detail view: the shell takes the detail helpers from the
// side-effect-free `@object-ui/plugin-detail/core` subpath and draws its few
// detail components behind `lazy()`, and the list and record routes reach both
// entries through their own lazy route chunks, 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.
ComponentRegistry.registerLazy('object-grid', () => import('@object-ui/plugin-grid'), {
namespace: 'plugin-grid',
category: 'plugin',
});
ComponentRegistry.registerLazy('grid', () => import('@object-ui/plugin-grid'), {
namespace: 'view',
skipFallback: true,
category: 'view',
});
ComponentRegistry.registerLazy('detail-view', () => import('@object-ui/plugin-detail'), {
namespace: 'plugin-detail',
category: 'Views',
});
ComponentRegistry.registerLazy('detail-section', () => import('@object-ui/plugin-detail'), {
namespace: 'plugin-detail',
category: 'Detail Components',
});
ComponentRegistry.registerLazy('detail', () => import('@object-ui/plugin-detail'), {
namespace: 'view',
category: 'view',
});
for (const variant of [
'details',
'related_list',
'highlights',
'activity',
'chatter',
'discussion',
'path',
'quick_actions',
'history',
'reference_rail',
'alert',
]) {
ComponentRegistry.registerLazy(variant, () => import('@object-ui/plugin-detail'), {
namespace: 'record',
skipFallback: true,
category: 'record',
});
}

ComponentRegistry.registerLazy('object-map', () => import('@object-ui/plugin-map'), {
namespace: 'plugin-map',
category: 'view',
Expand Down
10 changes: 9 additions & 1 deletion 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/types/zod` above (objectui#13410).
'@object-ui/plugin-chatbot/core': path.resolve(import.meta.dirname, '../../packages/plugin-chatbot/src/core.ts'),
'@object-ui/plugin-chatbot': path.resolve(import.meta.dirname, '../../packages/plugin-chatbot/src'),
'@object-ui/plugin-detail/core': path.resolve(import.meta.dirname, '../../packages/plugin-detail/src/core.ts'),
'@object-ui/plugin-detail': path.resolve(import.meta.dirname, '../../packages/plugin-detail/src'),
'@object-ui/plugin-editor': path.resolve(import.meta.dirname, '../../packages/plugin-editor/src'),
'@object-ui/plugin-gantt': path.resolve(import.meta.dirname, '../../packages/plugin-gantt/src'),
Expand Down Expand Up @@ -1529,7 +1530,8 @@ export default defineConfig({
// ## 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`.
// `@object-ui/plugin-form/core`, `@object-ui/plugin-view/core` and
// `@object-ui/plugin-detail/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
Expand All @@ -1549,6 +1551,12 @@ export default defineConfig({
priority: 71,
includeDependenciesRecursively: false,
},
{
name: 'plugin-detail-core',
test: /[\\/]packages[\\/]plugin-detail[\\/]src[\\/](core|autoLayout|relatedListCompact|relatedListSort|queueClaim|ConcurrentUpdateDialog|useDetailTranslation|recordFieldAccess|useRecordEditable|useRelatedCounts|renderers[\\/]recordActivityFeed|synth[\\/](relatedListEntry|relatedArrangement|buildDefaultPageSchema))\.tsx?$/,
priority: 71,
includeDependenciesRecursively: false,
},
//
// ## The chatbot's side-effect-free half stays out of its chunk (objectui#13410)
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
*/

/**
* The console shell takes the form and view helpers from the side-effect-free
* `/core` subpaths, never from the package entries (objectstack#33581).
* The console shell takes the form, view and detail 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
* `@object-ui/plugin-form`, `@object-ui/plugin-view` and
* `@object-ui/plugin-detail` (which reaches `@object-ui/plugin-grid`) 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
Expand All @@ -21,9 +23,10 @@
* - 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.
* - the always-eager shell modules that draw a form, a view or a detail
* component import nothing from those entries (nor from the grid's) by
* value: their components load through `lazy()` (`views/lazyFormSurfaces.tsx`,
* `views/lazyDetailSurfaces.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
Expand All @@ -36,6 +39,7 @@ 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';
import * as detailCore from '@object-ui/plugin-detail/core';
// @ts-expect-error — plain-JS shared helper, intentionally untyped (`allowJs: false`)
import { maskComments } from '../../../../scripts/js-comment-mask.mjs';

Expand All @@ -48,6 +52,9 @@ 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)),
'@object-ui/plugin-detail': new Set(Object.keys(detailCore)),
// No `/core` subpath: listed so the eager-module pin below sees its entry.
'@object-ui/plugin-grid': new Set<string>(),
} as const;
type Entry = keyof typeof ENTRIES;

Expand Down Expand Up @@ -100,7 +107,7 @@ function entryImports(file: string): EntryImport[] {
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)', () => {
describe('the form, view and detail 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']) {
Expand All @@ -109,10 +116,15 @@ describe('the form and view helpers come from the /core subpaths (objectstack#33
for (const name of ['deriveRecordSurface', 'deriveRecordFlowSurface', 'overlayWidthFor', 'toFilterGroup']) {
expect(ENTRIES['@object-ui/plugin-view'].has(name), name).toBe(true);
}
for (const name of ['isRefusedFeedRead', 'relatedListEntryNames', 'seedRecordVerdict', 'relatedCountTargetsIn']) {
expect(ENTRIES['@object-ui/plugin-detail'].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);
const detailCoreImporters = FILES.filter((f) => /from\s*['"]@object-ui\/plugin-detail\/core['"]/.test(readFileSync(f, 'utf8')));
expect(detailCoreImporters.length).toBeGreaterThanOrEqual(9);
});

it('no shell or console source imports a /core helper from a package entry', () => {
Expand All @@ -127,7 +139,7 @@ describe('the form and view helpers come from the /core subpaths (objectstack#33
expect(offenders).toEqual([]);
});

it('the always-eager modules that draw a form or a view import neither entry by value', () => {
it('the always-eager modules that draw a form, a view or a detail component import no entry by value', () => {
const EAGER = [
'packages/app-shell/src/console/AppContent.tsx',
'packages/app-shell/src/hooks/useActionModal.tsx',
Expand All @@ -139,6 +151,15 @@ describe('the form and view helpers come from the /core subpaths (objectstack#33
'packages/app-shell/src/views/userFilterUrlState.ts',
'apps/console/src/components/FormPage.tsx',
'apps/console/src/register-plugins.ts',
'apps/console/src/App.tsx',
'packages/app-shell/src/hooks/sharedUserFeeds.ts',
'packages/app-shell/src/utils/deriveRelatedLists.ts',
'packages/app-shell/src/utils/workspacePreference.ts',
'packages/app-shell/src/views/recordPagePayload.ts',
'packages/app-shell/src/views/recordDetailSections.ts',
'packages/app-shell/src/views/lazyDetailSurfaces.tsx',
'packages/app-shell/src/views/record-preview/RecordPreviewCard.tsx',
'packages/app-shell/src/views/approval-decision/SubmittedRecord.tsx',
];
const offenders: string[] = [];
for (const r of EAGER) {
Expand Down
2 changes: 1 addition & 1 deletion ui/packages/app-shell/src/hooks/sharedUserFeeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ import { usePermissions } from '@object-ui/permissions';
import { errorCodeIs } from '@object-ui/types';
// The refused-read verdict the record activity panel reads (objectui#11195),
// so a refused `sys_activity` read means the same thing on Home (objectui#12843).
import { isRefusedFeedRead } from '@object-ui/plugin-detail';
import { isRefusedFeedRead } from '@object-ui/plugin-detail/core';
// Re-exported from `@object-ui/react` — import it through the provider module
// so a consumer that stubs the provider stubs this too.
import { useAdapter } from '../providers/AdapterProvider.js';
Expand Down
2 changes: 1 addition & 1 deletion ui/packages/app-shell/src/utils/deriveRelatedLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import {
relatedListEntryName,
} from '@objectstack/spec/data';
import { convertSortToQueryParams } from '@object-ui/core';
import { relatedListEntryNames } from '@object-ui/plugin-detail';
import { relatedListEntryNames } from '@object-ui/plugin-detail/core';

/** Audit/ownership FKs that exist on nearly every object — never related lists. */
const AUDIT_FK_FIELDS = new Set(['created_by', 'updated_by', 'owner_id']);
Expand Down
2 changes: 1 addition & 1 deletion ui/packages/app-shell/src/utils/workspacePreference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
relatedArrangementFromRecord,
relatedArrangementToRecord,
type RelatedArrangement,
} from '@object-ui/plugin-detail';
} from '@object-ui/plugin-detail/core';

/**
* The console's per-reader workspace preferences — how a reader likes the
Expand Down
3 changes: 2 additions & 1 deletion ui/packages/app-shell/src/views/RecordDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

import { useState, useEffect, useLayoutEffect, useCallback, useContext, useMemo, useRef, type ReactElement } from 'react';
import { useParams, useNavigate, useLocation, useSearchParams, Link } from 'react-router-dom';
import { activityRowToFeedItem, buildCommentThreads, CommentsButton, CommentsPage, RecordCommentsInPanelContext, composeImpersonatedActor, IMPERSONATED_ACTOR_FALLBACK, auditEntriesToFeedItems, bodyTableIdsOf, claimQueuedRecord, RECORD_PAGE_TIMELINE_PANEL, RECORD_TIMELINE_PANEL_MAX_ENTRIES, RecordFieldChangesContext, RecordFieldHistoryContext, RecordTimelineTotalContext, DefaultRecordPageContext, EMPTY_RELATED_ARRANGEMENT, InlineEditSaveBar, RECORD_PAGE_DETAILS_WIDTH, RecordBodyTablesContext, RecordMetaFooter, RecordPageColumns, buildDefaultPageColumns, buildDefaultPageSchema, extractMentions, isRefusedFeedRead, recordSitsInQueue, resolveTitleField, useQueueClaimOffered, useRecordEditable, useRecordPageTier } from '@object-ui/plugin-detail';
import { activityRowToFeedItem, buildCommentThreads, CommentsButton, CommentsPage, RecordCommentsInPanelContext, composeImpersonatedActor, IMPERSONATED_ACTOR_FALLBACK, auditEntriesToFeedItems, bodyTableIdsOf, claimQueuedRecord, RECORD_PAGE_TIMELINE_PANEL, RECORD_TIMELINE_PANEL_MAX_ENTRIES, RecordFieldChangesContext, RecordFieldHistoryContext, RecordTimelineTotalContext, DefaultRecordPageContext, EMPTY_RELATED_ARRANGEMENT, InlineEditSaveBar, RECORD_PAGE_DETAILS_WIDTH, RecordBodyTablesContext, RecordMetaFooter, RecordPageColumns, buildDefaultPageColumns, buildDefaultPageSchema, extractMentions, recordSitsInQueue, resolveTitleField, useQueueClaimOffered, useRecordEditable, useRecordPageTier } from '@object-ui/plugin-detail';
import { isRefusedFeedRead } from '@object-ui/plugin-detail/core';
// objectstack#36075 — the comment panel's unresolved count and the moderator's verdict.
import { unresolvedThreadCount, useRecordVerdict } from '@object-ui/plugin-detail';
import { Empty, EmptyTitle, EmptyDescription, Button, PageHeaderActions, PageHeaderPhoneContext, PageHeaderTrailingContext, PanelToggles, ObjectIconTile, RecordHeaderBarContext, RecordHeaderStateContext, RecordTopBar, RecordTopBarButton, cn, useRecordStepKeys, type PanelToggleItem, type RecordHeaderBar, type RecordHeaderGroupParts, type RecordHeaderState, type RecordTopBarStepper } from '@object-ui/components';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import { isDeadlineSettled, withoutDeniedFields } from '@object-ui/core';
import { getCellRenderer, resolveCellRendererType } from '@object-ui/fields';
import { useSafeFieldLabel } from '@object-ui/i18n';
import { usePermissions } from '@object-ui/permissions';
import { deriveFieldGroupDetailSections, isWideFieldType, RelatedList } from '@object-ui/plugin-detail';
import { deriveFieldGroupDetailSections, isWideFieldType } from '@object-ui/plugin-detail/core';
import {
useAdapter,
useDataInvalidation,
Expand All @@ -112,6 +112,7 @@ import { deriveRecordDetailSections } from '../recordDetailSections.js';
import { deriveRelatedLists } from '../../utils/deriveRelatedLists.js';
import { servedObjectLabel, servedObjectPluralLabel } from '../../hooks/servedObjectLabel.js';
import { useReportRecordRead } from './recordReadReport.js';
import { LazyRelatedList } from '../lazyDetailSurfaces.js';
import {
distinctLabels,
planSubmittedRecord,
Expand Down Expand Up @@ -608,7 +609,7 @@ export function SubmittedChildTables({ model, className }: { model: SubmittedRec
data-submitted-child={relation.childObject}
>
<p className="mb-2 text-xs text-muted-foreground" data-submitted-child-note>{note}</p>
<RelatedList
<LazyRelatedList
title={title}
type="table"
api={relation.childObject}
Expand Down
Loading
Loading