From 9de80a7f906000b4400b7219899352218246a516 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 03:27:47 +0000 Subject: [PATCH 1/4] perf(console): plugin-grid and plugin-detail leave the first load (wip) Claude-Session: https://claude.ai/code/session_01FEkQ5kt9AD1TPLy7Y9oa9D Co-Authored-By: Claude --- ui/apps/console/src/App.tsx | 6 +- ui/apps/console/src/register-plugins.ts | 55 +++++++++++++-- ui/apps/console/vite.config.ts | 10 ++- .../app-shell/src/hooks/sharedUserFeeds.ts | 2 +- .../app-shell/src/utils/deriveRelatedLists.ts | 2 +- .../src/utils/workspacePreference.ts | 2 +- .../approval-decision/SubmittedRecord.tsx | 5 +- .../src/views/lazyDetailSurfaces.tsx | 68 +++++++++++++++++++ .../record-preview/RecordPreviewCard.tsx | 8 ++- .../src/views/recordDetailSections.ts | 2 +- .../app-shell/src/views/recordDrawerStack.tsx | 2 +- .../app-shell/src/views/recordPagePayload.ts | 2 +- ui/packages/plugin-detail/src/RelatedList.tsx | 26 ++----- ui/packages/plugin-detail/src/core.ts | 51 ++++++++++++++ .../plugin-detail/src/relatedListSort.ts | 30 ++++++++ 15 files changed, 230 insertions(+), 41 deletions(-) create mode 100644 ui/packages/app-shell/src/views/lazyDetailSurfaces.tsx create mode 100644 ui/packages/plugin-detail/src/core.ts create mode 100644 ui/packages/plugin-detail/src/relatedListSort.ts diff --git a/ui/apps/console/src/App.tsx b/ui/apps/console/src/App.tsx index 80fb26c3025..e30d8fa5e80 100644 --- a/ui/apps/console/src/App.tsx +++ b/ui/apps/console/src/App.tsx @@ -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, @@ -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`; @@ -481,7 +483,7 @@ export function App() { {/* Dev-only: row-action inline-overflow (multiple primary actions). */} - + }> } /> 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', diff --git a/ui/apps/console/vite.config.ts b/ui/apps/console/vite.config.ts index bd12e83f226..f2c19fd620f 100644 --- a/ui/apps/console/vite.config.ts +++ b/ui/apps/console/vite.config.ts @@ -627,6 +627,7 @@ const workspaceAliases: Record = { // `@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'), @@ -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 @@ -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) // diff --git a/ui/packages/app-shell/src/hooks/sharedUserFeeds.ts b/ui/packages/app-shell/src/hooks/sharedUserFeeds.ts index 09b38fd42aa..2eb71a2710e 100644 --- a/ui/packages/app-shell/src/hooks/sharedUserFeeds.ts +++ b/ui/packages/app-shell/src/hooks/sharedUserFeeds.ts @@ -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'; diff --git a/ui/packages/app-shell/src/utils/deriveRelatedLists.ts b/ui/packages/app-shell/src/utils/deriveRelatedLists.ts index 15f3a647a91..b4818dc4b93 100644 --- a/ui/packages/app-shell/src/utils/deriveRelatedLists.ts +++ b/ui/packages/app-shell/src/utils/deriveRelatedLists.ts @@ -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']); diff --git a/ui/packages/app-shell/src/utils/workspacePreference.ts b/ui/packages/app-shell/src/utils/workspacePreference.ts index dda7df8a4be..599802331fb 100644 --- a/ui/packages/app-shell/src/utils/workspacePreference.ts +++ b/ui/packages/app-shell/src/utils/workspacePreference.ts @@ -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 diff --git a/ui/packages/app-shell/src/views/approval-decision/SubmittedRecord.tsx b/ui/packages/app-shell/src/views/approval-decision/SubmittedRecord.tsx index 6b49b5cda26..110fe69adb9 100644 --- a/ui/packages/app-shell/src/views/approval-decision/SubmittedRecord.tsx +++ b/ui/packages/app-shell/src/views/approval-decision/SubmittedRecord.tsx @@ -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, @@ -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, @@ -608,7 +609,7 @@ export function SubmittedChildTables({ model, className }: { model: SubmittedRec data-submitted-child={relation.childObject} >

{note}

