Skip to content

Commit d25a2a3

Browse files
committed
fix(app-shell): the record route's object scope follows where an authored page applies; merge main (#36150)
L1-c and L2 rework on #36174: - appObjectScope: declaredRecordPage reads authoredRecordPageApplies, so a phone record route takes the synthesized page's arm and the standard page's child tabs are all there; AppContent and the prefetch hand it usePhoneViewport(), so the scope follows the width across 768. - #36114's "no icon on a hand-written page" pin mounts the full page; a new case pins the drawer of an authored-page object offering the panel. - feedRecordScope mounts the drawer for its synthesized-page cases again (#36114 opens the drawer's panel there). - New AppContent.authoredPagePhoneScope-36150 pin (6) and a print-style media-query pin on the view. - Nits: ruling cited in the kept-objects jsdoc, object-name key noted, pages.mdx names the 768 px window and the interface preview, a test title. - Skills-docs: follow-up #36179 (spec describes: #36180). Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgVHYk1S4MD4WibYGKk
1 parent 331ddbd commit d25a2a3

10 files changed

Lines changed: 398 additions & 16 deletions

‎.changeset/36150-authored-record-page-desktop-only.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ feat(app-shell): an authored record page is drawn on the desktop full page only;
66

77
Clause-②: no
88
Metadata-protocol: semantic
9+
Skills-docs: follow-up #36179 — skills/objectstack-ui/rules/record-page.md rules 4 and 5 (the `record_more` advice); skills edits ride a domain:skills PR
910

