From dba2847a24439a31a05d2a8fb1ca0753e2785ec4 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 05:00:09 +0000 Subject: [PATCH 1/4] perf(console): Studio en strings and metadata-form strings load with the screens that read them The default Studio canvas moves to its own module and registers through lazyPage, which moves to services/lazyPage.tsx so every such registration shares one wrapper. The datasource page, the position list's two cells, the create-view dialog and the Pending changes sheet load on first draw. The studio namespace loader gets its own chunk group, so the eager i18n-runtime chunk stops carrying its static en edge. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5ousB2MKFUbJFc3Hwp --- ui/apps/console/vite.config.ts | 10 + .../app-shell/src/preview/DraftPreviewBar.tsx | 15 +- .../src/services/builtinComponents.tsx | 64 +++-- .../app-shell/src/services/lazyPage.tsx | 53 ++++ .../app-shell/src/views/ObjectView.tsx | 23 +- .../metadata-admin/datasource/register.ts | 13 +- .../studio-design/studio-canvas-preview.tsx | 237 ++--------------- .../studio-object-records-canvas.tsx | 243 ++++++++++++++++++ 8 files changed, 394 insertions(+), 264 deletions(-) create mode 100644 ui/packages/app-shell/src/services/lazyPage.tsx create mode 100644 ui/packages/app-shell/src/views/studio-design/studio-object-records-canvas.tsx diff --git a/ui/apps/console/vite.config.ts b/ui/apps/console/vite.config.ts index 4f975c8eeae..0498dd10ff5 100644 --- a/ui/apps/console/vite.config.ts +++ b/ui/apps/console/vite.config.ts @@ -1235,6 +1235,16 @@ export default defineConfig({ // `en` is the namespace's resident fallback and gets its own chunk so // its bytes are named in `eager-closure.json` instead of hiding in // the runtime's. + // + // The loader module (`index.ts`, which imports `en` statically: the + // synchronous fallback, objectstack#25922) gets a group too, for the + // marketplace loader's reason below: without one it falls to the + // eager `i18n-runtime` group, and its static `en` edge put the 64 KB + // `en` catalogue on every console route, though only the Studio + // and Setup screens that import `metadata-admin/i18n.ts` read it + // (objectstack#33582). `includeDependenciesRecursively: false` for + // the same measured reason as the marketplace loader's. + { name: 'i18n-ns-studio', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]studio[\\/]index\.ts$/, priority: 84, includeDependenciesRecursively: false }, { name: 'i18n-ns-studio-en', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]studio[\\/]en\.ts$/, priority: 84 }, { name: 'i18n-ns-studio-zh', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]studio[\\/]zh\.ts$/, priority: 84 }, // diff --git a/ui/packages/app-shell/src/preview/DraftPreviewBar.tsx b/ui/packages/app-shell/src/preview/DraftPreviewBar.tsx index 80a7a2b1d97..81768aeab7e 100644 --- a/ui/packages/app-shell/src/preview/DraftPreviewBar.tsx +++ b/ui/packages/app-shell/src/preview/DraftPreviewBar.tsx @@ -14,7 +14,7 @@ * keeps a read-only preview from ever being confused with the live app. */ -import { useEffect, useMemo, useState } from 'react'; +import { lazy, Suspense, useEffect, useMemo, useState } from 'react'; import { useLocation, useNavigate, useParams } from 'react-router-dom'; import { Eye, X, Rocket, GitCompareArrows, Sparkles } from 'lucide-react'; import { Button, cn } from '@object-ui/components'; @@ -22,7 +22,14 @@ import { useObjectTranslation } from '@object-ui/i18n'; import { usePreviewDrafts, markPreviewExit, PREVIEW_QUERY_FLAG } from './PreviewModeContext.js'; import { usePendingDrafts } from './usePendingDrafts.js'; import { usePublishAllDrafts } from './usePublishAllDrafts.js'; -import { DraftChangesPanel } from './DraftChangesPanel.js'; +// objectstack#33582: the Pending changes sheet loads with the bar, not with the +// console. The bar is in every route's EAGER graph (`ConsoleLayout`), and the +// sheet, closed until asked for, held the metadata form strings and the object +// field reader there by value. Drawn only in preview mode, the bar fetches it +// as it appears, before anyone can open it. +const DraftChangesPanel = lazy(() => + import('./DraftChangesPanel.js').then((m) => ({ default: m.DraftChangesPanel })), +); import { draftSurfaceOf, draftsOnSurface } from './draftSurface.js'; export function DraftPreviewBar() { @@ -182,7 +189,9 @@ export function DraftPreviewBar() { : t('preview.draftBar.publishCta', { defaultValue: 'Publish to see it live' })} - + + + )} diff --git a/ui/packages/app-shell/src/services/builtinComponents.tsx b/ui/packages/app-shell/src/services/builtinComponents.tsx index ec73e832d58..6a6fe76075e 100644 --- a/ui/packages/app-shell/src/services/builtinComponents.tsx +++ b/ui/packages/app-shell/src/services/builtinComponents.tsx @@ -15,10 +15,10 @@ * metadata type. */ -import { lazy, Suspense, type ComponentType } from 'react'; +import { lazy, Suspense } from 'react'; import { registerAppComponent } from './componentRegistry.js'; +import { lazyPage, LazyPageFallback as MetadataAdminFallback } from './lazyPage.js'; import { registerMetadataResource } from '../views/metadata-admin/registry.js'; -import { PositionGrantedSetsCell, PositionHolderCountCell } from '../views/metadata-admin/PositionGrantCells.js'; import { CONNECTOR_CREDENTIALS_REF } from '../views/setup/connectorCredentials.js'; import { CONNECTOR_CONNECTIONS_REF } from '../views/setup/connectorConnections.js'; import { PERMISSION_SET_ASSIGNMENT_REF, POSITION_HOLDERS_REF } from '../views/setup/peopleAssignments.js'; @@ -94,42 +94,22 @@ const MetadataResourceRouter = lazy(() => import('../views/metadata-admin/index.js').then((m) => ({ default: m.MetadataResourceRouter })), ); -function MetadataAdminFallback({ label }: { label: string }) { - return
Loading {label}…
; -} - /** - * A page registered BY REFERENCE to its module, loaded the first time it is - * drawn (objectstack#33293). Every page below was imported here by value, and - * this module is a side-effect import of the package entry, so each one, with - * everything it imports, was in the console's EAGER closure: on a dashboard - * route the browser downloaded the Packages page, its package form dialog, the - * permission-matrix editor and the Setup assignment pages before it asked for - * data. Measured from `apps/console/dist/eager-closure.json` and the emitted - * chunks' module lists, not from a source search (see the trap above): with - * these registrations lazy, the `PackageFormDialog` and - * `PositionHoldersSection` chunks leave the closure. + * Pages registered BY REFERENCE to their module, loaded the first time they are + * drawn (objectstack#33293), through the one wrapper `./lazyPage.tsx`, whose + * header says why. Every page below was imported here by value, and this module + * is a side-effect import of the package entry, so each one, with everything it + * imports, was in the console's EAGER closure: on a dashboard route the browser + * downloaded the Packages page, its package form dialog, the permission-matrix + * editor and the Setup assignment pages before it asked for data. Measured from + * `apps/console/dist/eager-closure.json` and the emitted chunks' module lists, + * not from a source search (see the trap above): with these registrations lazy, + * the `PackageFormDialog` and `PositionHoldersSection` chunks leave the closure. * - * The same shape as the two registrations above: the `Suspense` boundary lives - * inside the registered value, so `registerAppComponent` and - * `registerMetadataResource` still receive a component, and no render site - * learns about pending. ⛔ It only defers anything while nothing else in the - * package's eager graph names the page module statically; the barrel's - * `PackagedActionsPage` re-export is tree-shaken today because the console - * imports no such name. + * ⛔ It only defers anything while nothing else in the package's eager graph + * names the page module statically; the barrel's `PackagedActionsPage` + * re-export is tree-shaken today because the console imports no such name. */ -function lazyPage

