Skip to content

Commit 9f120af

Browse files
fix(app-shell): Home asks for the objects it names instead of loading the whole object registry (#29229)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbBxNE9wTVjSGYnZ9fUpaahr)_ Fixes #29121 Clause-②: no Metadata-protocol: none Claim: 6572592854 · amendment: 6573209598 ## 维护者速读 - 改了什么:租户首页不再读整张对象注册表(`GET /api/v1/meta/object`)和整张视图表;命令面板第一次打开时才挂载,首页的动态、最近访问、面板最近记录都只按名字读自己用到的对象。 - 为什么改:每次进首页都下载全部对象定义(HotCRM 约 875 KB,app-crm 551 KB),只为一个关着的面板和几行图标、标签;网络慢时首页因此多等。 - 风险与回滚:读法从「一次整表」变成「按名逐个读」,首页请求数多了(app-crm 上 +9 个小请求,合计 70 KB 对 558 KB);进入应用后整表已加载时一律直接用整表,不再发请求。回滚即 revert 本 PR。 - 先看:`ui/packages/app-shell/src/hooks/useObjectPresence.ts`(新的 `readObjectsByName`)、`ui/packages/app-shell/src/console/home/HomeLayout.tsx`(面板首开才挂载)、`ui/packages/app-shell/src/hooks/useNavMemberGates.ts`(首页无应用时的能力门)。 - 两分钟验证:打开首页,开发者工具 Network 过滤 `meta/object`:只见 `meta/object/<名字>`,没有不带名字的 `meta/object`;按 ⌘K 搜 `acme`,结果与改前一致。 - 需要你做的:无,席位落地。 ## What changes On `main`, every visit to `/home` read the whole object registry and the whole view list. Measured with CDP initiator stacks on a production Console (app-crm), four readers asked for them unconditionally, each hidden behind the one before by the provider's cache, and four more once there is data: | Reader | Before | Now | |---|---|---| | `HomeLayout`: the command palette's `objects` prop (palette closed) | whole list at mount | palette mounted from its first open; then the host app's scope over its navigation's objects, `views: false` | | `useObjectPresence` outside an app (activity feeds' `sys_activity` check) | whole list | by name, `views: false` | | `useNavMemberGates` outside an app (the feeds' cross-app roster capability gate) | whole list | names-only scope over the app list's `requiresObject` union, `views: false`; the package leg asks without views too | | `HomePage`: recent record row icons | whole list at render | the row's object by name | | `useNavTargetLabel` object label (Home's recent record rows) | whole list | `{ byName: true }` option: the object by name; a view target reads its object with its views | | `useRecentItemLabel`: recent object / list-view rows | whole list | the row's object by name (a view row with its views) | | `ActivityObjectLabel`: activity rows (Home rail, bell) | whole list | the row's object by name | | `CommandPalette` recent record rows (palette open) | whole list | the row's object by name | `readObjectsByName` (in `useObjectPresence.ts`) is the one helper: while nothing has loaded the whole list it asks each name through the names-only scope (objectui#12980); once the list is loaded or loading it reads the list and asks nothing; a hand-rolled context reads its `objects`; no name asks nothing (a names-only scope with no names would be the whole registry). Every in-app leg is unchanged: inside an app the sidebar, routes and gates read what they read before. The palette's record search reads only its navigation's objects (`useRecordSearch` with `objectNames`), so handing it the host app's scope over those names leaves its results unchanged. ## Tests Request-count tests over the real `MetadataProvider` and a fake adapter that records each read: - `console/home/__tests__/homeObjectReads-29121.test.tsx`: presence check, roster gate (answers as the whole list did, including an absent required object), activity label, an empty-names read; CONTROL: with the whole list loaded each reader asks nothing. - `console/home/__tests__/HomeLayout.paletteReads-29121.test.tsx`: closed palette not mounted and no read; opened (click or `?palette=1`) reads `object?package=…` plus the outside name; a package-less app reads by name only. - `console/home/__tests__/HomePage.recentObjectReads-29121.test.tsx`: no recent row → no read; record rows read their objects by name (icon and label pinned); an object row by name and a list-view row with its views (`view`, never `object`). - `chrome/CommandPalette.recentReadsByName-29121.test.tsx`: the palette's recent rows read their objects by name. - Updated pins: `HomeLayout.searchOpensPalette-12601` (the palette probe exists from the first open), `navGateUnionScope-12980` (its "outside an app reads the whole registry" control now pins the by-name read), `openPathObjectReaders-12811` (the census learns `readObjectsByName(…)` as a spelling and a `byName` kind; HomeLayout, HomePage, ActivityObjectLabel and useRecentItemLabel reclassified). ## Acceptance notes - **Files beyond the amendment's seven:** `chrome/CommandPalette.tsx` (the palette's recent rows, its object source while open; found on the production re-measure) and the three updated test pins above. - **Acceptance 1** (no unscoped `GET /api/v1/meta/object` on home): met on app-crm, see Verification. The home now asks the 8 `requiresObject` names of the Setup app's navigation by name (the roster gate), plus `sys_activity` and the objects its recent and activity rows name. That is more requests than one list (19 → 28 on app-crm) and far fewer bytes (558 KB → 70 KB). There is no batch by-names read on `/meta/object` today. - **Acceptance 2** (palette object search unchanged): the palette's text for `acme` is byte-identical between main and this branch on the same server. - The card's premise named only the palette. Measuring showed it was the first of four unconditional readers; the claim was amended (6573209598) to the full shape. - Not changed: a recent dashboard / page / report row still reads that type's list (`useRecentItemLabel`), and opening the palette reads `/meta/report` and `/meta/dataset` (its report entries). Neither is the object registry. ## Verification <details><summary>Home requests, production Console, app-crm (<code>objectstack dev --fresh</code>), recent records and activity rows present</summary> main `0a41075a`: 19 `/api/` requests on reload of `/home`, including `GET /api/v1/meta/object` (551,461 bytes) and `GET /api/v1/meta/view` (6,643 bytes); the initiator of both is `HomeLayout` (`get objects`). This branch `5705cea1`: 28 requests; no `GET /api/v1/meta/object` without a name and no `/meta/view`. By name: `sys_business_unit`, `sys_notification`, `sys_notification_preference`, `sys_notification_template`, `sys_queue`, `sys_queue_member`, `sys_record_share`, `sys_sharing_rule` (Setup's `requiresObject` entries), `sys_activity`, `crm_contact`, `crm_account` (recent and activity rows): 70,164 bytes together. Opening the palette and typing reads `object?package=com.example.crm` (31,636 bytes), `/meta/report`, `/meta/dataset`. Same page on both: recent rows' text and icons, activity rows' labels, and the activity feed's `sys_activity` filter (21 object names) are identical. </details> <details><summary>Ablations (each leg through <code>scripts/ablation-replace.mjs</code>, restored with <code>git diff HEAD</code> empty)</summary> - A1 palette mounted while closed → `HomeLayout.paletteReads` "closed" red. - A2 presence check keeps the whole list outside an app → `homeObjectReads` presence red. - A3 roster gate keeps the whole list outside an app → `homeObjectReads` gate red. - A4 `readObjectsByName` returns the whole list → activity label, empty-names, both HomePage row cases red (4). - A5 HomePage icon reads `metadata.objects` → record rows red. - A6 `useNavTargetLabel` ignores `byName` → both HomePage row cases red. - A7 `useRecentItemLabel` title reads `metadata.objects` → object/view row case red. - A8 palette scope composed with views → both opened cases red. - A9 / A10 palette recent icon / label read the whole list → `CommandPalette.recentReadsByName` red. </details> <details><summary>Local runs at <code>5705cea1</code></summary> - 91 test files naming the touched modules (`CommandPalette`, `useNavTargetLabel`, `readObjectsByName`, the census): 90 files / 802 tests passed (one name listed twice). Earlier heads: 88 files naming the seven hooks/components (2 expected pins updated, then green) and 151 files naming `sharedUserFeeds`, `InboxPopover`, `RecentApps`, `HomeRail`, `CommandPalette`, `AppHeader`: 620 + 498 tests passed. - `turbo run type-check --filter=@object-ui/app-shell`: 65/65 tasks. - `eslint --no-inline-config` on the changed files: 0 errors. - Derived gates (`node scripts/pm/dispatch-gates.mjs --commands`) at `d8b43ffa`: 34 derived, 34 run, all exit 0, reconciled with `--ran` (0 NOT-MEASURED); `check:type-check-debt` under the verify lock; `node scripts/check-sdui-manifest.mjs` exit 0 among them. The full app-shell suite is CI's Test UI. </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (not touched) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jSvXnowXjLpyfdKoux --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8f0d838 commit 9f120af

16 files changed

Lines changed: 1011 additions & 69 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): Home asks for the objects it names instead of loading the whole object registry
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Every visit to `/home` read `GET /api/v1/meta/object` (the whole registry, the largest metadata payload of the page) and `GET /api/v1/meta/view`, for a few object names. Now:
11+
12+
- The command palette is mounted from its first open. Opened, it reads its host app's object scope over the objects its navigation lists, without views: the objects its record search reads.
13+
- Outside an app, the activity feeds' `sys_activity` check (`useObjectPresence`) and their roster's capability gate (`useNavMemberGates`) ask their names by name, without views.
14+
- Recent rows (Home's and the palette's) and activity rows read the object each one names, by name (`readObjectsByName`, `useNavTargetLabel({ byName: true })`, `useRecentItemLabel`, `ActivityObjectLabel`). A list-view row reads its object with its views.
15+
16+
Once something has loaded the whole list (inside an app, say), every one of these reads it and asks nothing more. What Home and the palette show is unchanged.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#29121 — the palette's recent rows read the objects they name, by
5+
* name.
6+
*
7+
* A recent record row draws its object's label and icon (objectui#12852). It
8+
* read them off `useMetadata().objects`, so opening the palette with a recent
9+
* record in the list loaded the whole object registry (and the view list) — on
10+
* Home, where nothing else had loaded it, that was the registry the page no
11+
* longer reads. Now each row's object is read by name.
12+
*
13+
* Real subjects: `CommandPalette`, `CommandPaletteProvider` and
14+
* `MetadataProvider` over a fake adapter that records each read; what the rows
15+
* print is pinned by `CommandPalette.recentItemType-12852`.
16+
*/
17+
18+
import * as React from 'react';
19+
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
20+
import { render, cleanup, waitFor } from '@testing-library/react';
21+
import { MemoryRouter } from 'react-router-dom';
22+
import { createI18n, I18nProvider } from '@object-ui/i18n';
23+
import type { RecentItem } from '../context/RecentItemsProvider';
24+
import { MetadataProvider } from '../providers/MetadataProvider';
25+
26+
vi.mock('@object-ui/auth', async (importOriginal) => ({
27+
...(await importOriginal<Record<string, unknown>>()),
28+
useAuth: () => ({ user: { id: 'u1' }, activeOrganization: null }),
29+
}));
30+
31+
const recent = vi.hoisted(() => ({ items: [] as unknown[] }));
32+
vi.mock('../context/RecentItemsProvider', async (importOriginal) => ({
33+
...(await importOriginal<Record<string, unknown>>()),
34+
useRecentItems: () => ({ recentItems: recent.items, addRecentItem: () => {}, clearRecentItems: () => {} }),
35+
}));
36+
37+
vi.mock('../utils/getIcon', () => ({
38+
getIcon: (name: string) =>
39+
function StubIcon(props: { className?: string }) {
40+
return <svg data-testid="stub-icon" data-glyph={name} className={props.className} />;
41+
},
42+
}));
43+
44+
import { CommandPalette } from './CommandPalette';
45+
import { CommandPaletteProvider } from '../context/CommandPaletteProvider';
46+
47+
const APP = { name: 'cloud', label: 'Cloud', navigation: [] };
48+
49+
const OBJECTS = [
50+
{ name: 'sys_organization', label: 'Organization', icon: 'Building2', fields: {} },
51+
{ name: 'sys_environment', label: 'Environment', icon: 'Server', fields: {} },
52+
{ name: 'sys_user', label: 'User', icon: 'User', fields: {} },
53+
];
54+
55+
function makeAdapter(calls: string[]) {
56+
return {
57+
clearCache: vi.fn(),
58+
invalidateCache: vi.fn(),
59+
getObjectSchema(this: { getClient(): any }, name: string) {
60+
return this.getClient()
61+
.meta.getItem('object', name)
62+
.then((res: any) => (res && typeof res === 'object' && 'item' in res ? res.item : res));
63+
},
64+
getClient: () => ({
65+
meta: {
66+
getItems: (type: string, options?: { packageId?: string }) => {
67+
calls.push(options?.packageId ? `${type}?package=${options.packageId}` : type);
68+
const items = type === 'object' ? OBJECTS : type === 'app' ? [APP] : [];
69+
return Promise.resolve({ type, items: structuredClone(items) });
70+
},
71+
getItem: (type: string, name: string) => {
72+
calls.push(`${type}/${name}`);
73+
const item = (type === 'object' ? OBJECTS : []).find((o) => o.name === name) ?? null;
74+
return Promise.resolve({ item: structuredClone(item) });
75+
},
76+
},
77+
}),
78+
} as unknown as Parameters<typeof MetadataProvider>[0]['adapter'];
79+
}
80+
81+
const metaReads = (calls: string[]) =>
82+
calls.filter((c) => c === 'object' || c === 'view' || c.startsWith('object?') || c.startsWith('object/'));
83+
84+
const VISITED = '2026-10-17T00:00:00.000Z';
85+
const record = (id: string, href: string, label: string): RecentItem => ({ id, type: 'record', href, label, visitedAt: VISITED });
86+
87+
function mount(items: RecentItem[]): string[] {
88+
recent.items = items;
89+
const calls: string[] = [];
90+
render(
91+
<I18nProvider instance={createI18n({ defaultLanguage: 'en', detectBrowserLanguage: false })} persistLanguage={false}>
92+
<MemoryRouter initialEntries={['/home?palette=1']}>
93+
<MetadataProvider adapter={makeAdapter(calls)}>
94+
<CommandPaletteProvider>
95+
<CommandPalette apps={[APP]} activeApp={APP} objects={[]} onAppChange={() => {}} />
96+
</CommandPaletteProvider>
97+
</MetadataProvider>
98+
</MemoryRouter>
99+
</I18nProvider>,
100+
);
101+
return calls;
102+
}
103+
104+
function recentRows() {
105+
return Array.from(document.querySelectorAll('[cmdk-item][data-value^="recent "]')).map((el) => ({
106+
type: el.querySelector('[data-testid="palette-recent-type"]')?.textContent ?? null,
107+
icon: el.querySelector('svg')?.getAttribute('data-glyph') ?? null,
108+
}));
109+
}
110+
111+
const settle = () => new Promise((resolve) => setTimeout(resolve, 50));
112+
113+
beforeEach(() => sessionStorage.clear());
114+
afterEach(() => {
115+
cleanup();
116+
recent.items = [];
117+
});
118+
119+
describe('objectstack#29121 — the palette’s recent rows read their objects by name', () => {
120+
it('each recent record row’s object is read by name, for its type and its icon; the whole list is never read', async () => {
121+
const calls = mount([
122+
record('record:sys_organization:o1', '/apps/cloud/sys_organization/record/o1', 'Objectstack'),
123+
record('record:sys_environment:e1', '/apps/cloud/sys_environment/record/e1', 'Objectstack'),
124+
]);
125+
await waitFor(() =>
126+
expect(recentRows()).toEqual([
127+
{ type: 'Organization', icon: 'Building2' },
128+
{ type: 'Environment', icon: 'Server' },
129+
]),
130+
);
131+
await settle();
132+
expect([...metaReads(calls)].sort()).toEqual(['object/sys_environment', 'object/sys_organization']);
133+
});
134+
});

