Skip to content

Commit ca3b1be

Browse files
committed
fix(console): the headers take the shell's group through a slot, never import it
PageHeader, the list's view bar and the record page imported the group module, which reads the app's metadata, so every page bundled on its own and every test mounting one bare pulled MetadataProvider in at import: the mobile-app QR bundle lost its exports and the record page tests met the metadata client before their auth mock existed. The scope now hands a stable render function down through shellPageActionsSlot.ts, which imports only React and the phone breakpoint; the group module is imported by the shell alone. Claude-Session: https://claude.ai/code/session_01L6bhgVcCRGjxwhDjrRVYsY Co-authored-by: Claude <noreply@anthropic.com>
1 parent bbf1849 commit ca3b1be

5 files changed

Lines changed: 83 additions & 32 deletions

File tree

‎ui/packages/app-shell/src/layout/PageHeader.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import * as React from 'react';
5959
import { RefreshCw } from 'lucide-react';
6060
import { Button, cn } from '@object-ui/components';
6161
import { useInSetupApp } from '../console/setupApp.js';
62-
import { ShellPageActions, useShellPageActionsOn } from './ShellPageActions.js';
62+
import { useShellPageActionsSlot } from './shellPageActionsSlot.js';
6363

6464
/**
6565
* Props of the app-shell `<PageHeader>` React component.
@@ -271,9 +271,9 @@ export function PageHeader({
271271
// objectstack#36111 — the shell's top-right button group, after the page's
272272
// own actions, where the shell turned it on (`ShellPageActions`); a hairline
273273
// sets it apart from them.
274-
const shellActions = useShellPageActionsOn();
274+
const renderShellGroup = useShellPageActionsSlot();
275275
const pageActions = refreshButton || drawnActions;
276-
const trailing = (pageActions || shellActions) && (
276+
const trailing = (pageActions || renderShellGroup) && (
277277
<div
278278
ref={clusterRef}
279279
className="flex items-center gap-1.5 sm:gap-2 shrink-0"
@@ -282,10 +282,10 @@ export function PageHeader({
282282
>
283283
{refreshButton}
284284
{drawnActions}
285-
{shellActions && pageActions && (
285+
{renderShellGroup && pageActions && (
286286
<span aria-hidden="true" className="h-4 w-px shrink-0 bg-border" data-testid="page-header-shell-divider" />
287287
)}
288-
{shellActions && <ShellPageActions />}
288+
{renderShellGroup?.({})}
289289
</div>
290290
);
291291

‎ui/packages/app-shell/src/layout/ShellPageActions.tsx‎

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
* every in-app page — a list, a record, a dashboard, a report, a custom page.
88
*
99
* The SHELL decides whether it is drawn, not the page: `ConsoleLayout` mounts
10-
* `ShellPageActionsScope`, and each page's header draws `<ShellPageActions/>`
10+
* `ShellPageActionsScope`, which hands the group to the headers through the
11+
* slot in `shellPageActionsSlot.ts` (a header imports the slot, never this
12+
* module and its metadata, Studio and AI reads), and each header draws it
1113
* where its top-right is — the console `PageHeader` after the page's own
1214
* actions (reports and every custom page draw that header too), the record
1315
* page's navigation row before its ✕.
@@ -37,7 +39,11 @@ import { matchAppBySegment, appStudioRoutePath } from '../utils/index.js';
3739
import { useStudioEntryGate, type StudioEntry } from '../hooks/useStudioDesignGate.js';
3840
import { useServedAppLabel } from '../hooks/useServedAppLabel.js';
3941
import { useAiSurfaceEnabled } from '../hooks/useAiSurface.js';
40-
import { usePhoneViewport } from '../hooks/usePhoneViewport.js';
42+
import {
43+
ShellPageActionsSlotContext,
44+
useShellPageActionsSlot,
45+
type ShellPageActionsSlotProps,
46+
} from './shellPageActionsSlot.js';
4147
import { AssistantTopBarButton } from './AssistantTopBarButton.js';
4248
import { HelpMenu } from './HelpMenu.js';
4349

@@ -61,19 +67,23 @@ export function readShellPageActionsSwitch(): boolean {
6167
}
6268
}
6369

64-
const ShellPageActionsContext = React.createContext<boolean>(false);
65-
66-
/** The shell's decision for the pages under it. `on` absent: the switch's answer. */
70+
/**
71+
* The shell's decision for the pages under it. `on` absent: the switch's
72+
* answer. On, it hands the group to the headers through the slot
73+
* (`shellPageActionsSlot.ts`), so a header never imports the group itself.
74+
*/
6775
export function ShellPageActionsScope({ on, children }: { on?: boolean; children: React.ReactNode }) {
6876
const [switched] = React.useState(readShellPageActionsSwitch);
69-
return <ShellPageActionsContext.Provider value={on ?? switched}>{children}</ShellPageActionsContext.Provider>;
77+
return (
78+
<ShellPageActionsSlotContext.Provider value={(on ?? switched) ? renderShellPageActionsGroup : null}>
79+
{children}
80+
</ShellPageActionsSlotContext.Provider>
81+
);
7082
}
7183

