From a3a30d47033b93b97e7c7c908c8b03a7b1ce664e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 08:50:33 +0000 Subject: [PATCH 1/6] fix(app-shell): home asks the objects it names by name and mounts its palette on first open Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jSvXnowXjLpyfdKoux --- .../app-shell/src/console/home/HomeLayout.tsx | 76 +++++++++++++++++-- .../app-shell/src/console/home/HomePage.tsx | 23 +++++- .../app-shell/src/hooks/useNavMemberGates.ts | 25 +++--- .../app-shell/src/hooks/useNavTargetLabel.ts | 20 ++++- .../app-shell/src/hooks/useObjectPresence.ts | 51 +++++++++++-- .../src/layout/ActivityObjectLabel.tsx | 16 ++-- 6 files changed, 178 insertions(+), 33 deletions(-) diff --git a/ui/packages/app-shell/src/console/home/HomeLayout.tsx b/ui/packages/app-shell/src/console/home/HomeLayout.tsx index 3c56c454e8c..59f635a0ad8 100644 --- a/ui/packages/app-shell/src/console/home/HomeLayout.tsx +++ b/ui/packages/app-shell/src/console/home/HomeLayout.tsx @@ -29,13 +29,24 @@ * `current_user.positions` answers here as it does in the sidebar. `features` * is not bound: Home reads no deployment config, as the scope it replaces did. * + * The palette is mounted from the first time it opens, never while Home is + * merely shown (objectstack#29121). Mounted closed, it read the whole object + * registry (`useMetadata().objects`, the largest metadata payload of the page) + * and its host app's package scope for its gates, on every visit, for a dialog + * nobody had opened. Opened, it is handed the host app's object scope over the + * objects its navigation lists, read without views: those are the objects its + * record search reads (`useRecordSearch` searches the navigation's objects and + * names their groups from these definitions), which is what the palette is + * handed inside an app as well. Once mounted it stays, so it closes as it + * always has. + * * @module */ -import React, { useCallback, useEffect, useMemo } from 'react'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { useLocation, useNavigate } from 'react-router-dom'; import { useNavigationContext } from '../../context/NavigationContext.js'; -import { CommandPaletteProvider } from '../../context/CommandPaletteProvider.js'; +import { CommandPaletteProvider, useCommandPalette } from '../../context/CommandPaletteProvider.js'; import { CommandPalette } from '../../chrome/CommandPalette.js'; import { AppHeader } from '../../layout/AppHeader.js'; import { CONSOLE_TOP_BAR } from '../../layout/consoleTopBar.js'; @@ -44,6 +55,8 @@ import { useAdapter } from '../../providers/AdapterProvider.js'; import { filterActiveApps, matchAppBySegment, resolveHostAppSegment } from '../../utils/index.js'; import { useAiSurfaceEnabled } from '../../hooks/useAiSurface.js'; import { ExpressionProvider } from '../../providers/ExpressionProvider.js'; +import { navigationNames } from '../appObjectScope.js'; +import type { ReadNamesWithoutViews } from '../../hooks/useObjectPresence.js'; import { buildExpressionUser } from '../../providers/expressionUser.js'; import { useAuth } from '@object-ui/auth'; import { useObjectTranslation } from '@object-ui/i18n'; @@ -59,6 +72,58 @@ import { rememberDockReturnLocation } from '../../layout/chatDockState.js'; */ const NO_SCOPE_INPUT: Record = {}; +const NO_OBJECTS: any[] = []; + +/** + * The objects the palette searches, while it is open: the host app's object + * scope over the objects its navigation lists, without views + * (objectstack#29121) — its package's list plus, by name, a listed object the + * package does not hold; by name alone for an app bound to no package. Once + * the whole registry is loaded, or on its way, it is that list, and nothing + * more is asked. A provider without scope reads answers its `objects`. + */ +function useHostAppPaletteObjects(hostApp: Record): any[] { + const metadata = useMetadata(); + const names = navigationNames(hostApp.navigation, (item) => (item.type === 'object' ? item.objectName : undefined)); + const packageId = typeof hostApp._packageId === 'string' && hostApp._packageId ? hostApp._packageId : undefined; + const { readObjectScope, getTypeStatus } = metadata; + if (readObjectScope && getTypeStatus?.('object') === 'idle') { + const read = readObjectScope as ReadNamesWithoutViews; + if (packageId) return read({ packageId, names, views: false }).objects; + return names.length > 0 ? read({ names, views: false }).objects : NO_OBJECTS; + } + return metadata.objects ?? NO_OBJECTS; +} + +interface HomeCommandPaletteProps { + apps: any[]; + hostApp: Record; + onAppChange: (segment: string) => void; + dataSource?: any; +} + +/** The palette once opened, with the objects it searches. */ +function OpenedHomeCommandPalette({ apps, hostApp, onAppChange, dataSource }: HomeCommandPaletteProps) { + const objects = useHostAppPaletteObjects(hostApp); + return ( + + ); +} + +/** Home's palette: mounted from its first open (see the module doc). */ +function HomeCommandPalette(props: HomeCommandPaletteProps) { + const { open } = useCommandPalette(); + const [opened, setOpened] = useState(open); + if (open && !opened) setOpened(true); + return opened || open ? : null; +} + interface HomeLayoutProps { children: React.ReactNode; /** @@ -73,7 +138,7 @@ export function HomeLayout({ children }: HomeLayoutProps) { const { user } = useAuth(); // The shared `current_user` normaliser, keyed on the session user (objectui#6515). const expressionUser = useMemo(() => buildExpressionUser(user), [user]); - const { apps, objects } = useMetadata(); + const { apps } = useMetadata(); const dataSource = useAdapter(); const { t } = useObjectTranslation(); const navigate = useNavigate(); @@ -116,10 +181,9 @@ export function HomeLayout({ children }: HomeLayoutProps) { {hostApp ? ( {header} - navigate(`/apps/${segment}`)} dataSource={dataSource} /> diff --git a/ui/packages/app-shell/src/console/home/HomePage.tsx b/ui/packages/app-shell/src/console/home/HomePage.tsx index 07e099a3c06..130ee980a31 100644 --- a/ui/packages/app-shell/src/console/home/HomePage.tsx +++ b/ui/packages/app-shell/src/console/home/HomePage.tsx @@ -21,6 +21,7 @@ import { useMetadata } from '../../providers/MetadataProvider.js'; import { useRecentItems, type RecentItem } from '../../hooks/useRecentItems.js'; import { useRecentItemLabel } from '../../hooks/useRecentItemLabel.js'; import { useNavTargetLabel } from '../../hooks/useNavTargetLabel.js'; +import { readObjectsByName } from '../../hooks/useObjectPresence.js'; import { useFavorites } from '../../hooks/useFavorites.js'; import { useObjectTranslation } from '@object-ui/i18n'; // Its own line: the line above is the pack-hook binding `perm-home-namespace-3546.test.tsx` reads. @@ -346,15 +347,31 @@ function usePendingDraftsRow(t: (key: string, opts?: any) => string, language: s export function HomePage() { const navigate = useNavigate(); const { t, language } = useObjectTranslation(); - const { apps, objects, loading } = useMetadata(); + const metadata = useMetadata(); + const { apps, loading } = metadata; const { recentItems } = useRecentItems(); // A recent entry stores identity; the rail labels it with this, on the // render, in the current language (objectui#11678). const recentLabel = useRecentItemLabel(); + // objectstack#29121 — the objects the recent record rows name, read by name + // (`readObjectsByName`): their icons and labels are all Home needs of the + // object registry, so it never loads the whole list for them. + const recentObjectNames = useMemo( + () => [ + ...new Set( + recentItems + .filter((item) => item.type === 'record') + .map((item) => recentItemObject(item)) + .filter((name): name is string => typeof name === 'string' && name !== ''), + ), + ], + [recentItems], + ); + const recentObjects = readObjectsByName(metadata, recentObjectNames); // A record row's trail names its object as the sidebar names an unlabelled // navigation entry for it, and the app as its launcher tile does // (objectui#12604). - const targetLabel = useNavTargetLabel(); + const targetLabel = useNavTargetLabel({ objects: recentObjects }); const { appLabel } = useObjectLabel(); const { favorites } = useFavorites(); const { user } = useAuth(); @@ -491,7 +508,7 @@ export function HomePage() { const app = segment ? matchAppBySegment(activeApps, segment) : undefined; const objectIcon = item.type === 'record' && objectName - ? (objects ?? []).find((o: { name?: unknown }) => o?.name === objectName)?.icon + ? (recentObjects as Array<{ name?: unknown; icon?: unknown } | null | undefined>).find((o) => o?.name === objectName)?.icon : undefined; return { context: diff --git a/ui/packages/app-shell/src/hooks/useNavMemberGates.ts b/ui/packages/app-shell/src/hooks/useNavMemberGates.ts index 6b9e663337b..b741121ef74 100644 --- a/ui/packages/app-shell/src/hooks/useNavMemberGates.ts +++ b/ui/packages/app-shell/src/hooks/useNavMemberGates.ts @@ -98,6 +98,7 @@ import { import { withoutUnreadableObjectEntries, type ObjectReadCheck } from '../utils/navObjectReadGate.js'; import { filterActiveApps } from '../utils/appRoute.js'; import { navigationNames } from '../console/appObjectScope.js'; +import type { ReadNamesWithoutViews } from './useObjectPresence.js'; const NO_MISSING: readonly string[] = []; @@ -354,9 +355,8 @@ export function useNavMemberGates(forApp?: Record): NavMemberGa // as registered, as every object did while the whole list loaded. The gate // asks for nothing itself: `AppContent` names the objects the app's own // entries require, so the sidebar's answer is exact, while the bell's - // cross-app roster does not ask another app's objects one by one. Outside an - // app (the home page's feeds) there is no package, and the gate reads the - // whole registry, as it does once anything has loaded it. + // cross-app roster does not ask another app's objects one by one. Once + // anything has loaded the whole registry, the gate reads it. // // objectui#12980 — inside an app whose served item names NO package (an app // created in the console), on the same condition, the gate reads the @@ -367,19 +367,26 @@ export function useNavMemberGates(forApp?: Record): NavMemberGa // it. A name not answered yet, or whose read failed (objectui#13009: left // unanswered), shows, as every entry does while the whole list loads or // after it fails. + // + // objectstack#29121 — outside an app (the home page's feeds, whose roster + // gates every app's navigation) the gate reads the same names-only scope over + // the app list's `requiresObject` union, with `views: false`: it reads which + // objects there are, never their views. It read the whole registry there, + // which the home page then loaded on every visit for these few names. const metadata = useMetadata(); const packageId = typeof app?._packageId === 'string' && app._packageId ? app._packageId : undefined; - const packageless = !packageId && typeof app?.name === 'string' && app.name !== ''; - const readObjectScope = - (packageId || packageless) && metadata.getTypeStatus?.('object') === 'idle' ? metadata.readObjectScope : undefined; + const inApp = typeof app?.name === 'string' && app.name !== ''; + const readObjectScope = metadata.getTypeStatus?.('object') === 'idle' ? metadata.readObjectScope : undefined; const unionNames = readObjectScope && !packageId ? requiredObjectUnion(metadata.apps, app) : NO_MISSING; const scope: { objects: readonly unknown[]; missing: readonly string[] } | null = !readObjectScope ? null : packageId ? readObjectScope({ packageId }) - : unionNames.length > 0 - ? readObjectScope({ names: unionNames }) - : NO_REQUIRED_OBJECTS; + : unionNames.length === 0 + ? NO_REQUIRED_OBJECTS + : inApp + ? readObjectScope({ names: unionNames }) + : (readObjectScope as ReadNamesWithoutViews)({ names: unionNames, views: false }); const metadataObjects = scope ? scope.objects : metadata.objects; const missingObjects = scope ? scope.missing : NO_MISSING; const registeredObjectNames = useMemo( diff --git a/ui/packages/app-shell/src/hooks/useNavTargetLabel.ts b/ui/packages/app-shell/src/hooks/useNavTargetLabel.ts index ba0f564f24d..3ca681d6fcc 100644 --- a/ui/packages/app-shell/src/hooks/useNavTargetLabel.ts +++ b/ui/packages/app-shell/src/hooks/useNavTargetLabel.ts @@ -138,8 +138,22 @@ function listViewsOf(def: LabelledRecord | undefined): Record) : {}; } -export function useNavTargetLabel(): NavTargetLabelResolver { +/** + * Where an object target's definition is read from, when not the whole + * `objects` list (objectstack#29121). Home names the objects of its recent + * record rows from definitions it read by name (`readObjectsByName`): handed + * here, an `object` target is looked up in them, and the whole list is never + * read for its label. A `view` target still reads `objects`: a definition read + * by name carries no composed views. Omitted, the resolver reads `objects`, as + * the sidebar and every other caller does. + */ +export interface NavTargetLabelSources { + objects?: readonly unknown[]; +} + +export function useNavTargetLabel(sources?: NavTargetLabelSources): NavTargetLabelResolver { const metadata = useMetadata(); + const objectsSource = sources?.objects; const bundledReads = useBundledReads(); const { objectLabel, viewLabel, dashboardLabel } = useObjectLabel(); const { language, t } = useObjectTranslation(); @@ -149,7 +163,7 @@ export function useNavTargetLabel(): NavTargetLabelResolver { () => (target: NavLabelTarget) => { switch (target.kind) { case 'object': { - const def = findByName(metadata.objects, target.objectName); + const def = findByName(objectsSource ?? metadata.objects, target.objectName); const text = metadataText(def?.label, language) ?? draftText(drafts, 'object', target.objectName, language); return nonEmpty(objectLabel({ name: target.objectName, label: text ?? '' })); @@ -174,6 +188,6 @@ export function useNavTargetLabel(): NavTargetLabelResolver { return undefined; } }, - [metadata, bundledReads, objectLabel, viewLabel, dashboardLabel, language, t, drafts], + [metadata, objectsSource, bundledReads, objectLabel, viewLabel, dashboardLabel, language, t, drafts], ); } diff --git a/ui/packages/app-shell/src/hooks/useObjectPresence.ts b/ui/packages/app-shell/src/hooks/useObjectPresence.ts index 62c7a746183..82dd8962837 100644 --- a/ui/packages/app-shell/src/hooks/useObjectPresence.ts +++ b/ui/packages/app-shell/src/hooks/useObjectPresence.ts @@ -53,9 +53,44 @@ * type is still `idle` (`MetadataProvider`'s `readType`). No consumer of this * hook adds a request; the point is to remove one. */ -import { useMetadata, type MetadataTypeStatus } from '@object-ui/react'; +import { useMetadata, type MetadataContextValue, type MetadataTypeStatus } from '@object-ui/react'; import { useExpressionContext } from '../providers/ExpressionProvider.js'; +type ReadObjectScope = NonNullable; + +/** + * `readObjectScope` with the provider's package-local `views: false` hand-off + * (`MetadataProvider`): a reader that asks which objects there are, or what one + * is called, composes no views, so it never reads the `/meta/view` list. + */ +export type ReadNamesWithoutViews = (scope: Parameters[0] & { views: false }) => ReturnType; + +const NO_OBJECTS: readonly unknown[] = Object.freeze([]); + +/** + * The definitions of `names`, without the whole object registry + * (objectstack#29121): while nothing has asked for the whole list, each name is + * asked by name through the names-only scope (objectui#12980), and the answer + * is the names that have landed so far; once the whole list is loaded, or on + * its way, it is that list, and nothing more is asked. A provider without + * scope reads (a hand-rolled context) answers with its `objects`, as before. + * + * Asking for no name asks for nothing: a names-only scope with no names would + * be the whole registry. + */ +export function readObjectsByName( + metadata: Pick, + names: readonly string[], +): readonly unknown[] { + const { readObjectScope, getTypeStatus } = metadata; + if (readObjectScope && getTypeStatus?.('object') === 'idle') { + const asked = names.filter((name) => typeof name === 'string' && name !== ''); + if (asked.length === 0) return NO_OBJECTS; + return (readObjectScope as ReadNamesWithoutViews)({ names: asked, views: false }).objects; + } + return metadata.objects ?? NO_OBJECTS; +} + /** What the metadata registry can say about one object name. */ export type ObjectPresence = 'present' | 'absent' | 'unknown'; @@ -102,18 +137,20 @@ export function useObjectPresence(name: string): ObjectPresenceReading { // objectui#12980 — inside an app whose served item names NO package (an app // created in the console is stored bound to none), on the same condition, // the object is asked for by name through the names-only scope: the one - // name this hook is asked about is the whole set it needs. Outside an app - // (no app name: the home page) it reads the whole registry, as before. + // name this hook is asked about is the whole set it needs. + // + // objectstack#29121 — outside an app (no app name: the home page, whose + // activity feeds ask about `sys_activity`) it is asked by name the same way. + // It used to read the whole registry there, which the home page then loaded + // on every visit for this one question. const { app } = useExpressionContext(); const packageId = typeof app?._packageId === 'string' && app._packageId ? app._packageId : undefined; - const inApp = typeof app?.name === 'string' && app.name !== ''; // // objectstack#28645 — it asks with `views: false` (the provider's hand-off, // `MetadataProvider`): whether an object is there reads no views, so this // question never reads the `/meta/view` list. - if ((packageId || inApp) && readObjectScope && getTypeStatus?.('object') === 'idle') { - type ReadScope = NonNullable; - const readNames = readObjectScope as (scope: Parameters[0] & { views: false }) => ReturnType; + if (readObjectScope && getTypeStatus?.('object') === 'idle') { + const readNames = readObjectScope as ReadNamesWithoutViews; const scope = readNames(packageId ? { packageId, names: [name], views: false } : { names: [name], views: false }); const presence: ObjectPresence = !scope.settled ? 'unknown' diff --git a/ui/packages/app-shell/src/layout/ActivityObjectLabel.tsx b/ui/packages/app-shell/src/layout/ActivityObjectLabel.tsx index 7cd7e1d4d21..32bfe312dfe 100644 --- a/ui/packages/app-shell/src/layout/ActivityObjectLabel.tsx +++ b/ui/packages/app-shell/src/layout/ActivityObjectLabel.tsx @@ -13,6 +13,7 @@ import { useObjectLabel, useObjectTranslation } from '@object-ui/i18n'; import { findByName, metadataText } from '../hooks/useNavTargetLabel.js'; import { useMetadata } from '../providers/MetadataProvider.js'; +import { readObjectsByName } from '../hooks/useObjectPresence.js'; /** `''` from a bundle lookup that found nothing and had no metadata to fall back to. */ function nonEmpty(text: string | undefined): string | undefined { @@ -29,8 +30,13 @@ function nonEmpty(text: string | undefined): string | undefined { * the server wrote it. The label is read the way `useNavTargetLabel` reads an * object's: the definition's `label` from `useMetadata().objects` (an inline * locale map read in the active language), passed through `useObjectLabel`'s - * bundle lookup (`{ns}.objects..label`). `objects` is the shell's cached - * `object` list, loaded once for the whole type, never once per row. + * bundle lookup (`{ns}.objects..label`). + * + * objectstack#29121 — the definition is read by name (`readObjectsByName`) + * while nothing has loaded the whole `object` list, so a few rows on Home ask + * for their few objects, never the registry; once the list is loaded (inside + * an app, say) the row reads it and asks nothing. The row's name is asked + * once, whichever rows name it: the names-only scope keeps every answer. * * The API name is the fallback, and only that: an object the list does not * hold (not loaded yet, or since removed) and no bundle names is shown by its @@ -38,15 +44,15 @@ function nonEmpty(text: string | undefined): string | undefined { * * A component of its own so that the list is read only while a row is on * screen. The rows are built on every render of the bell, open or closed, and - * reading `objects` is what loads the type. + * reading a definition is what asks for it. * * Home's activity card renders the same component for the same row * (objectui#12238), so the bell and Home name an object one way. */ export function ActivityObjectLabel({ objectName }: { objectName: string }) { - const { objects } = useMetadata(); + const metadata = useMetadata(); const { objectLabel } = useObjectLabel(); const { language } = useObjectTranslation(); - const text = metadataText(findByName(objects, objectName)?.label, language); + const text = metadataText(findByName(readObjectsByName(metadata, [objectName]), objectName)?.label, language); return <>{nonEmpty(objectLabel({ name: objectName, label: text ?? '' })) ?? objectName}; } From 51fe51e25f4f2f268aee2054f17f5197361abbc6 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 09:01:29 +0000 Subject: [PATCH 2/6] fix(app-shell): home's recent rows read their objects by name; request-count tests for each home reader Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jSvXnowXjLpyfdKoux --- .../app-shell/src/console/home/HomePage.tsx | 29 +- .../HomeLayout.paletteReads-29121.test.tsx | 182 +++++++++++++ ...meLayout.searchOpensPalette-12601.test.tsx | 15 +- .../HomePage.recentObjectReads-29121.test.tsx | 248 ++++++++++++++++++ .../__tests__/homeObjectReads-29121.test.tsx | 182 +++++++++++++ .../app-shell/src/hooks/useNavMemberGates.ts | 7 +- .../app-shell/src/hooks/useNavTargetLabel.ts | 31 ++- .../app-shell/src/hooks/useObjectPresence.ts | 7 + .../app-shell/src/hooks/useRecentItemLabel.ts | 11 +- 9 files changed, 668 insertions(+), 44 deletions(-) create mode 100644 ui/packages/app-shell/src/console/home/__tests__/HomeLayout.paletteReads-29121.test.tsx create mode 100644 ui/packages/app-shell/src/console/home/__tests__/HomePage.recentObjectReads-29121.test.tsx create mode 100644 ui/packages/app-shell/src/console/home/__tests__/homeObjectReads-29121.test.tsx diff --git a/ui/packages/app-shell/src/console/home/HomePage.tsx b/ui/packages/app-shell/src/console/home/HomePage.tsx index 130ee980a31..e733fbcfb6c 100644 --- a/ui/packages/app-shell/src/console/home/HomePage.tsx +++ b/ui/packages/app-shell/src/console/home/HomePage.tsx @@ -20,7 +20,7 @@ import { useNavigate } from 'react-router-dom'; import { useMetadata } from '../../providers/MetadataProvider.js'; import { useRecentItems, type RecentItem } from '../../hooks/useRecentItems.js'; import { useRecentItemLabel } from '../../hooks/useRecentItemLabel.js'; -import { useNavTargetLabel } from '../../hooks/useNavTargetLabel.js'; +import { useNavTargetLabel, type NavTargetLabelOptions } from '../../hooks/useNavTargetLabel.js'; import { readObjectsByName } from '../../hooks/useObjectPresence.js'; import { useFavorites } from '../../hooks/useFavorites.js'; import { useObjectTranslation } from '@object-ui/i18n'; @@ -344,6 +344,9 @@ function usePendingDraftsRow(t: (key: string, opts?: any) => string, language: s ); } +/** Home's labels read each object they name by name (objectstack#29121). */ +const BY_NAME: NavTargetLabelOptions = { byName: true }; + export function HomePage() { const navigate = useNavigate(); const { t, language } = useObjectTranslation(); @@ -353,25 +356,13 @@ export function HomePage() { // A recent entry stores identity; the rail labels it with this, on the // render, in the current language (objectui#11678). const recentLabel = useRecentItemLabel(); - // objectstack#29121 — the objects the recent record rows name, read by name - // (`readObjectsByName`): their icons and labels are all Home needs of the - // object registry, so it never loads the whole list for them. - const recentObjectNames = useMemo( - () => [ - ...new Set( - recentItems - .filter((item) => item.type === 'record') - .map((item) => recentItemObject(item)) - .filter((name): name is string => typeof name === 'string' && name !== ''), - ), - ], - [recentItems], - ); - const recentObjects = readObjectsByName(metadata, recentObjectNames); // A record row's trail names its object as the sidebar names an unlabelled // navigation entry for it, and the app as its launcher tile does // (objectui#12604). - const targetLabel = useNavTargetLabel({ objects: recentObjects }); + // + // objectstack#29121 — by name: the object a row names is read alone (as its + // icon below is), so Home never loads the whole registry for its rows. + const targetLabel = useNavTargetLabel(BY_NAME); const { appLabel } = useObjectLabel(); const { favorites } = useFavorites(); const { user } = useAuth(); @@ -508,7 +499,9 @@ export function HomePage() { const app = segment ? matchAppBySegment(activeApps, segment) : undefined; const objectIcon = item.type === 'record' && objectName - ? (recentObjects as Array<{ name?: unknown; icon?: unknown } | null | undefined>).find((o) => o?.name === objectName)?.icon + ? (readObjectsByName(metadata, [objectName]) as Array<{ name?: unknown; icon?: unknown } | null | undefined>).find( + (o) => o?.name === objectName, + )?.icon : undefined; return { context: diff --git a/ui/packages/app-shell/src/console/home/__tests__/HomeLayout.paletteReads-29121.test.tsx b/ui/packages/app-shell/src/console/home/__tests__/HomeLayout.paletteReads-29121.test.tsx new file mode 100644 index 00000000000..5aaccb602e0 --- /dev/null +++ b/ui/packages/app-shell/src/console/home/__tests__/HomeLayout.paletteReads-29121.test.tsx @@ -0,0 +1,182 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#29121 — Home's command palette reads no object until it opens. + * + * `HomeLayout` mounted the palette closed and handed it `useMetadata().objects`, + * so every visit to `/home` read the whole object registry (and the view list) + * for a dialog nobody had opened. Now the palette is mounted from its first + * open, and handed the host app's object scope over the objects its navigation + * lists, read without views: what its record search reads. + * + * Real subjects: `HomeLayout`, `CommandPaletteProvider`, `MetadataProvider` + * over a fake adapter that records each read, and a `MemoryRouter`. The bar is + * a stub with an open button, and the palette a probe that records the objects + * it was handed (what the palette lists is its own files' pins). + */ + +import '@testing-library/jest-dom/vitest'; +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import React from 'react'; +import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; +import { MetadataProvider } from '../../../providers/MetadataProvider'; + +vi.mock('@object-ui/i18n', async (importOriginal) => ({ + ...(await importOriginal>()), + useObjectTranslation: () => ({ language: 'en', t: (key: string, o?: { defaultValue?: string }) => o?.defaultValue ?? key }), +})); +vi.mock('@object-ui/auth', async (importOriginal) => ({ + ...(await importOriginal>()), + useAuth: () => ({ user: { id: 'u1', name: 'Dev Admin', email: 'dev.admin@example.com' } }), +})); +vi.mock('../../../hooks/useAiSurface', () => ({ + useAiSurfaceEnabled: () => ({ enabled: false, isLoading: false }), +})); +vi.mock('../../../providers/AdapterProvider', () => ({ useAdapter: () => undefined })); +vi.mock('../../../context/NavigationContext', () => ({ + useNavigationContext: () => ({ setContext: () => {}, currentAppName: undefined, recordTitle: undefined }), +})); +// The bar: one button that opens the palette, as the search field does. +vi.mock('../../../layout/AppHeader', async () => { + const { useCommandPalette, useCommandPaletteProviderMounted } = await import('../../../context/CommandPaletteProvider'); + return { + // Drawn once a palette provider is above it (the app list has landed), as + // the real bar draws its search field. + AppHeader: () => { + const { openCommandPalette } = useCommandPalette(); + const mounted = useCommandPaletteProviderMounted(); + return mounted ?