- | undefined; + +/** Starts loading the detail entry (once); the lazy components below share it. */ +export function preloadDetailEntry(): Promise { + // A failed load is forgotten, so the next draw asks again. + detailEntry ??= import('@object-ui/plugin-detail').catch((error: unknown) => { + detailEntry = undefined; + throw error; + }); + return detailEntry; +} + +const HeaderHighlightChunk = lazy(() => preloadDetailEntry().then((m) => ({ default: m.HeaderHighlight }))); +const RelatedListChunk = lazy(() => preloadDetailEntry().then((m) => ({ default: m.RelatedList }))); + +/** `HeaderHighlight`, loaded on first draw. Nothing shows until the detail chunk is in. */ +export function LazyHeaderHighlight(props: ComponentProps) { + return ( + + + + ); +} + +/** `RelatedList`, loaded on first draw. Nothing shows until the detail chunk is in. */ +export function LazyRelatedList(props: ComponentProps) { + return ( + + + + ); +} diff --git a/ui/packages/app-shell/src/views/record-preview/RecordPreviewCard.tsx b/ui/packages/app-shell/src/views/record-preview/RecordPreviewCard.tsx index 0151868f971..57cb44a1869 100644 --- a/ui/packages/app-shell/src/views/record-preview/RecordPreviewCard.tsx +++ b/ui/packages/app-shell/src/views/record-preview/RecordPreviewCard.tsx @@ -107,7 +107,7 @@ import { useEffect, useMemo, useState } from 'react'; import { Card, CardContent, CardHeader, CardTitle, EmptyValue, cn } from '@object-ui/components'; import { buildExpandFields, getRecordDisplayName, withoutDeniedFields } from '@object-ui/core'; -import { deriveHighlightFields, HeaderHighlight } from '@object-ui/plugin-detail'; +import { deriveHighlightFields } from '@object-ui/plugin-detail/core'; import { usePermissions } from '@object-ui/permissions'; import { InlineEditProvider, @@ -121,6 +121,7 @@ import type { QueryParams } from '@object-ui/types'; import { Link2Off, Loader2 } from 'lucide-react'; import { servedObjectLabel } from '../../hooks/servedObjectLabel.js'; import { useReportRecordRead } from '../approval-decision/recordReadReport.js'; +import { LazyHeaderHighlight, preloadDetailEntry } from '../lazyDetailSurfaces.js'; /** * The one read the card makes. Structural, so the console's adapter satisfies @@ -193,6 +194,9 @@ export function RecordPreviewCard({ objectName, recordId, dataSource, className if (targetObject === null || targetRecord === null || targetKey === null) return; if (!defReady || !dataSource?.findOne) return; let cancelled = false; + // The key fields draw through the detail chunk: fetch it beside the read. + // A failed load surfaces where the strip draws, not here. + preloadDetailEntry().catch(() => undefined); const expand: string[] = JSON.parse(expandKey); // The executor runs synchronously, so a data source that THROWS rather than // rejecting lands in the same branch as a rejection. @@ -298,7 +302,7 @@ export function RecordPreviewCard({ objectName, recordId, dataSource, className - ({ name, label: def.fields?.[name]?.label }))} diff --git a/ui/packages/app-shell/src/views/recordDetailSections.ts b/ui/packages/app-shell/src/views/recordDetailSections.ts index 01bc7b3d1fa..bd67ec33415 100644 --- a/ui/packages/app-shell/src/views/recordDetailSections.ts +++ b/ui/packages/app-shell/src/views/recordDetailSections.ts @@ -22,7 +22,7 @@ * Pinned by `recordDetailSections.agreement-12442.test.ts` beside this file. */ -import { deriveFieldGroupDetailSections, resolveDetailSections } from '@object-ui/plugin-detail'; +import { deriveFieldGroupDetailSections, resolveDetailSections } from '@object-ui/plugin-detail/core'; import { BUILT_IN_LANGUAGE_CODES, loadBuiltInLocale } from '@object-ui/i18n'; import { AUDIT_FIELD_NAMES, HIDDEN_SYSTEM_FIELD_NAMES } from './record-detail-system-fields.js'; diff --git a/ui/packages/app-shell/src/views/recordDrawerStack.tsx b/ui/packages/app-shell/src/views/recordDrawerStack.tsx index 947c6a141f1..336484b0c5f 100644 --- a/ui/packages/app-shell/src/views/recordDrawerStack.tsx +++ b/ui/packages/app-shell/src/views/recordDrawerStack.tsx @@ -67,7 +67,7 @@ import { overlayWidthFor } from '@object-ui/plugin-view/core'; import type { FieldContainerLike } from '@object-ui/core'; import { useObjectLabel, useObjectTranslation } from '@object-ui/i18n'; import { servedObjectLabel, servedObjectPluralLabel } from '../hooks/servedObjectLabel.js'; -import { prefetchRelatedCounts, relatedCountTargetsIn } from '@object-ui/plugin-detail'; +import { prefetchRelatedCounts, relatedCountTargetsIn } from '@object-ui/plugin-detail/core'; import { useFilterScope } from '@object-ui/react'; import { RECORD_DETAIL_TAB_PARAM, diff --git a/ui/packages/app-shell/src/views/recordPagePayload.ts b/ui/packages/app-shell/src/views/recordPagePayload.ts index fa58f4a08d1..0fc0574e03c 100644 --- a/ui/packages/app-shell/src/views/recordPagePayload.ts +++ b/ui/packages/app-shell/src/views/recordPagePayload.ts @@ -63,7 +63,7 @@ import { seedQueueClaimDecision, seedRecordFieldAccess, seedRecordVerdict, -} from '@object-ui/plugin-detail'; +} from '@object-ui/plugin-detail/core'; import type { RecordFieldAccess, RecordPageOperation, diff --git a/ui/packages/plugin-detail/src/RelatedList.tsx b/ui/packages/plugin-detail/src/RelatedList.tsx index 73dc80b7f4d..b02af9b9661 100644 --- a/ui/packages/plugin-detail/src/RelatedList.tsx +++ b/ui/packages/plugin-detail/src/RelatedList.tsx @@ -108,6 +108,7 @@ import { import { relatedCardId } from './synth/relatedArrangement'; import { relatedTabConditionsChanged, useRelatedTabConditions } from './relatedTabConditions'; import { RelatedCardMenu, RelatedPanelHandle } from './RelatedCardMenu'; +import { normalizeSortSpec } from './relatedListSort'; import { detectStatusField } from '@object-ui/types'; export interface RelatedListProps { @@ -383,28 +384,9 @@ function resolveRelatedLookupLabel(record: any, refSchema: any): string | undefi ); } -/** - * Normalize the spec `sort` union (`'field'` / `'-field'` string or - * `[{field, order}]`) into the object-array form fed to `$orderby`. - */ -/** - * A related list's declared sort as the row read sends it (`$orderby`). The - * record page's payload asks a list's first rows in this order - * (objectstack#27627), so a compact card can take them. - */ -export function normalizeSortSpec( - sort: RelatedListProps['defaultSort'], -): Array<{ field: string; order: 'asc' | 'desc' }> { - if (!sort) return []; - if (typeof sort === 'string') { - const trimmed = sort.trim(); - if (!trimmed) return []; - return trimmed.startsWith('-') - ? [{ field: trimmed.slice(1), order: 'desc' }] - : [{ field: trimmed, order: 'asc' }]; - } - return sort.filter((s) => !!s?.field); -} +// The sort normalizer lives in its own module so the side-effect-free +// `/core` subpath can export it without this component. +export { normalizeSortSpec }; /** The permission context this component reads field-level security from. */ type FieldReadPolicy = ReturnType; diff --git a/ui/packages/plugin-detail/src/core.ts b/ui/packages/plugin-detail/src/core.ts new file mode 100644 index 00000000000..c3ed609ae20 --- /dev/null +++ b/ui/packages/plugin-detail/src/core.ts @@ -0,0 +1,51 @@ +/** + * 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. + * + * `@object-ui/plugin-detail/core` — the side-effect-free half of this package. + * + * The package root registers the detail and record-page renderers with + * `ComponentRegistry` when it is evaluated and statically reaches every detail + * surface, so a host that imports one pure helper from the root keeps all of + * it in its own chunk. The console shell imports the helpers below from this + * subpath instead, and the detail renderers load (and register) only when a + * record page or a detail block is drawn. + * + * ⛔ Nothing exported here may import a detail renderer, `./index` or a module + * that registers a component, directly or through a neighbour: the subpath is + * only worth having while its closure stays these helpers. The same names are + * still exported from the package root, unchanged. A module added to this + * file's closure also joins the console's `plugin-detail-core` chunk group + * (`apps/console/vite.config.ts`). + * + * The record-page caches the payload seeds write (`seedRecordVerdict`, + * `seedRecordFieldAccess`, `seedQueueClaimDecision`) are module state their + * hooks read from the root. Both entries reach the same module, so a seed + * written through this subpath is the one the root's hooks read: the console + * resolves both to the one source module, and the published ESM build emits + * the two entries from one pass with the modules they share in shared files. + */ + +export { isRefusedFeedRead } from './renderers/recordActivityFeed'; +export { relatedListEntryNames } from './synth/relatedListEntry'; +export { + RELATED_ARRANGEMENT_RECORD_VERSION, + relatedArrangementFromRecord, + relatedArrangementToRecord, +} from './synth/relatedArrangement'; +export type { RelatedArrangement } from './synth/relatedArrangement'; +export { + deriveFieldGroupDetailSections, + deriveHighlightFields, + resolveDetailSections, +} from './synth/buildDefaultPageSchema'; +export { isWideFieldType } from './autoLayout'; +export { prefetchRelatedCounts, relatedCountTargetsIn } from './useRelatedCounts'; +export { COMPACT_RELATED_ROWS } from './relatedListCompact'; +export { normalizeSortSpec as normalizeRelatedListSort } from './relatedListSort'; +export { seedQueueClaimDecision } from './queueClaim'; +export { seedRecordFieldAccess } from './recordFieldAccess'; +export { seedRecordVerdict } from './useRecordEditable'; diff --git a/ui/packages/plugin-detail/src/relatedListSort.ts b/ui/packages/plugin-detail/src/relatedListSort.ts new file mode 100644 index 00000000000..ae357263185 --- /dev/null +++ b/ui/packages/plugin-detail/src/relatedListSort.ts @@ -0,0 +1,30 @@ +/** + * 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 spec `sort` union a related list declares: `'field'` / `'-field'`, or `[{ field, order }]`. */ +export type RelatedListSortSpec = string | Array<{ field: string; order: 'asc' | 'desc' }>; + +/** + * A related list's declared sort as the row read sends it (`$orderby`): the + * spec `sort` union normalized into the object-array form. The record page's + * payload asks a list's first rows in this order (objectstack#27627), so a + * compact card can take them. + */ +export function normalizeSortSpec( + sort: RelatedListSortSpec | undefined, +): Array<{ field: string; order: 'asc' | 'desc' }> { + if (!sort) return []; + if (typeof sort === 'string') { + const trimmed = sort.trim(); + if (!trimmed) return []; + return trimmed.startsWith('-') + ? [{ field: trimmed.slice(1), order: 'desc' }] + : [{ field: trimmed, order: 'asc' }]; + } + return sort.filter((s) => !!s?.field); +} From 5ca063618fe73d1c3899231bf40e0374de11d064 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 03:55:00 +0000 Subject: [PATCH 2/4] perf(plugin-detail): publish a side-effect-free /core subpath from one ESM pass (wip) Claude-Session: https://claude.ai/code/session_01FEkQ5kt9AD1TPLy7Y9oa9D Co-Authored-By: Claude --- .../pluginCoreSubpaths-33581.test.ts | 4 ++ .../app-shell/src/views/RecordDetailView.tsx | 3 +- ui/packages/plugin-detail/package.json | 8 ++- ui/packages/plugin-detail/vite.config.ts | 7 ++- ui/packages/plugin-detail/vite.es.config.ts | 51 +++++++++++++++++++ 5 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 ui/packages/plugin-detail/vite.es.config.ts diff --git a/ui/packages/app-shell/src/__tests__/pluginCoreSubpaths-33581.test.ts b/ui/packages/app-shell/src/__tests__/pluginCoreSubpaths-33581.test.ts index c0ceeed3ce0..4443f3b106d 100644 --- a/ui/packages/app-shell/src/__tests__/pluginCoreSubpaths-33581.test.ts +++ b/ui/packages/app-shell/src/__tests__/pluginCoreSubpaths-33581.test.ts @@ -36,6 +36,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'; @@ -48,6 +49,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(), } as const; type Entry = keyof typeof ENTRIES; diff --git a/ui/packages/app-shell/src/views/RecordDetailView.tsx b/ui/packages/app-shell/src/views/RecordDetailView.tsx index 2a7d53b9d81..5ecc973f0b7 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.tsx @@ -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, 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, 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'; diff --git a/ui/packages/plugin-detail/package.json b/ui/packages/plugin-detail/package.json index deeee7c42c3..b759d9f4298 100644 --- a/ui/packages/plugin-detail/package.json +++ b/ui/packages/plugin-detail/package.json @@ -17,11 +17,13 @@ "module": "dist/index.js", "types": "dist/index.d.ts", "sideEffects": [ + "./dist/core.js", "./dist/index.js", "./dist/index.umd.cjs", "./dist/queueClaim.js", "./dist/recordFieldAccess.js", "./dist/useRecordEditable.js", + "./src/core.ts", "./src/index.tsx", "./src/queueClaim.ts", "./src/recordFieldAccess.tsx", @@ -32,10 +34,14 @@ "types": "./dist/index.d.ts", "import": "./dist/index.js", "require": "./dist/index.umd.cjs" + }, + "./core": { + "types": "./dist/core.d.ts", + "import": "./dist/core.js" } }, "scripts": { - "build": "vite build", + "build": "vite build && vite build --config vite.es.config.ts", "test": "vitest run --root ../.. packages/plugin-detail/", "test:watch": "vitest --root ../.. packages/plugin-detail/", "type-check": "tsc --noEmit && tsc -p tsconfig.test.json", diff --git a/ui/packages/plugin-detail/vite.config.ts b/ui/packages/plugin-detail/vite.config.ts index a09f588789c..d4bd5c72a42 100644 --- a/ui/packages/plugin-detail/vite.config.ts +++ b/ui/packages/plugin-detail/vite.config.ts @@ -60,8 +60,11 @@ export default defineConfig({ lib: { entry: resolve(__dirname, 'src/index.tsx'), name: 'ObjectUIPluginDetail', - formats: ['es', 'umd'], - fileName: (format) => `index.${format === 'es' ? 'js' : 'umd.cjs'}`, + // The UMD build only. The ESM build (`dist/index.js`, `dist/core.js`) + // is `vite.es.config.ts`, a second pass: a lib build with more than one + // entry cannot emit UMD. + formats: ['umd'], + fileName: () => 'index.umd.cjs', }, rollupOptions: { // IMPORTANT: do NOT inline @object-ui/* runtime packages. diff --git a/ui/packages/plugin-detail/vite.es.config.ts b/ui/packages/plugin-detail/vite.es.config.ts new file mode 100644 index 00000000000..5530d0ec54c --- /dev/null +++ b/ui/packages/plugin-detail/vite.es.config.ts @@ -0,0 +1,51 @@ +/** + * 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. + */ + +import { defineConfig } from 'vite'; +import react from '@vitejs/plugin-react'; +import { resolve } from 'path'; + +/** + * Second build pass: the ESM build, `dist/index.js` (the package root) and + * `dist/core.js` (the `@object-ui/plugin-detail/core` subpath, see + * `src/core.ts`). + * + * Both entries come from ONE pass with `preserveModules`, so a module both + * reach is one file both import. The record-page caches the `/core` seeds + * write (`queueClaim`, `recordFieldAccess`, `useRecordEditable`) are module + * state the root's hooks read; two bundles would each carry their own copy, + * and a seed written through `/core` would never reach the root. One file per + * source module is also the published spelling the `sideEffects` array names + * (`./dist/queueClaim.js` beside `./src/queueClaim.ts`). + * + * The typings and the UMD build come from the main pass (`vite.config.ts`), + * which runs first. ⛔ `emptyOutDir: false`: this pass must not delete them. + */ +export default defineConfig({ + plugins: [react()], + build: { + emptyOutDir: false, + lib: { + entry: { + index: resolve(__dirname, 'src/index.tsx'), + core: resolve(__dirname, 'src/core.ts'), + }, + formats: ['es'], + }, + rollupOptions: { + // ⛔ Never inline the @object-ui/* runtime packages: every plugin shares + // the one `ComponentRegistry` of `@object-ui/core` (see vite.config.ts). + external: (id) => !/^[./]/.test(id) && !id.startsWith(__dirname), + output: { + preserveModules: true, + preserveModulesRoot: resolve(__dirname, 'src'), + entryFileNames: '[name].js', + }, + }, + }, +}); From 10d582ff492cf013f03689b4eb7b0fc98fd9e8be Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 04:04:05 +0000 Subject: [PATCH 3/4] test(ui): pin the detail /core subpath and the grid-free eager modules (wip) Claude-Session: https://claude.ai/code/session_01FEkQ5kt9AD1TPLy7Y9oa9D Co-Authored-By: Claude --- .../33581-plugin-detail-core-subpath.md | 16 +++++++++ .../pluginCoreSubpaths-33581.test.ts | 33 ++++++++++++++----- .../check-side-effects-array.test.ts | 3 +- ...de-effects-declaration-consistency.test.ts | 1 + 4 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 .changeset/33581-plugin-detail-core-subpath.md diff --git a/.changeset/33581-plugin-detail-core-subpath.md b/.changeset/33581-plugin-detail-core-subpath.md new file mode 100644 index 00000000000..db609acb791 --- /dev/null +++ b/.changeset/33581-plugin-detail-core-subpath.md @@ -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. diff --git a/ui/packages/app-shell/src/__tests__/pluginCoreSubpaths-33581.test.ts b/ui/packages/app-shell/src/__tests__/pluginCoreSubpaths-33581.test.ts index 4443f3b106d..1f474da185e 100644 --- a/ui/packages/app-shell/src/__tests__/pluginCoreSubpaths-33581.test.ts +++ b/ui/packages/app-shell/src/__tests__/pluginCoreSubpaths-33581.test.ts @@ -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 @@ -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 @@ -104,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']) { @@ -113,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', () => { @@ -131,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', @@ -143,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) { diff --git a/ui/scripts/__tests__/check-side-effects-array.test.ts b/ui/scripts/__tests__/check-side-effects-array.test.ts index 003e9770400..fb6992fd055 100644 --- a/ui/scripts/__tests__/check-side-effects-array.test.ts +++ b/ui/scripts/__tests__/check-side-effects-array.test.ts @@ -795,7 +795,7 @@ describe('the real workspace — the population this widening was measured again const kinds = results.flatMap((r) => r.entryForms.map((e) => e.kind)); expect(kinds).toContain('asset'); // @object-ui/app-shell's `./styles.css` expect(results.flatMap((r) => r.entryForms.flatMap((e) => e.alternateFormats)).length).toBeGreaterThan(0); - // ...and the genuine multi-entry population is exactly the two `/core` + // ...and the genuine multi-entry population is exactly the three `/core` // subpaths objectstack#33581 published: side-effect-free secondary entry // points, walked as roots of their own (and finding no registrar, which is // their point). Every other package still walks from one root. A package @@ -804,6 +804,7 @@ describe('the real workspace — the population this widening was measured again results.filter((r) => r.entryPoints.length > 1).map((r) => [r.name, r.entryPoints]), ); expect(multi).toEqual({ + '@object-ui/plugin-detail': ['src/core.ts', 'src/index.tsx'], '@object-ui/plugin-form': ['src/core.ts', 'src/index.tsx'], '@object-ui/plugin-view': ['src/core.ts', 'src/index.tsx'], }); diff --git a/ui/scripts/__tests__/side-effects-declaration-consistency.test.ts b/ui/scripts/__tests__/side-effects-declaration-consistency.test.ts index 737ea43dbf3..a4ff4c6257a 100644 --- a/ui/scripts/__tests__/side-effects-declaration-consistency.test.ts +++ b/ui/scripts/__tests__/side-effects-declaration-consistency.test.ts @@ -1451,6 +1451,7 @@ describe('`sideEffects` declarations match load-time behaviour (objectui#3943)', ); expect(exempt).toContain('@object-ui/plugin-form/src/core.ts'); expect(exempt).toContain('@object-ui/plugin-view/src/core.ts'); + expect(exempt).toContain('@object-ui/plugin-detail/src/core.ts'); expect(exempt.filter((e) => /\/src\/index\.[a-z]+$/.test(e))).toEqual([]); }); From feb24f5308e45b35475fc0bb2ebd7a47f4c49dab Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 04:52:45 +0000 Subject: [PATCH 4/4] fix(app-shell): a detail surface mounted after the entry loaded draws without suspending Claude-Session: https://claude.ai/code/session_01FEkQ5kt9AD1TPLy7Y9oa9D Co-Authored-By: Claude --- .../src/views/lazyDetailSurfaces.tsx | 34 +++++++++++++++---- .../record-preview/RecordPreviewCard.test.tsx | 7 +++- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/ui/packages/app-shell/src/views/lazyDetailSurfaces.tsx b/ui/packages/app-shell/src/views/lazyDetailSurfaces.tsx index 5d5da81d7aa..76be8b3b6de 100644 --- a/ui/packages/app-shell/src/views/lazyDetailSurfaces.tsx +++ b/ui/packages/app-shell/src/views/lazyDetailSurfaces.tsx @@ -26,7 +26,7 @@ * entry. */ -import { lazy, Suspense, type ComponentProps } from 'react'; +import { lazy, Suspense, useState, type ComponentProps } from 'react'; import type { HeaderHighlight as HeaderHighlightComponent, RelatedList as RelatedListComponent, @@ -35,22 +35,37 @@ import type { type DetailEntry = typeof import('@object-ui/plugin-detail'); let detailEntry: Promise | undefined; +/** The entry once it has loaded: a surface mounted after that renders it without suspending. */ +let loadedEntry: DetailEntry | undefined; /** Starts loading the detail entry (once); the lazy components below share it. */ export function preloadDetailEntry(): Promise { // A failed load is forgotten, so the next draw asks again. - detailEntry ??= import('@object-ui/plugin-detail').catch((error: unknown) => { - detailEntry = undefined; - throw error; - }); + detailEntry ??= import('@object-ui/plugin-detail').then( + (entry) => { + loadedEntry = entry; + return entry; + }, + (error: unknown) => { + detailEntry = undefined; + throw error; + }, + ); return detailEntry; } const HeaderHighlightChunk = lazy(() => preloadDetailEntry().then((m) => ({ default: m.HeaderHighlight }))); const RelatedListChunk = lazy(() => preloadDetailEntry().then((m) => ({ default: m.RelatedList }))); -/** `HeaderHighlight`, loaded on first draw. Nothing shows until the detail chunk is in. */ +/** + * `HeaderHighlight`, loaded on first draw. Nothing shows until the detail chunk + * is in; once it is, the component draws in the same render. + */ export function LazyHeaderHighlight(props: ComponentProps) { + // Decided once per mount, so a draw never switches between the two element + // types (which would remount the component and drop its state). + const [entry] = useState(() => loadedEntry); + if (entry) return ; return ( @@ -58,8 +73,13 @@ export function LazyHeaderHighlight(props: ComponentProps) { + const [entry] = useState(() => loadedEntry); + if (entry) return ; return ( diff --git a/ui/packages/app-shell/src/views/record-preview/RecordPreviewCard.test.tsx b/ui/packages/app-shell/src/views/record-preview/RecordPreviewCard.test.tsx index a18f876cf4a..a6b26136f90 100644 --- a/ui/packages/app-shell/src/views/record-preview/RecordPreviewCard.test.tsx +++ b/ui/packages/app-shell/src/views/record-preview/RecordPreviewCard.test.tsx @@ -33,6 +33,10 @@ import { PermissionProvider } from '@object-ui/permissions'; import { createI18n, I18nProvider } from '@object-ui/i18n'; import { MetadataProvider } from '../../providers/MetadataProvider'; import { RecordPreviewCard, type RecordPreviewSource } from './RecordPreviewCard'; +// The key fields draw through `lazy()` (`lazyDetailSurfaces.tsx`): load the +// detail entry at module scope, so its cost is paid at import and never inside +// a test's waits (ui/AGENTS.md, lazy boundaries in tests). +import '@object-ui/plugin-detail'; const OBJECT = 'invoice_12029'; @@ -136,7 +140,8 @@ describe('RecordPreviewCard — loading and readable (objectui#12029)', () => { expect(screen.getByTitle('Laptop refresh')).toHaveTextContent('Laptop refresh'); expect(screen.queryByText('INV-0001')).toBeNull(); expect(screen.getByText('Invoice')).toBeInTheDocument(); - expect(screen.getByText('Note')).toBeInTheDocument(); + // The key-field strip sits behind the detail entry's lazy boundary. + expect(await screen.findByText('Note')).toBeInTheDocument(); expect(screen.getByText('Quarterly batch')).toBeInTheDocument(); // One read, the record page's request shape: no reference field is shown,