(label: string, load: () => Promise>): ComponentType

{ - const Page = lazy(() => load().then((component) => ({ default: component }))); - function LazyPage(props: P) { - return ( - }> - - - ); - } - return LazyPage; -} - const PackagesPage = lazyPage('packages', () => import('../views/metadata-admin/PackagesPage.js').then((m) => m.PackagesPage), ); @@ -154,6 +134,20 @@ const PermissionSetAssignmentPage = lazyPage('permission set assignments', () => const RecycleBinPage = lazyPage('recycle bin', () => import('../views/setup/RecycleBinPage.js').then((m) => m.RecycleBinPage), ); +/** + * The position list's two served cells (objectstack#33582): by value they held + * `metadata-admin/i18n.ts`, and with it the Studio `en` string namespace, in the + * eager closure. A cell draws nothing until its module lands (no page-sized + * loading line inside a table cell); every cell shares the one load. + */ +const PositionHolderCountCell = lazyPage('position holders', () => + import('../views/metadata-admin/PositionGrantCells.js').then((m) => m.PositionHolderCountCell), + null, +); +const PositionGrantedSetsCell = lazyPage('position permission sets', () => + import('../views/metadata-admin/PositionGrantCells.js').then((m) => m.PositionGrantedSetsCell), + null, +); /** * The Suspense boundary lives INSIDE the registration value, which is the shape diff --git a/ui/packages/app-shell/src/services/lazyPage.tsx b/ui/packages/app-shell/src/services/lazyPage.tsx new file mode 100644 index 00000000000..885b43e7a67 --- /dev/null +++ b/ui/packages/app-shell/src/services/lazyPage.tsx @@ -0,0 +1,53 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * A component registered BY REFERENCE to its module, loaded the first time it + * is drawn (objectstack#33293, objectstack#33582). + * + * The package entry imports its registration modules for their side effects + * (`services/builtinComponents.tsx`, `views/metadata-admin/register-builtins.ts`, + * `views/studio-design/studio-canvas-preview.tsx`), so a component one of them + * registers BY VALUE is, with everything it imports, in the console's EAGER + * closure: every route downloads it before it asks for data, though only the + * page that draws it reads it. Registering the value this returns instead keeps + * the module behind a dynamic `import()` until the component first renders. + * + * The `Suspense` boundary lives INSIDE the returned component, so the registry + * that receives it still receives a component, and no render site learns about + * pending. ⛔ It only defers anything while nothing else in the package's eager + * graph names the module statically: measure from + * `apps/console/dist/eager-closure.json` and the emitted chunks' module lists, + * never from a source search (see the trap note in `builtinComponents.tsx`). + * + * One wrapper for every such registration; ⛔ do not grow a second one. + */ + +import { lazy, Suspense, type ComponentType, type ReactNode } from 'react'; + +/** The default while a page's module loads: one muted line naming the page. */ +export function LazyPageFallback({ label }: { label: string }) { + return

Loading {label}…
; +} + +/** + * Wrap `load` as a component that loads its module on first render. + * + * `fallback` replaces the page-sized loading line where the component is not a + * page, e.g. a list cell, which draws nothing until its module lands. + */ +export function lazyPage

( + label: string, + load: () => Promise>, + fallback?: ReactNode, +): ComponentType

{ + const Page = lazy(() => load().then((component) => ({ default: component }))); + const shown = fallback === undefined ? : fallback; + function LazyPage(props: P) { + return ( + + + + ); + } + return LazyPage; +} diff --git a/ui/packages/app-shell/src/views/ObjectView.tsx b/ui/packages/app-shell/src/views/ObjectView.tsx index 1ac9a90e071..556081718b0 100644 --- a/ui/packages/app-shell/src/views/ObjectView.tsx +++ b/ui/packages/app-shell/src/views/ObjectView.tsx @@ -38,7 +38,12 @@ const ViewConfigPanel = lazy(() => ); import { useMetadataClient } from './metadata-admin/useMetadata.js'; import { dropPublishedViewList } from './metadata-admin/viewListDrop.js'; -import { CreateViewDialog } from './CreateViewDialog.js'; +// objectstack#33582: the create-view dialog loads with the first list, as the +// view config panel above does. Statically, it held the dataset catalogue and, +// through it, the Studio `en` string namespace in the EAGER closure. +const CreateViewDialog = lazy(() => + import('./CreateViewDialog.js').then((m) => ({ default: m.CreateViewDialog })), +); import { usePreviewDrafts, } from '../preview/PreviewModeContext.js'; @@ -1396,13 +1401,15 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co /> - v.label).filter(Boolean)} - objectDef={objectDef} - onCreate={(cfg) => handleViewCreate(cfg)} - /> + + v.label).filter(Boolean)} + objectDef={objectDef} + onCreate={(cfg) => handleViewCreate(cfg)} + /> + { if (!open) setPersonalViewDialog(null); }} diff --git a/ui/packages/app-shell/src/views/metadata-admin/datasource/register.ts b/ui/packages/app-shell/src/views/metadata-admin/datasource/register.ts index 2b260a7c6db..9ff01db91a1 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/datasource/register.ts +++ b/ui/packages/app-shell/src/views/metadata-admin/datasource/register.ts @@ -16,7 +16,18 @@ */ import { registerMetadataResource } from '../registry.js'; -import { DatasourceResourcePage } from './DatasourceResourcePage.js'; +import { lazyPage } from '../../../services/lazyPage.js'; + +/** + * Registered by reference to its module (objectstack#33582): this module runs + * at load (`register-builtins.ts` is a side-effect import of the package + * entry), so the page by value held it, `metadata-admin/i18n.ts` with the + * Studio `en` string namespace, and the JSON-schema field reader in the + * console's eager closure, on every route. + */ +const DatasourceResourcePage = lazyPage('datasources', () => + import('./DatasourceResourcePage.js').then((m) => m.DatasourceResourcePage), +); let registered = false; diff --git a/ui/packages/app-shell/src/views/studio-design/studio-canvas-preview.tsx b/ui/packages/app-shell/src/views/studio-design/studio-canvas-preview.tsx index 7b40a8a52a8..88577d58c08 100644 --- a/ui/packages/app-shell/src/views/studio-design/studio-canvas-preview.tsx +++ b/ui/packages/app-shell/src/views/studio-design/studio-canvas-preview.tsx @@ -32,16 +32,11 @@ */ import * as React from 'react'; -import { SchemaRenderer, useMetadata } from '@object-ui/react'; -import { resolveViewId } from '@object-ui/core'; -import { useAuth } from '@object-ui/auth'; import { resolveHref, type NavTemplateContext } from '@object-ui/layout'; import type { NavigationEntryItem } from '@object-ui/types'; import type { ObjectNavItem } from '@objectstack/spec/ui'; -import { Database, Loader2 } from 'lucide-react'; import { parseUrlFilterTriples, type FilterTriple } from '../drillUrlFilters.js'; -import { findByName } from '../../hooks/useNavTargetLabel.js'; -import { t } from '../metadata-admin/i18n.js'; +import { lazyPage } from '../../services/lazyPage.js'; /** * Props handed to a Studio-canvas renderer. Intentionally a small, read-only @@ -263,223 +258,31 @@ export function navEntryListTarget( return { filter: [] }; } -/** - * Default Studio-canvas renderer for `object` leaves: the runtime records grid, - * exactly as the running app shows it (preview = runtime). Schema editing lives - * in the Data pillar, so this is the object-view grid — NOT the field-form - * designer that is the `object` entry in the MetadataPreviewRegistry. - * - * objectui#11774 — opened on a nav entry that slices the object (`filters`) or - * names one of its views (`viewName`), it shows that slice or that view, as the - * running app does (see {@link navEntryListTarget}). The named view is the - * object's own, from the merged `listViews` the shell's metadata holds — the - * map `ObjectView` and the rail's label resolver (`useNavTargetLabel`) read — - * handed to the renderer as the Studio's view preview hands one. With no entry - * (or a plain one) the schema is exactly the one this rendered before. - * - * objectui#11823 — while the Properties panel beside it holds a list view of - * this object ({@link StudioCanvasListViewContext}), that view is the one - * shown: the panel's buffer, so an edit shows here before it is published. - * The panel holds the view this canvas opens (the entry's named view, else the - * object's default list view, as the running app opens it). - * - * objectui#12508 — an object the Interfaces pillar names draft-only - * ({@link StudioCanvasDraftOnlyObjectsContext}) has no runtime yet: no schema - * and no records to read. The canvas says it is not published instead of - * mounting the grid, whose reads would answer 404. - * - * Exported so downstream renderers can compose/wrap it; override the default - * wholesale via `registerStudioCanvasPreview('object', …)`. - */ -export function StudioObjectRecordsCanvas(props: StudioCanvasPreviewProps) { - const { name, locale } = props; - // objectui#12508 — an object with only a draft has no runtime to preview, - // and while the pillar has not said, the grid waits rather than ask. - const draftOnly = React.useContext(StudioCanvasDraftOnlyObjectsContext); - if (draftOnly?.status === 'pending') { - return ( -

- {t('engine.studio.loading', locale)} -
- ); - } - if (draftOnly?.status === 'known' && draftOnly.names.has(name)) { - return ( -
-
- -
-
-

{t('engine.studio.if.objectUnpublishedTitle', locale)}

-

{t('engine.studio.if.objectUnpublishedHint', locale)}

-
-
- ); - } - return ; -} - -/** The runtime records grid {@link StudioObjectRecordsCanvas} renders for a published object. */ -function ObjectRecordsGrid({ name }: StudioCanvasPreviewProps) { - const entry = React.useContext(StudioCanvasNavEntryContext); - const edited = React.useContext(StudioCanvasListViewContext); - const editedView = edited && edited.objectName === name ? edited : null; - const { user, activeOrganization } = useAuth(); - const currentUserId = user?.id ?? null; - const currentOrgId = activeOrganization?.id ?? null; - // Keyed on the values, never on the context object's identity (AGENTS.md #10). - const navId = entry?.navId; - const filtersKey = JSON.stringify(entry?.filters ?? null); - const entryViewName = entry?.viewName; - const target = React.useMemo(() => { - const filters = (JSON.parse(filtersKey) as StudioCanvasNavEntry['filters'] | null) ?? undefined; - return navEntryListTarget(name, { navId, filters, viewName: entryViewName }, { currentUserId, currentOrgId }); - }, [name, navId, filtersKey, entryViewName, currentUserId, currentOrgId]); - // Read only for an entry that names a view: a plain entry asks the metadata - // cache for nothing, as before. The panel's view, when there is one, is - // shown instead of the cache's (objectui#11823). - const metadata = useMetadata(); - const objectViews = !editedView && target.viewName ? listViewsOf(findByName(metadata.objects, name)) : undefined; - const viewId = editedView - ? editedView.viewId - : objectViews && target.viewName - ? resolveViewId(target.viewName, Object.keys(objectViews), name) - : undefined; - const view = editedView ? editedView.view : viewId ? objectViews?.[viewId] : undefined; - const schema = { - type: 'object-view', - objectName: name, - ...(target.filter.length > 0 ? { table: { filter: target.filter } } : {}), - ...(viewId && view ? { listViews: { [viewId]: view }, defaultListView: viewId } : {}), - }; - // The renderer settles its named view once, at mount, so a different view is - // a different mount; a different slice of the same list is a refetch. - return ( - - - - - - ); +/** An object definition's merged `listViews` map, or `{}` when it has none. */ +export function listViewsOf(def: { listViews?: unknown } | undefined): Record { + const views = def?.listViews; + return views && typeof views === 'object' ? (views as Record) : {}; } /** - * objectui#12725 — the canvas half of selecting a kanban view's card: a click - * on a card of the board ({@link StudioCanvasCardSelectionContext}) selects - * the card and does not open the record. The board names each card's record - * on its element (`data-kanban-card`, `SortableCard`). Both the click and the - * pointer press are taken in the capture phase, before the card's own handlers - * see them: the click would open the record, and the press is where the - * board's drag sensor starts a move. A control drawn inside a card keeps its - * job. - * - * A focused card opens on Enter and on Space's release, as a click does - * (objectui#12888), so the keys are taken in the capture phase too: on the - * Studio canvas Enter, and Space's release, select the card, and Space's press - * is held so the board does not scroll. Only a key on the card element itself, - * the board's own guard: a key on something inside the card stays its own. + * Default Studio-canvas renderer for `object` leaves: the runtime records grid + * (`./studio-object-records-canvas.tsx`, whose header says what it draws). * - * Drawn always, with no box, for the reason {@link ColumnHeaderSelect} is. - */ -function KanbanCardSelect({ objectName, children }: { objectName: string; children: React.ReactNode }) { - const channel = React.useContext(StudioCanvasCardSelectionContext); - const cards = channel && channel.objectName === objectName ? channel : null; - const scope = React.useId(); - const cardOf = (e: React.SyntheticEvent): Element | null => { - if (!cards || !(e.target instanceof Element)) return null; - const card = e.target.closest('[data-kanban-card]'); - if (!card || !e.currentTarget.contains(card)) return null; - const control = e.target.closest('button, input, a, [role="checkbox"]'); - if (control && card.contains(control)) return null; - return card; - }; - const onPointerDownCapture = (e: React.PointerEvent) => { - if (cardOf(e)) e.stopPropagation(); - }; - const onKeyCapture = (e: React.KeyboardEvent) => { - if (!cards || !(e.target instanceof Element) || !e.target.matches('[data-kanban-card]')) return; - if (!e.currentTarget.contains(e.target)) return; - const selects = e.type === 'keydown' ? e.key === 'Enter' : e.key === ' '; - if (!selects && !(e.type === 'keydown' && e.key === ' ')) return; - e.stopPropagation(); - e.preventDefault(); - const id = e.target.getAttribute('data-kanban-card'); - if (selects && id) cards.onSelect(id); - }; - const onClickCapture = (e: React.MouseEvent) => { - const id = cardOf(e)?.getAttribute('data-kanban-card'); - if (!cards || !id) return; - e.stopPropagation(); - e.preventDefault(); - cards.onSelect(id); - }; - return ( -
- {cards?.selected ? ( - // The clicked card is outlined, as the StudioRailProps artboard draws - // a selected element. A style rule, for the reason the column's is: - // the board owns its cards and redraws them. - - ) : null} - {children} -
- ); -} - -/** - * objectui#12725 — the canvas half of selecting a column: a click on a header - * the panel lists ({@link StudioCanvasColumnSelectionContext}) selects that - * column and does not sort. The runtime grid names each header's column on - * the cell (`data-column-key`, the data table's `accessorKey`, which the - * object grid sets to the column's `field`); the click is taken in the - * capture phase, before the header's own sort handler sees it. + * Registered BY REFERENCE to its module (objectstack#33582). The package entry + * imports this module for its load-time registration (it is in the package's + * `sideEffects`), so the grid by value held its imports, the designer strings + * among them (`metadata-admin/i18n.ts` and the Studio `en` string namespace), + * in the console's EAGER closure on every route. The grid now loads the first + * time a Studio canvas draws an `object` leaf. * - * The wrapper is always drawn, and draws no box (`display: contents`), so the - * grid under it is not remounted when the channel arrives or goes. + * Exported so downstream renderers can compose/wrap it, and so a surface can + * tell the default from an override by identity: this value, not the module's + * own function, is the one registered. Override the default wholesale via + * `registerStudioCanvasPreview('object', …)`. */ -function ColumnHeaderSelect({ objectName, children }: { objectName: string; children: React.ReactNode }) { - const channel = React.useContext(StudioCanvasColumnSelectionContext); - const columns = channel && channel.objectName === objectName ? channel : null; - const scope = React.useId(); - const onClickCapture = (e: React.MouseEvent) => { - if (!columns || !(e.target instanceof Element)) return; - const header = e.target.closest('thead th[data-column-key]'); - if (!header || !e.currentTarget.contains(header)) return; - // A control drawn inside the header (the edit-field button) keeps its job. - const control = e.target.closest('button, input, a, [role="checkbox"]'); - if (control && header.contains(control)) return; - const field = header.getAttribute('data-column-key'); - if (!field || !columns.fields.includes(field)) return; - e.stopPropagation(); - e.preventDefault(); - columns.onSelect(field, header.textContent?.trim() || field); - }; - return ( -
- {columns?.selected ? ( - // The selected column's header is outlined, as the StudioRailProps - // artboard draws a selected element. A style rule, not a class on - // the cell: the grid owns its cells and redraws them. - - ) : null} - {children} -
- ); -} - -/** An object definition's merged `listViews` map, or `{}` when it has none. */ -export function listViewsOf(def: { listViews?: unknown } | undefined): Record { - const views = def?.listViews; - return views && typeof views === 'object' ? (views as Record) : {}; -} +export const StudioObjectRecordsCanvas: StudioCanvasPreview = lazyPage('studio canvas', () => + import('./studio-object-records-canvas.js').then((m) => m.StudioObjectRecordsCanvas), +); // Side-effect: register the built-in defaults. Kept inline (rather than a // separate `previews/` folder like metadata-admin) because there is exactly one diff --git a/ui/packages/app-shell/src/views/studio-design/studio-object-records-canvas.tsx b/ui/packages/app-shell/src/views/studio-design/studio-object-records-canvas.tsx new file mode 100644 index 00000000000..9d6101bb0ec --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/studio-object-records-canvas.tsx @@ -0,0 +1,243 @@ +// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The Studio canvas's built-in `object` renderer: the runtime records grid. + * + * Its own module so it loads on first draw (objectstack#33582): + * `./studio-canvas-preview.tsx` is imported by the package entry for its + * load-time registration, and registers this component through a lazy wrapper + * of the same name. ⛔ Import it statically only from code that is itself lazy + * (tests aside): a static import from the package's eager graph puts the grid, + * and the designer strings it reads, back on every console route. + */ + +import * as React from 'react'; +import { SchemaRenderer, useMetadata } from '@object-ui/react'; +import { resolveViewId } from '@object-ui/core'; +import { useAuth } from '@object-ui/auth'; +import { Database, Loader2 } from 'lucide-react'; +import { findByName } from '../../hooks/useNavTargetLabel.js'; +import { t } from '../metadata-admin/i18n.js'; +import { + listViewsOf, + navEntryListTarget, + StudioCanvasCardSelectionContext, + StudioCanvasColumnSelectionContext, + StudioCanvasDraftOnlyObjectsContext, + StudioCanvasListViewContext, + StudioCanvasNavEntryContext, + type StudioCanvasNavEntry, + type StudioCanvasPreviewProps, +} from './studio-canvas-preview.js'; + +/** + * Default Studio-canvas renderer for `object` leaves: the runtime records grid, + * exactly as the running app shows it (preview = runtime). Schema editing lives + * in the Data pillar, so this is the object-view grid — NOT the field-form + * designer that is the `object` entry in the MetadataPreviewRegistry. + * + * objectui#11774 — opened on a nav entry that slices the object (`filters`) or + * names one of its views (`viewName`), it shows that slice or that view, as the + * running app does (see {@link navEntryListTarget}). The named view is the + * object's own, from the merged `listViews` the shell's metadata holds — the + * map `ObjectView` and the rail's label resolver (`useNavTargetLabel`) read — + * handed to the renderer as the Studio's view preview hands one. With no entry + * (or a plain one) the schema is exactly the one this rendered before. + * + * objectui#11823 — while the Properties panel beside it holds a list view of + * this object ({@link StudioCanvasListViewContext}), that view is the one + * shown: the panel's buffer, so an edit shows here before it is published. + * The panel holds the view this canvas opens (the entry's named view, else the + * object's default list view, as the running app opens it). + * + * objectui#12508 — an object the Interfaces pillar names draft-only + * ({@link StudioCanvasDraftOnlyObjectsContext}) has no runtime yet: no schema + * and no records to read. The canvas says it is not published instead of + * mounting the grid, whose reads would answer 404. + * + * Exported so downstream renderers can compose/wrap it; override the default + * wholesale via `registerStudioCanvasPreview('object', …)`. + */ +export function StudioObjectRecordsCanvas(props: StudioCanvasPreviewProps) { + const { name, locale } = props; + // objectui#12508 — an object with only a draft has no runtime to preview, + // and while the pillar has not said, the grid waits rather than ask. + const draftOnly = React.useContext(StudioCanvasDraftOnlyObjectsContext); + if (draftOnly?.status === 'pending') { + return ( +
+ {t('engine.studio.loading', locale)} +
+ ); + } + if (draftOnly?.status === 'known' && draftOnly.names.has(name)) { + return ( +
+
+ +
+
+

{t('engine.studio.if.objectUnpublishedTitle', locale)}

+

{t('engine.studio.if.objectUnpublishedHint', locale)}

+
+
+ ); + } + return ; +} + +/** The runtime records grid {@link StudioObjectRecordsCanvas} renders for a published object. */ +function ObjectRecordsGrid({ name }: StudioCanvasPreviewProps) { + const entry = React.useContext(StudioCanvasNavEntryContext); + const edited = React.useContext(StudioCanvasListViewContext); + const editedView = edited && edited.objectName === name ? edited : null; + const { user, activeOrganization } = useAuth(); + const currentUserId = user?.id ?? null; + const currentOrgId = activeOrganization?.id ?? null; + // Keyed on the values, never on the context object's identity (AGENTS.md #10). + const navId = entry?.navId; + const filtersKey = JSON.stringify(entry?.filters ?? null); + const entryViewName = entry?.viewName; + const target = React.useMemo(() => { + const filters = (JSON.parse(filtersKey) as StudioCanvasNavEntry['filters'] | null) ?? undefined; + return navEntryListTarget(name, { navId, filters, viewName: entryViewName }, { currentUserId, currentOrgId }); + }, [name, navId, filtersKey, entryViewName, currentUserId, currentOrgId]); + // Read only for an entry that names a view: a plain entry asks the metadata + // cache for nothing, as before. The panel's view, when there is one, is + // shown instead of the cache's (objectui#11823). + const metadata = useMetadata(); + const objectViews = !editedView && target.viewName ? listViewsOf(findByName(metadata.objects, name)) : undefined; + const viewId = editedView + ? editedView.viewId + : objectViews && target.viewName + ? resolveViewId(target.viewName, Object.keys(objectViews), name) + : undefined; + const view = editedView ? editedView.view : viewId ? objectViews?.[viewId] : undefined; + const schema = { + type: 'object-view', + objectName: name, + ...(target.filter.length > 0 ? { table: { filter: target.filter } } : {}), + ...(viewId && view ? { listViews: { [viewId]: view }, defaultListView: viewId } : {}), + }; + // The renderer settles its named view once, at mount, so a different view is + // a different mount; a different slice of the same list is a refetch. + return ( + + + + + + ); +} + +/** + * objectui#12725 — the canvas half of selecting a kanban view's card: a click + * on a card of the board ({@link StudioCanvasCardSelectionContext}) selects + * the card and does not open the record. The board names each card's record + * on its element (`data-kanban-card`, `SortableCard`). Both the click and the + * pointer press are taken in the capture phase, before the card's own handlers + * see them: the click would open the record, and the press is where the + * board's drag sensor starts a move. A control drawn inside a card keeps its + * job. + * + * A focused card opens on Enter and on Space's release, as a click does + * (objectui#12888), so the keys are taken in the capture phase too: on the + * Studio canvas Enter, and Space's release, select the card, and Space's press + * is held so the board does not scroll. Only a key on the card element itself, + * the board's own guard: a key on something inside the card stays its own. + * + * Drawn always, with no box, for the reason {@link ColumnHeaderSelect} is. + */ +function KanbanCardSelect({ objectName, children }: { objectName: string; children: React.ReactNode }) { + const channel = React.useContext(StudioCanvasCardSelectionContext); + const cards = channel && channel.objectName === objectName ? channel : null; + const scope = React.useId(); + const cardOf = (e: React.SyntheticEvent): Element | null => { + if (!cards || !(e.target instanceof Element)) return null; + const card = e.target.closest('[data-kanban-card]'); + if (!card || !e.currentTarget.contains(card)) return null; + const control = e.target.closest('button, input, a, [role="checkbox"]'); + if (control && card.contains(control)) return null; + return card; + }; + const onPointerDownCapture = (e: React.PointerEvent) => { + if (cardOf(e)) e.stopPropagation(); + }; + const onKeyCapture = (e: React.KeyboardEvent) => { + if (!cards || !(e.target instanceof Element) || !e.target.matches('[data-kanban-card]')) return; + if (!e.currentTarget.contains(e.target)) return; + const selects = e.type === 'keydown' ? e.key === 'Enter' : e.key === ' '; + if (!selects && !(e.type === 'keydown' && e.key === ' ')) return; + e.stopPropagation(); + e.preventDefault(); + const id = e.target.getAttribute('data-kanban-card'); + if (selects && id) cards.onSelect(id); + }; + const onClickCapture = (e: React.MouseEvent) => { + const id = cardOf(e)?.getAttribute('data-kanban-card'); + if (!cards || !id) return; + e.stopPropagation(); + e.preventDefault(); + cards.onSelect(id); + }; + return ( +
+ {cards?.selected ? ( + // The clicked card is outlined, as the StudioRailProps artboard draws + // a selected element. A style rule, for the reason the column's is: + // the board owns its cards and redraws them. + + ) : null} + {children} +
+ ); +} + +/** + * objectui#12725 — the canvas half of selecting a column: a click on a header + * the panel lists ({@link StudioCanvasColumnSelectionContext}) selects that + * column and does not sort. The runtime grid names each header's column on + * the cell (`data-column-key`, the data table's `accessorKey`, which the + * object grid sets to the column's `field`); the click is taken in the + * capture phase, before the header's own sort handler sees it. + * + * The wrapper is always drawn, and draws no box (`display: contents`), so the + * grid under it is not remounted when the channel arrives or goes. + */ +function ColumnHeaderSelect({ objectName, children }: { objectName: string; children: React.ReactNode }) { + const channel = React.useContext(StudioCanvasColumnSelectionContext); + const columns = channel && channel.objectName === objectName ? channel : null; + const scope = React.useId(); + const onClickCapture = (e: React.MouseEvent) => { + if (!columns || !(e.target instanceof Element)) return; + const header = e.target.closest('thead th[data-column-key]'); + if (!header || !e.currentTarget.contains(header)) return; + // A control drawn inside the header (the edit-field button) keeps its job. + const control = e.target.closest('button, input, a, [role="checkbox"]'); + if (control && header.contains(control)) return; + const field = header.getAttribute('data-column-key'); + if (!field || !columns.fields.includes(field)) return; + e.stopPropagation(); + e.preventDefault(); + columns.onSelect(field, header.textContent?.trim() || field); + }; + return ( +
+ {columns?.selected ? ( + // The selected column's header is outlined, as the StudioRailProps + // artboard draws a selected element. A style rule, not a class on + // the cell: the grid owns its cells and redraws them. + + ) : null} + {children} +
+ ); +} From 237660a4f9d035297d8fa4152cd26c0ec9ab0ba7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 05:01:45 +0000 Subject: [PATCH 2/4] chore(changeset): console first load drops the Studio and metadata form strings Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5ousB2MKFUbJFc3Hwp --- .../33582-console-eager-closure-studio-strings.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .changeset/33582-console-eager-closure-studio-strings.md diff --git a/.changeset/33582-console-eager-closure-studio-strings.md b/.changeset/33582-console-eager-closure-studio-strings.md new file mode 100644 index 00000000000..e0ac3e22591 --- /dev/null +++ b/.changeset/33582-console-eager-closure-studio-strings.md @@ -0,0 +1,10 @@ +--- +'@object-ui/console': patch +--- + +perf(console): the first load no longer downloads the Studio designer strings and the metadata form strings + +Clause-②: no +Metadata-protocol: none + +Every Console route, a dashboard included, used to download the Studio designer's English strings (64 KB gzipped) and the metadata form strings before the app asked for any data, though only Studio and Setup screens draw them. They were held there by five components the Console registers or mounts at load: the Studio canvas's default object grid, the Setup datasources page, the position list's holder and permission-set cells, a list's "Create view" dialog and the preview bar's "Pending changes" sheet. Each now loads the first time it is drawn, and the Studio strings' loader gets its own chunk. English stays the strings' synchronous fallback once a Studio or Setup screen has loaded. The Console's eager closure (`dist/eager-closure.json`) goes from 2,165,707 to 2,058,468 bytes gzipped (−107,239), measured on two builds of the same tree. What each screen draws is unchanged; the datasources page shows a one-line loading notice while its code arrives. From 5c76b35ee024c0d5532fa9591f20b3725494cd35 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 05:37:28 +0000 Subject: [PATCH 3/4] test(app-shell): pin the lazily registered Studio canvas default Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5ousB2MKFUbJFc3Hwp --- .../openPathObjectReaders-12811.test.ts | 2 +- .../studio-canvas-preview.test.tsx | 62 +++++++++++++++++-- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/ui/packages/app-shell/src/console/__tests__/openPathObjectReaders-12811.test.ts b/ui/packages/app-shell/src/console/__tests__/openPathObjectReaders-12811.test.ts index 102b1b0d67d..577dcdc2635 100644 --- a/ui/packages/app-shell/src/console/__tests__/openPathObjectReaders-12811.test.ts +++ b/ui/packages/app-shell/src/console/__tests__/openPathObjectReaders-12811.test.ts @@ -126,7 +126,7 @@ const OBJECTS_READERS: Record = { kind: 'off', why: "Studio: the object's view labels New view refuses to reuse, the read the list-view panel made before the switcher moved into the header (objectstack#30046)", }, - 'packages/app-shell/src/views/studio-design/studio-canvas-preview.tsx': { kind: 'off', why: 'Studio' }, + 'packages/app-shell/src/views/studio-design/studio-object-records-canvas.tsx': { kind: 'off', why: 'Studio' }, 'packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx': { kind: 'off', why: "Studio: the Data pillar's Form tab asks selectRecordFormView which form view the app opens, over the served objects (objectstack#30057)", diff --git a/ui/packages/app-shell/src/views/studio-design/studio-canvas-preview.test.tsx b/ui/packages/app-shell/src/views/studio-design/studio-canvas-preview.test.tsx index 61857da52d5..854731f2a69 100644 --- a/ui/packages/app-shell/src/views/studio-design/studio-canvas-preview.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/studio-canvas-preview.test.tsx @@ -30,6 +30,10 @@ import { StudioObjectRecordsCanvas, } from './studio-canvas-preview'; import type { StudioCanvasListView } from './studio-canvas-preview'; +// The grid's own module: the registry above holds it behind a lazy wrapper of +// the same name (objectstack#33582), so the grid's behaviour is pinned on the +// module's component, and the wrapper by the lazy-registration block below. +import { StudioObjectRecordsCanvas as ObjectRecordsCanvas } from './studio-object-records-canvas'; describe('studio-canvas-preview registry', () => { it('ships a built-in default for `object` (the records grid)', () => { @@ -104,7 +108,7 @@ describe('navEntryListTarget — the runtime reading of an object entry (objectu }); }); -describe('StudioObjectRecordsCanvas — renders the entry it is open on (objectui#11774)', () => { +describe('the default object canvas — renders the entry it is open on (objectui#11774)', () => { /** Stands in for `plugin-view`'s `object-view`, recording the schema it is handed. */ function ObjectViewRecorder({ schema }: { schema: Record }) { return
{JSON.stringify(schema)}
; @@ -134,7 +138,7 @@ describe('StudioObjectRecordsCanvas — renders the entry it is open on (objectu render( - + , ); @@ -177,7 +181,7 @@ describe('StudioObjectRecordsCanvas — renders the entry it is open on (objectu * it is editing: the panel's buffer, handed over through * `StudioCanvasListViewContext` (beside the published props, like the entry). */ -describe('StudioObjectRecordsCanvas — shows the list view its panel edits (objectui#11823)', () => { +describe('the default object canvas — shows the list view its panel edits (objectui#11823)', () => { function ObjectViewRecorder({ schema }: { schema: Record }) { return
{JSON.stringify(schema)}
; } @@ -212,7 +216,7 @@ describe('StudioObjectRecordsCanvas — shows the list view its panel edits (obj - + , @@ -254,3 +258,53 @@ describe('StudioObjectRecordsCanvas — shows the list view its panel edits (obj }); }); }); + +/** + * objectstack#33582 — the registered `object` default is a lazy wrapper of the + * grid's module, not the module's component: the registry module is imported + * by the package entry at load, so a by-value default held the grid and the + * designer strings in the console's eager closure. Drawn through the registry, + * as `StudioDesignSurface` draws it, the wrapper shows its loading line, then + * the grid with the schema the module's own component renders. + */ +describe('the registered object default loads the grid on first draw (objectstack#33582)', () => { + function ObjectViewRecorder({ schema }: { schema: Record }) { + return
{JSON.stringify(schema)}
; + } + const METADATA: MetadataContextValue = { + apps: [], + objects: [{ name: 'showcase_task', label: 'Task' }], + dashboards: [], + reports: [], + pages: [], + loading: false, + error: null, + refresh: async () => {}, + invalidate: () => {}, + ensureType: async () => [], + getItem: async () => null, + getItemsByType: () => [], + }; + + beforeAll(() => { + ComponentRegistry.register('object-view', ObjectViewRecorder as never, { namespace: 'plugin-view' }); + }); + afterEach(cleanup); + + it('the default is the wrapper, not the grid module\'s own component', () => { + expect(getStudioCanvasPreview('object')).toBe(StudioObjectRecordsCanvas); + expect(StudioObjectRecordsCanvas).not.toBe(ObjectRecordsCanvas); + }); + + it('drawn through the registry, it loads and draws the grid', async () => { + const Canvas = getStudioCanvasPreview('object')!; + render( + + + , + ); + const grid = await screen.findByTestId('object-view-schema'); + expect(JSON.parse(grid.textContent ?? 'null')).toEqual({ type: 'object-view', objectName: 'showcase_task' }); + expect(screen.queryByText('Loading studio canvas…')).toBeNull(); + }); +}); From 58e603fe30c57b20e447875101c51423da49e4ba Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 05:46:28 +0000 Subject: [PATCH 4/4] fix(app-shell): the lazy datasource page keeps the registry's list-page prop type Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5ousB2MKFUbJFc3Hwp --- .../app-shell/src/views/metadata-admin/datasource/register.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/packages/app-shell/src/views/metadata-admin/datasource/register.ts b/ui/packages/app-shell/src/views/metadata-admin/datasource/register.ts index 9ff01db91a1..36ce7834e9e 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/datasource/register.ts +++ b/ui/packages/app-shell/src/views/metadata-admin/datasource/register.ts @@ -25,7 +25,7 @@ import { lazyPage } from '../../../services/lazyPage.js'; * Studio `en` string namespace, and the JSON-schema field reader in the * console's eager closure, on every route. */ -const DatasourceResourcePage = lazyPage('datasources', () => +const DatasourceResourcePage = lazyPage<{ type: string }>('datasources', () => import('./DatasourceResourcePage.js').then((m) => m.DatasourceResourcePage), );