7284
/** Whether the group is drawn here: inside a scope that turned it on, and not on a phone. */
7385
export function useShellPageActionsOn(): boolean {
74-
const on = React.useContext(ShellPageActionsContext);
75-
const phone = usePhoneViewport();
76-
return on && !phone;
86+
return useShellPageActionsSlot() !== null;
7787
}
7888

7989
/**
@@ -148,19 +158,17 @@ function EditAppButton({ entry, appText }: { entry: StudioEntry; appText: string
148158
);
149159
}
150160

151-
export interface ShellPageActionsProps {
152-
/**
153-
* The comments entry, first in the group: handed by the list and record
154-
* pages only, nothing until the comments work puts its icon here.
155-
*/
156-
comments?: React.ReactNode;
157-
}
161+
export type ShellPageActionsProps = ShellPageActionsSlotProps;
158162

159163
/** The group, where the shell turned it on; nothing anywhere else. */
160164
export function ShellPageActions({ comments }: ShellPageActionsProps) {
161-
const on = useShellPageActionsOn();
162-
if (!on) return null;
163-
return <ShellPageActionsGroup comments={comments} />;
165+
const renderGroup = useShellPageActionsSlot();
166+
return renderGroup ? renderGroup({ comments }) : null;
167+
}
168+
169+
/** The slot's value while the group is on: one stable function, never remade. */
170+
function renderShellPageActionsGroup(props: ShellPageActionsSlotProps): React.ReactNode {
171+
return <ShellPageActionsGroup {...props} />;
164172
}
165173