1011
What a `kind: 'full'` record page means changes: it is drawn on the desktop full page only. On a phone, and in every embedded record view (the side drawer a list opens, the split pane, an interface page's preview), the record draws the platform's standard page for its object, whether or not the object has an authored page. **Open full page** from the drawer still lands on the authored page.
1112

‎content/docs/ui/pages.mdx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,10 @@ Use a slotted page to change one or two parts of an otherwise standard record pa
260260

261261
### Where an authored page applies
262262

263-
A `kind: 'full'` record page is drawn on the **desktop full page** only. On a phone, and in the
264-
side drawer or split pane a list opens a record in, the record takes the platform's standard
265-
page for its object, whether or not the object has an authored page; **Open full page** from the
263+
A `kind: 'full'` record page is drawn on the **desktop full page** only. On a phone (any window
264+
narrower than 768 px, a narrowed desktop window included), and in every embedded record view (the
265+
side drawer or split pane a list opens a record in, and an interface page's preview), the record
266+
takes the platform's standard page for its object, whether or not the object has an authored page; **Open full page** from the
266267
drawer lands on the authored one. There is no setting that keeps an authored page on the phone
267268
or in the drawer.
268269

‎examples/app-showcase/test/record-action-location-hosts.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('showcase_task record action locations have a stock host (#22030)', ()
102102
expect(result.data?.actions).toEqual(ids);
103103
});
104104

105-
it('lists the task\'s whole record_header / record_more set — what the synthesized header carries — but the section bar\'s', () => {
105+
it('lists the task\'s whole record_header / record_more set — what the synthesized header carries — less the actions its section bar draws', () => {
106106
expect(ids.every((id) => typeof id === 'string')).toBe(true);
107107
expect(new Set(ids).size, 'no id is listed twice').toBe(ids.length);
108108
// An action placed at record_section AND record_more is drawn on this

‎ui/packages/app-shell/src/console/AppContent.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,11 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
486486
// app whose served item carries its package; the whole registry everywhere
487487
// else, as before (that module says why). A page route reads the objects
488488
// its page binds (objectui#12980), resolved as `PageView` resolves the page,
489-
// and a record route those of its declared record page (objectui#13046).
489+
// and a record route those of its declared record page (objectui#13046),
490+
// on the desktop only: on a phone the view draws the standard page, whose
491+
// related lists read every object that points at the record's
492+
// (objectstack#36150), so the scope follows the width as the view does.
493+
const phoneViewport = usePhoneViewport();
490494
const {
491495
candidate: scopeCandidate,
492496
scope: objectScope,
@@ -546,6 +550,7 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
546550
const appName = typeof activeApp?.name === 'string' ? activeApp.name : undefined;
547551
return bundledReads && appName ? bundledReads.objectsReferencing(appName, objectName) : BUNDLE_MISS;
548552
},
553+
phoneViewport,
549554
);
550555
// Until the app list has loaded, a scope candidate does not know its package
551556
// yet, and reads nothing (the splash is up).
Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#36150 — the record ROUTE's object scope follows the page the
5+
* record view draws. An authored full record page is drawn on the desktop
6+
* full page only; on a phone the view draws the standard page, whose child
7+
* tabs are derived from every object that points at the record's object. So
8+
* on a phone the route must not read only the objects the authored page binds
9+
* (L2 M1 on #36174): it takes the synthesized page's arm, as the view does.
10+
*
11+
* Through the real `AppContent` and `MetadataProvider` (the harness of
12+
* `AppContent.emptyPackageScope-13046.test.tsx`), the view a double that
13+
* prints the object list it is handed:
14+
*
15+
* - desktop: the authored page's objects, as before (CONTROL); a child the
16+
* page does not bind is not in the list.
17+
* - phone: the whole registry, the unbound child included.
18+
* - the width crossing 768 on an open record moves the scope with it.
19+
* - a media-query change that leaves the window wide (what printing fires)
20+
* keeps the authored page's scope (N4).
21+
* - the host's exceptions on a phone: a page named in the URL, and the
22+
* platform user page, still read their page's objects.
23+
*/
24+
25+
import '@testing-library/jest-dom/vitest';
26+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
27+
import React from 'react';
28+
import { act, cleanup, render, screen, waitFor } from '@testing-library/react';
29+
import { MemoryRouter, Routes, Route } from 'react-router-dom';
30+
import { AuthProvider, ActiveOrganizationStorage } from '@object-ui/auth';
31+
import type { AuthClient, AuthOrganization } from '@object-ui/auth';
32+
33+
vi.mock('@object-ui/plugin-designer', async (importOriginal) => ({
34+
...(await importOriginal<typeof import('@object-ui/plugin-designer')>()),
35+
CreateAppPage: () => null,
36+
EditAppPage: () => null,
37+
DashboardDesignPage: () => null,
38+
}));
39+
// The chrome: what the sidebar's capability gate asks, as `ConsoleLayout` does.
40+
vi.mock('../../layout/ConsoleLayout', async () => {
41+
const { useNavMemberGates } = await import('../../hooks/useNavMemberGates');
42+
return {
43+
ConsoleLayout: ({ children }: { children?: React.ReactNode }) => {
44+
const gates = useNavMemberGates();
45+
return (
46+
<div data-testid="console-layout">
47+
<span data-testid="members-entry">{String(gates.checkCapability('object', 'sys_member'))}</span>
48+
{children}
49+
</div>
50+
);
51+
},
52+
};
53+
});
54+
vi.mock('../../chrome/CommandPalette', () => ({ CommandPalette: () => null }));
55+
vi.mock('../../chrome/KeyboardShortcutsDialog', () => ({ KeyboardShortcutsDialog: () => null }));
56+
vi.mock('../../chrome/OnboardingWalkthrough', () => ({ OnboardingWalkthrough: () => null }));
57+
vi.mock('../../views/ObjectView', () => ({
58+
ObjectView: ({ objects }: { objects: Array<{ name: string }> }) => (
59+
<div data-testid="object-view">{objects.map((o) => o.name).join(',')}</div>
60+
),
61+
}));
62+
vi.mock('../../views/RecordDetailView', () => ({
63+
RecordDetailView: ({ objects }: { objects: Array<{ name: string }> }) => (
64+
<div data-testid="record-view">{objects.map((o) => o.name).join(',')}</div>
65+
),
66+
}));
67+
vi.mock('@object-ui/i18n', async (importOriginal) => ({
68+
...(await importOriginal<Record<string, unknown>>()),
69+
useObjectTranslation: () => ({
70+
t: (key: string, options?: Record<string, unknown>) => String(options?.defaultValue ?? key),
71+
}),
72+
useObjectLabel: () => ({ objectLabel: ({ label }: { label?: string }) => label, objectPluralLabel: () => '' }),
73+
}));
74+
75+
const dataSourceStub = {
76+
onConnectionStateChange: () => () => {},
77+
getConnectionState: () => 'connected',
78+
};
79+
vi.mock('../../providers/AdapterProvider', async (importOriginal) => ({
80+
...(await importOriginal<Record<string, unknown>>()),
81+
useAdapter: () => dataSourceStub,
82+
}));
83+
84+
const actionRunnerStub = { registerHandler: vi.fn(), getContext: () => ({}) };
85+
vi.mock('@object-ui/react', async (importOriginal) => ({
86+
...(await importOriginal<Record<string, unknown>>()),
87+
useActionRunner: () => ({ execute: vi.fn(), runner: actionRunnerStub }),
88+
useGlobalUndo: () => {},
89+
useMutationInvalidationBridge: () => {},
90+
}));
91+
92+
// `AppContent` reaches a dynamic `import('@objectstack/lint')` (through
93+
// `ConsoleLayout` → `DraftPreviewBar`, statically): pay its load at collection,
94+
// never inside a case's clocked window (`check:test-source-alias`).
95+
import '@objectstack/lint';
96+
import { AppContent } from '../AppContent';
97+
import { MetadataProvider } from '../../providers/MetadataProvider';
98+
99+
const CLOUD = 'com.example.cloud';
100+
const CRM = 'app.crm';
101+
const OBJECTS = [
102+
{ name: 'sys_member', _packageId: 'plugin.auth', fields: { user: { type: 'lookup', reference: 'sys_user' } } },
103+
{ name: 'sys_user', _packageId: 'plugin.auth', fields: {} },
104+
{ name: 'crm_account', _packageId: CRM, fields: {} },
105+
{ name: 'crm_opportunity', _packageId: CRM, fields: { account: { type: 'lookup', reference: 'crm_account' } } },
106+
{ name: 'crm_quote', _packageId: 'app.sales', fields: { opportunity: { type: 'master_detail', reference: 'crm_opportunity' } } },
107+
// A child of the opportunity the authored page does not bind.
108+
{ name: 'crm_task', _packageId: 'app.service', fields: { opportunity: { type: 'lookup', reference: 'crm_opportunity' } } },
109+
];
110+
const CLOUD_NAVIGATION = [{ id: 'n1', type: 'object', label: 'Members', objectName: 'sys_member' }];
111+
const CRM_NAVIGATION = [{ id: 'c1', type: 'object', label: 'Accounts', objectName: 'crm_account' }];
112+
const OPPORTUNITY_PAGE = {
113+
name: 'opportunity_detail',
114+
type: 'record',
115+
object: 'crm_opportunity',
116+
kind: 'full',
117+
isDefault: true,
118+
regions: [{ name: 'main', components: [{ type: 'record:related_list', properties: { objectName: 'crm_quote' } }] }],
119+
};
120+
const USER_PAGE = {
121+
name: 'user_detail',
122+
type: 'record',
123+
object: 'sys_user',
124+
kind: 'full',
125+
isDefault: true,
126+
regions: [{ name: 'main', components: [{ type: 'record:related_list', properties: { objectName: 'sys_member' } }] }],
127+
};
128+
129+
const server = { calls: [] as string[], apps: [] as unknown[], pages: [] as unknown[] };
130+
131+
function makeAdapter() {
132+
return {
133+
clearCache: vi.fn(),
134+
invalidateCache: vi.fn(),
135+
// objectui#13044 — the provider's by-name OBJECT read goes through the
136+
// adapter's `getObjectSchema`; this double answers it from the same door.
137+
getObjectSchema(this: { getClient(): any }, name: string) {
138+
return this.getClient()
139+
.meta.getItem('object', name)
140+
.then((res: any) => (res && typeof res === 'object' && 'item' in res ? res.item : res));
141+
},
142+
getClient: () => ({
143+
meta: {
144+
getItems: (type: string, options?: { packageId?: string; names?: readonly string[] }) => {
145+
// objectstack#34244 — the `?names=` presence read answers the asked names it holds and leaves an absent one out, as the list door does.
146+
if (options?.names) {
147+
server.calls.push(`${type}?names=${options.names.join(',')}`);
148+
const named: any[] = type === 'object' ? (OBJECTS as any[]).filter((o: any) => options.names!.includes(o.name)) : [];
149+
return Promise.resolve({ type, items: structuredClone(named) });
150+
}
151+
server.calls.push(options?.packageId ? `${type}?package=${options.packageId}` : type);
152+
const all = type === 'object' ? OBJECTS : type === 'app' ? server.apps : type === 'page' ? server.pages : [];
153+
const items = options?.packageId ? all.filter((o: any) => o._packageId === options.packageId) : all;
154+
return Promise.resolve({ type, items: structuredClone(items) });
155+
},
156+
getItem: (type: string, name: string) => {
157+
server.calls.push(`${type}/${name}`);
158+
const item = (type === 'object' ? OBJECTS : []).find((o) => o.name === name);
159+
return item
160+
? Promise.resolve({ type, name, item: structuredClone(item) })
161+
: Promise.reject(Object.assign(new Error('not found'), { httpStatus: 404, code: 'RESOURCE_NOT_FOUND' }));
162+
},
163+
},
164+
}),
165+
} as unknown as Parameters<typeof MetadataProvider>[0]['adapter'];
166+
}
167+
168+
const USER = 'u_36150';
169+
const ORG: AuthOrganization = { id: 'org_a', name: 'Org A', slug: 'a' };
170+
171+
function authClient(): AuthClient {
172+
return {
173+
getSession: vi.fn(async () => ({
174+
user: { id: USER, name: 'Ada', email: 'ada@test.com', role: 'admin', positions: ['admin'] },
175+
session: { token: 'tok-36150', activeOrganizationId: ORG.id },
176+
})),
177+
signOut: vi.fn(async () => undefined),
178+
getConfig: vi.fn(async () => ({ features: {} })),
179+
listOrganizations: vi.fn(async () => [ORG]),
180+
getActiveOrganization: vi.fn(async () => ORG),
181+
setActiveOrganization: vi.fn(async () => ORG),
182+
getActiveMember: vi.fn(async () => ({ id: 'm1', organizationId: ORG.id, userId: USER, role: 'owner' })),
183+
} as unknown as AuthClient;
184+
}
185+
186+
function boot(url: string) {
187+
render(
188+
<AuthProvider authUrl="/api/auth" client={authClient()}>
189+
<MetadataProvider adapter={makeAdapter()}>
190+
<MemoryRouter initialEntries={[url]}>
191+
<Routes>
192+
<Route path="/apps/:appName/*" element={<AppContent />} />
193+
</Routes>
194+
</MemoryRouter>
195+
</MetadataProvider>
196+
</AuthProvider>,
197+
);
198+
}
199+
200+
const objectCalls = () => server.calls.filter((c) => c === 'object' || c.startsWith('object?') || c.startsWith('object/'));
201+
const settle = () => new Promise((resolve) => setTimeout(resolve, 50));
202+
const listed = () => (screen.getByTestId('record-view').textContent ?? '').split(',');
203+
204+
// The viewport: `usePhoneViewport` reads `innerWidth` and listens to the
205+
// media query; this double lets a case move the width and fire the query.
206+
const mediaListeners = new Set<() => void>();
207+
function setWidth(width: number) {
208+
Object.defineProperty(window, 'innerWidth', { value: width, configurable: true, writable: true });
209+
}
210+
function fireMediaChange() {
211+
act(() => {
212+
for (const listener of [...mediaListeners]) listener();
213+
});
214+
}
215+
const originalWidth = window.innerWidth;
216+
const originalMatchMedia = window.matchMedia;
217+
218+
beforeEach(() => {
219+
server.calls = [];
220+
server.pages = [OPPORTUNITY_PAGE, USER_PAGE];
221+
server.apps = [
222+
{ name: 'cloud', label: 'Cloud', _packageId: CLOUD, navigation: CLOUD_NAVIGATION },
223+
{ name: 'crm', label: 'CRM', _packageId: CRM, navigation: CRM_NAVIGATION },
224+
];
225+
localStorage.clear();
226+
sessionStorage.clear();
227+
ActiveOrganizationStorage.clear();
228+
mediaListeners.clear();
229+
setWidth(1280);
230+
window.matchMedia = ((query: string) => {
231+
const max = Number(/max-width:\s*(\d+)px/.exec(query)?.[1] ?? Infinity);
232+
return {
233+
media: query,
234+
get matches() {
235+
return window.innerWidth <= max;
236+
},
237+
onchange: null,
238+
addEventListener: (_type: string, listener: () => void) => mediaListeners.add(listener),
239+
removeEventListener: (_type: string, listener: () => void) => mediaListeners.delete(listener),
240+
addListener: (listener: () => void) => mediaListeners.add(listener),
241+
removeListener: (listener: () => void) => mediaListeners.delete(listener),
242+
dispatchEvent: () => false,
243+
};
244+
}) as unknown as typeof window.matchMedia;
245+
});
246+
247+
afterEach(() => {
248+
cleanup();
249+
ActiveOrganizationStorage.clear();
250+
setWidth(originalWidth);
251+
window.matchMedia = originalMatchMedia;
252+
});
253+
254+
describe('the record route reads the objects of the page the view draws (objectstack#36150)', () => {
255+
it('CONTROL — desktop: the authored page\'s objects, by name; the child it does not bind is not read', async () => {
256+
boot('/apps/crm/crm_opportunity/record/r1');
257+
await waitFor(() => expect(screen.getByTestId('record-view')).toHaveTextContent('crm_quote'));
258+
await settle();
259+
expect(objectCalls()).not.toContain('object');
260+
expect(listed()).not.toContain('crm_task');
261+
});
262+
263+
it('phone: the standard page\'s scope, every object pointing at the record\'s, the unbound child included', async () => {
264+
setWidth(375);
265+
boot('/apps/crm/crm_opportunity/record/r1');
266+
await waitFor(() => expect(listed()).toContain('crm_task'));
267+
expect(listed()).toContain('crm_quote');
268+
expect(objectCalls()).toContain('object');
269+
});
270+
271+
it('the width crossing 768 on an open record moves the scope with it', async () => {
272+
boot('/apps/crm/crm_opportunity/record/r1');
273+
await waitFor(() => expect(screen.getByTestId('record-view')).toHaveTextContent('crm_quote'));
274+
await settle();
275+
expect(listed()).not.toContain('crm_task');
276+
setWidth(600);
277+
fireMediaChange();
278+
await waitFor(() => expect(listed()).toContain('crm_task'));
279+
});
280+
281+
it('N4 — a media-query change that leaves the window wide (printing fires one) keeps the authored page\'s scope', async () => {
282+
boot('/apps/crm/crm_opportunity/record/r1');
283+
await waitFor(() => expect(screen.getByTestId('record-view')).toHaveTextContent('crm_quote'));
284+
await settle();
285+
act(() => {
286+
window.dispatchEvent(new Event('beforeprint'));
287+
});
288+
fireMediaChange();
289+
await settle();
290+
expect(objectCalls()).not.toContain('object');
291+
expect(listed()).not.toContain('crm_task');
292+
});
293+
294+
it('phone: a page named in the URL still reads its own objects, never the whole registry', async () => {
295+
setWidth(375);
296+
boot('/apps/crm/crm_opportunity/record/r1/page/opportunity_detail');
297+
await waitFor(() => expect(screen.getByTestId('record-view')).toHaveTextContent('crm_quote'));
298+
await settle();
299+
expect(objectCalls()).not.toContain('object');
300+
expect(listed()).not.toContain('crm_task');
301+
});
302+
303+
it('phone: the platform user page keeps its own page, so its route reads that page\'s objects', async () => {
304+
setWidth(375);
305+
boot('/apps/cloud/sys_user/record/u1');
306+
await waitFor(() => expect(screen.getByTestId('record-view')).toHaveTextContent('sys_member'));
307+
await settle();
308+
expect(objectCalls()).not.toContain('object');
309+
});
310+
});

0 commit comments

Comments
 (0)