‎ui/packages/app-shell/src/chrome/CommandPalette.tsx‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ import { confirmUnsavedLeave } from './unsavedEdits.js';
6868
import { useMetadata } from '../providers/MetadataProvider.js';
6969
import { resolveHref, resolveNavItemLabel } from '@object-ui/layout';
7070
import type { NavigationItem } from '@object-ui/types';
71-
import { findByName, useNavTargetLabel } from '../hooks/useNavTargetLabel.js';
71+
import { findByName, useNavTargetLabel, type NavTargetLabelOptions } from '../hooks/useNavTargetLabel.js';
72+
import { readObjectsByName } from '../hooks/useObjectPresence.js';
73+
7274
import { useAuth } from '@object-ui/auth';
7375
import { matchesPaletteQuery } from './paletteMatch.js';
7476
import { fetchPackages, type PkgEntry } from '../views/studio-design/packages-io.js';
@@ -77,6 +79,9 @@ import { DESIGNER_SURFACE_PARAM, formatSurfaceParam } from '../views/metadata-ad
7779
import { flattenNavigation, useAppReportEntries } from '../views/appReportIndex.js';
7880
import { useServedApps } from '../hooks/useLauncherApps.js';
7981

82+
/** A recent row names its object by name (objectstack#29121). */
83+
const RECENT_ROW_LABELS: NavTargetLabelOptions = { byName: true };
84+
8085
/** The palette of the active app: the frame `ConsoleLayout` draws for `/apps/APP`. */
8186
interface AppCommandPaletteProps {
8287
/** Omitted inside an app; `'studio'` is the other scope. */
@@ -389,17 +394,19 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
389394
* address names no object, so its row shows no type and keeps the neutral
390395
* glyph — ⛔ never a type guessed from the title.
391396
*
392-
* `objects` is read inside the function, never at render: the metadata
393-
* cache loads the object list when it is first read, and a closed palette
394-
* reads nothing (objectui#11863).
397+
* The object is read inside the function, never at render, so a closed
398+
* palette reads nothing (objectui#11863); and it is read by name
399+
* (`readObjectsByName`, objectstack#29121), so a few recent rows never load
400+
* the whole object registry — on Home nothing else has.
395401
*/
396402
const metadata = useMetadata();
403+
const recentTargetLabel = useNavTargetLabel(RECENT_ROW_LABELS);
397404
const recentContext = (item: RecentItem): { type?: string; icon?: string } => {
398405
const objectName = recentItemObject(item);
399406
if (!objectName) return {};
400-
const def = findByName(metadata.objects, objectName) as { icon?: unknown } | undefined;
407+
const def = findByName(readObjectsByName(metadata, [objectName]), objectName) as { icon?: unknown } | undefined;
401408
return {
402-
type: targetLabel({ kind: 'object', objectName }) ?? objectName,
409+
type: recentTargetLabel({ kind: 'object', objectName }) ?? objectName,
403410
icon: typeof def?.icon === 'string' && def.icon !== '' ? def.icon : undefined,
404411
};
405412
};

‎ui/packages/app-shell/src/console/__tests__/openPathObjectReaders-12811.test.ts‎

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
* This file finds every reader of the whole object list off the metadata
1313
* context in the packages' and the console's source (a `{ objects }`
1414
* destructured from `useMetadata()`, `useMetadata().objects`, `.objects` on a
15-
* binding of `useMetadata()`, or `getItemsByType('object')`, which holds the
16-
* same list as served), and fails on a reader the table below does not
15+
* binding of `useMetadata()`, `getItemsByType('object')`, which holds the
16+
* same list as served, or `readObjectsByName(…)`, which reads it once it is
17+
* loaded), and fails on a reader the table below does not
1718
* classify, and on a row that names no reader. Each row says where the reader
1819
* runs:
1920
*
2021
* - `scope`: on the open path, it reads `readObjectScope`, and `objects`
2122
* only where no package scopes the read;
2223
* - `action`: it reads `objects` only when an action needs it, after
2324
* `ensureType('object')`;
25+
* - `byName`: it reads the objects it names by name (`readObjectsByName`,
26+
* objectstack#29121), and `objects` only once something else loaded it;
2427
* - `off`: it is not mounted on an app's object-list open, and keeps the
2528
* whole registry (the control: its own pins stay unchanged).
2629
*
@@ -43,7 +46,7 @@ import ts from 'typescript';
4346
const HERE = dirname(fileURLToPath(import.meta.url));
4447
const REPO_ROOT = join(HERE, '..', '..', '..', '..', '..');
4548

46-
type Kind = 'scope' | 'action' | 'off';
49+
type Kind = 'scope' | 'action' | 'byName' | 'off';
4750

4851
/** Every reader of `objects` off the metadata context, and where it runs. */
4952
const OBJECTS_READERS: Record<string, { kind: Kind; why: string }> = {
@@ -53,15 +56,15 @@ const OBJECTS_READERS: Record<string, { kind: Kind; why: string }> = {
5356
},
5457
'packages/app-shell/src/hooks/useNavMemberGates.ts': {
5558
kind: 'scope',
56-
why: "the capability gate reads the app's scope; with no app package (the home feeds) it reads objects",
59+
why: "the capability gate reads the app's scope; outside an app (the home feeds) the app list's required objects by name (objectstack#29121)",
5760
},
5861
'packages/app-shell/src/hooks/useServedViewItems.ts': {
5962
kind: 'scope',
6063
why: "the served object documents behind the view-tab labels (AppHeader, ObjectView) are the app scope's, until something loads the whole registry",
6164
},
6265
'packages/app-shell/src/hooks/useObjectPresence.ts': {
6366
kind: 'scope',
64-
why: "an object's presence (the bell's sys_activity feed) is asked by name through the app scope, until something loads the whole registry",
67+
why: "an object's presence (the bell's and Home's sys_activity feed) is asked by name, through the app scope inside an app, until something loads the whole registry; it also holds readObjectsByName",
6568
},
6669
'packages/app-shell/src/views/appReportIndex.ts': {
6770
kind: 'scope',
@@ -73,12 +76,18 @@ const OBJECTS_READERS: Record<string, { kind: Kind; why: string }> = {
7376
},
7477
'packages/app-shell/src/hooks/useConsoleActionRuntime.tsx': { kind: 'off', why: 'read inside action handlers, when an action runs' },
7578
'packages/plugin-grid/src/ObjectGrid.tsx': { kind: 'off', why: 'read inside an action handler, when an action runs' },
76-
'packages/app-shell/src/hooks/useNavTargetLabel.ts': { kind: 'off', why: 'read when a label is resolved for a nav entry without its own label, or a view entry' },
77-
'packages/app-shell/src/hooks/useRecentItemLabel.ts': { kind: 'off', why: 'read when a recent object or view entry is labelled' },
78-
'packages/app-shell/src/layout/ActivityObjectLabel.tsx': { kind: 'off', why: "the inbox and the home rail's activity rows" },
79+
'packages/app-shell/src/hooks/useNavTargetLabel.ts': {
80+
kind: 'off',
81+
why: 'read when a label is resolved for a nav entry without its own label, or a view entry; with { byName: true } (Home, recent rows) the object is read by name',
82+
},
83+
'packages/app-shell/src/hooks/useRecentItemLabel.ts': { kind: 'byName', why: "a recent object or view entry's object, by name (objectstack#29121)" },
84+
'packages/app-shell/src/layout/ActivityObjectLabel.tsx': { kind: 'byName', why: "the inbox's and the home rail's activity rows, each row's object by name (objectstack#29121)" },
7985
'packages/app-shell/src/chrome/CommandPalette.tsx': { kind: 'off', why: "the Studio scope's object list, read while the palette lists Studio entries" },
80-
'packages/app-shell/src/console/home/HomeLayout.tsx': { kind: 'off', why: 'the home page, outside any app' },
81-
'packages/app-shell/src/console/home/HomePage.tsx': { kind: 'off', why: 'the home page, outside any app' },
86+
'packages/app-shell/src/console/home/HomeLayout.tsx': {
87+
kind: 'scope',
88+
why: "Home's command palette, mounted from its first open: the host app's scope over its navigation's objects (objectstack#29121)",
89+
},
90+
'packages/app-shell/src/console/home/HomePage.tsx': { kind: 'byName', why: "Home's recent record rows, each row's object by name (objectstack#29121)" },
8291
'packages/app-shell/src/views/DashboardView.tsx': { kind: 'off', why: "a dashboard route: its widgets' objects" },
8392
'packages/app-shell/src/views/ReportView.tsx': { kind: 'off', why: "a report route: its columns' objects" },
8493
'packages/app-shell/src/views/PageView.tsx': {
@@ -133,7 +142,7 @@ const isUseMetadataCall = (node: ts.Node | undefined): boolean =>
133142
/** Whether the module reads `objects` off the metadata context, by any of the three spellings. */
134143
function readsObjects(path: string): boolean {
135144
const source = readFileSync(path, 'utf8');
136-
if (!source.includes('useMetadata(')) return false;
145+
if (!source.includes('useMetadata(') && !source.includes('readObjectsByName(')) return false;
137146
const file = ts.createSourceFile(path, source, ts.ScriptTarget.Latest, true, path.endsWith('x') ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
138147
const bindings = new Set<string>();
139148
let found = false;
@@ -165,6 +174,8 @@ function readsObjects(path: string): boolean {
165174
(ts.isIdentifier(callee) && bindings.has(`fn:${callee.text}`))
166175
) found = true;
167176
}
177+
// objectstack#29121 — `readObjectsByName(…)` reads the whole list once it is loaded.
178+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'readObjectsByName') found = true;
168179
ts.forEachChild(node, access);
169180
};
170181
access(file);
@@ -201,11 +212,12 @@ describe('the readers of `useMetadata().objects`, each classified (objectui#1281
201212
expect(found).toEqual(Object.keys(OBJECTS_READERS).sort());
202213
});
203214

204-
it('an open-path reader reads the scope, and an action-time reader waits for the list', () => {
215+
it('an open-path reader reads the scope, an action-time reader waits for the list, and a by-name reader reads by name', () => {
205216
for (const [path, { kind }] of Object.entries(OBJECTS_READERS)) {
206217
const source = readFileSync(join(REPO_ROOT, path), 'utf8');
207218
if (kind === 'scope') expect(source, path).toContain('readObjectScope');
208219
if (kind === 'action') expect(source, path).toContain("ensureType('object')");
220+
if (kind === 'byName') expect(source, path).toContain('readObjectsByName');
209221
}
210222
});
211223
});

0 commit comments

Comments
 (0)