166174
function ShellPageActionsGroup({ comments }: ShellPageActionsProps) {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The shell's top-right button group as the page headers see it
5+
* (objectstack#36111): a slot, not an import of the group.
6+
*
7+
* The headers that place the group (the console `PageHeader`, the list's view
8+
* bar, the record page's navigation row) are imported by pages that run
9+
* outside the console shell too: a page bundled on its own, a test that
10+
* mounts one bare. The group itself reads the app's metadata, the Studio
11+
* gate, the AI surface and the help menu's docs, so importing it from a
12+
* header would drag all of that into every one of those pages. The shell
13+
* hands the group in through this context instead (`ShellPageActionsScope`,
14+
* in `ShellPageActions.tsx`); a header reads it here, which imports nothing
15+
* but React and the phone breakpoint.
16+
*
17+
* `null` (outside a scope, the scope turned off, or a phone): the header
18+
* draws nothing for the group.
19+
*/
20+
21+
import * as React from 'react';
22+
import { usePhoneViewport } from '../hooks/usePhoneViewport.js';
23+
24+
export interface ShellPageActionsSlotProps {
25+
/**
26+
* The comments entry, first in the group: handed by the list and record
27+
* pages only, nothing until the comments work puts its icon here.
28+
*/
29+
comments?: React.ReactNode;
30+
}
31+
32+
/** Draws the group with the header's comments entry. */
33+
export type ShellPageActionsRender = (props: ShellPageActionsSlotProps) => React.ReactNode;
34+
35+
/** The group the shell turned on for the pages under it; `null` when off. */
36+
export const ShellPageActionsSlotContext = React.createContext<ShellPageActionsRender | null>(null);
37+
38+
/** The group to draw here: the shell's, unless it is off or this is a phone. */
39+
export function useShellPageActionsSlot(): ShellPageActionsRender | null {
40+
const renderGroup = React.useContext(ShellPageActionsSlotContext);
41+
const phone = usePhoneViewport();
42+
return renderGroup && !phone ? renderGroup : null;
43+
}

‎ui/packages/app-shell/src/views/RecordDetailView.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import { actionContextOrg } from '../utils/actionContextOrg.js';
6565
import { editFormLockedByState } from '../utils/editFormLockedByState.js';
6666
import { matchAppBySegment, resolveHostAppSegment } from '../utils/appRoute.js';
6767
import { hostInConsolePath } from '../utils/hostInConsolePath.js';
68-
import { ShellPageActions, useShellPageActionsOn } from '../layout/ShellPageActions.js';
68+
import { useShellPageActionsSlot } from '../layout/shellPageActionsSlot.js';
6969
import { recycleBinRefusalLabelsOf, recycleBinRestoreOf } from '../utils/recycleBinRestore.js';
7070
import { launchConsoleFlow } from '../utils/flowLaunch.js';
7171
import type { TranslateFn } from '@object-ui/i18n';
@@ -974,7 +974,8 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
974974
// this page (off while the top bar stands); the page face draws it in its
975975
// navigation row, before ✕. A pane or drawer never does: the page under it
976976
// has the group already.
977-
const shellActions = useShellPageActionsOn() && !embedded;
977+
const renderShellGroup = useShellPageActionsSlot();
978+
const shellActions = renderShellGroup !== null && !embedded;
978979
// `language` is also the language a flow launch reads a refused write's
979980
// permission line in.
980981
const { t, language } = useObjectTranslation();
@@ -5401,7 +5402,7 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
54015402
const closePage = pageReturn.toList ?? (objectListPath ? () => navigate(objectListPath) : undefined);
54025403
const pageFrame = closePage || shellActions ? (
54035404
<>
5404-
{shellActions && <ShellPageActions />}
5405+
{shellActions && renderShellGroup?.({})}
54055406
{closePage && (
54065407
<RecordTopBarButton label={t('common.close', { defaultValue: 'Close' })} onClick={closePage} data-testid="record-page-close">
54075408
<X className="h-3.5 w-3.5" />

‎ui/packages/app-shell/src/views/objectViewPageHeader.tsx‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import type { useObjectLabel, useObjectTranslation } from '@object-ui/i18n';
2828
import { FavoriteMenuItem } from '../layout/SidebarItemMenu.js';
2929
import type { useObjectListFavorite } from '../layout/SidebarItemMenu.js';
3030
import { PageHeader } from '../layout/PageHeader.js';
31-
import { ShellPageActions, useShellPageActionsOn } from '../layout/ShellPageActions.js';
31+
import { useShellPageActionsSlot } from '../layout/shellPageActionsSlot.js';
3232
import { ManagedByBadge } from '../components/ManagedByBadge.js';
3333
import { EnvironmentListToolbar } from '../environment/EnvironmentListToolbar.js';
3434
import { ListHeaderActionBar } from './objectViewHeaderLaunchGate.js';
@@ -177,7 +177,6 @@ export function ObjectViewPageHeader(props: ObjectViewPageBarProps) {
177177
setPageColumn(el?.parentElement ?? null);
178178
}, []);
179179
useListPageScope(pageColumn);
180-
const shellActions = useShellPageActionsOn();
181180
return (
182181
<div className="hidden sm:block" ref={headerRootRef}>
183182
<PageHeader
@@ -272,7 +271,7 @@ export function ObjectViewBarTrailing({ tools, ...props }: ObjectViewPageBarProp
272271
setPageColumn(el?.closest<HTMLElement>(`[${OBJECT_VIEW_PAGE_COLUMN_ATTR}]`) ?? null);
273272
}, []);
274273
useListPageScope(pageColumn);
275-
const shellActions = useShellPageActionsOn();
274+
const renderShellGroup = useShellPageActionsSlot();
276275
return (
277276
<div
278277
ref={rootRef}
@@ -285,10 +284,10 @@ export function ObjectViewBarTrailing({ tools, ...props }: ObjectViewPageBarProp
285284
<ObjectViewPageBarActions {...props} />
286285
</span>
287286
</div>
288-
{shellActions && (
287+
{renderShellGroup && (
289288
<>
290289
<span aria-hidden="true" className="mx-1 h-4 w-px shrink-0 bg-border" data-testid="list-view-bar-shell-divider" />
291-
<ShellPageActions />
290+
{renderShellGroup({})}
292291
</>
293292
)}
294293
</div>

0 commit comments

Comments
 (0)