Skip to content

Commit 1afb6d4

Browse files
fix(console): on a phone, a page the assistant opens closes its sheet (#37571)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg8JRuu4biowMGgDVcNVcsSp)_ Fixes #37556 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:在手机上用应用内 AI,点回答下方的引用后,AI 对话面板自动收起,直接看到被标出的那一段;再打开 AI 面板,还是原来的对话。电脑上面板照旧留在页面旁边。 - 为什么做:记录 AI 问询专题里引用条的跟进,原先手机上点引用像没反应,要手动关面板才看得到。 - 出错会怎样:手机上点 AI 里的链接后面板该收不收或不该收时收起;对话和数据不受影响,撤回本次合并即可恢复原样。 - 要你做什么:无。 ## What changes - `ui/packages/app-shell/src/layout/useConsoleChatDock.tsx`: on a phone (the drawer is a bottom sheet over the page), the host closes the sheet when the location moves by a PUSH or POP away from the history entry (`location.key`) the sheet was shown open on. A PUSH onto the same URL counts (a second click on the same citation chip carries fresh section state to the same URL). A REPLACE never closes it: a page rewriting its own query, the host's handoff hand-over, and an old `/ai…` link landing with the drawer armed open all stay as they were. - The entry the sheet was shown on is kept per tab in sessionStorage (`ai-chat-dock-sheet-shown-at`, cleared whenever the sheet is closed), not in the hook: a chip in a sheet opened over Home lands on an app's record through another layout, which mounts a new dock host that never saw the navigation (found by the first booted check). Where sessionStorage throws, a module copy stands in, so the rule still works for the life of the page. - Review rework (contract review 7195408408, seat REWORK 7195422188): - S1: the move away is noted on the navigation itself, before the phone check. `useIsMobile` answers `false` on a host's first render; an app named by its alias lands through `AppContent`, which REPLACEs the address on mount, so a rule judged only once the flag settled saw that REPLACE and kept the sheet open. - N1: at a desktop width (read off the window, since `useIsMobile`'s first-render `false` cannot tell) the entry is dropped, so turning a tablet portrait, landscape, portrait does not close the drawer on the turn. - S2: a POP case is pinned. N3: the storage-failure jsdoc is corrected and the in-memory fallback added. N2 and N4 accepted as they are. - The rule lives in the host, not at the chip: every navigation the chat makes on a phone (citation chip, `open_record`, list link, open-form) now reveals the page; the chip's click path is not touched. - The conversation is kept: closing only collapses the sheet; the dock target is untouched, so reopening shows the same thread. Desktop rail and the full-window rule are unchanged. - Changeset `.changeset/37556-phone-dock-closes-on-citation.md` (patch, `@object-ui/app-shell`). Read first: `useConsoleChatDock.tsx`, the effect under the full-window one and the storage helpers above `hasHandoff`. ## Tests - `ui/packages/app-shell/src/layout/__tests__/useConsoleChatDock.phoneCollapseOnNavigate-37556.test.tsx` (9): the real host, `useChatDockState` and router; `useIsMobile` is a stand-in with the real hook's timing (`false` on the first render, measured in its mount effect, again on resize); stand-in sheet/rail. Cases: a phone chip click (PUSH) closes the sheet and reopening with no target shows the same conversation; a same-URL re-click closes it; Back (POP) closes it; a chip from Home into an app (two layouts, two hosts) closes it and reopening shows the same thread; the alias landing (a parent `AppContent`-shaped redirect REPLACEs on mount while the new host's flag is held back one task) closes it; with `window.sessionStorage` throwing, a chip click closes it; a same-page REPLACE leaves it open; a tablet turn to landscape, a chip click there, and a turn back leaves the drawer open; CONTROL: at desktop width the rail stays open after a chip click. - The new tests against the previous head's hook (b220ce8): 3 failed (alias landing, storage throwing, tablet turn), 6 passed. - Ablation (the `collapse()` call replaced by a no-op): 6 failed, 3 passed (every closing case red; the REPLACE case, the tablet turn and the desktop control green); restored 9/9. ## Acceptance notes - Acceptance 1 (test): above. - Acceptance 2 (booted-console phone check): see Verification. ## Verification - Local on e4692c3: the new test 9/9; `@object-ui/app-shell` `type-check` exit 0; derived gate families: see the report. The package's whole suite is left to CI's `Test UI` (test-run scope, not a Clause-② narrowing). - Two-minute check: `pnpm --dir ui exec vitest run packages/app-shell/src/layout/__tests__/useConsoleChatDock.phoneCollapseOnNavigate-37556.test.tsx`, expected 9 passed. - Booted-console phone check (iPhone 13 profile). Showcase app (`objectstack dev --seed-admin`) with the `ui/` console dev server pointed at it, on `main` (which now carries PR #37539, so history draws chips) merged with this branch. **Injected, not produced**: no producer emits the citations part before cloud 10c, so the run serves the conversation-history read with an answer carrying a `data-record-citations` part, and a one-agent catalog because the boot has no model. - Package address: the old `/ai/ask/CONVERSATION` link lands on Home with the sheet open and 3 chips. Chip click: `/apps/com.example.showcase/showcase_field_zoo/record/ID?section=contractor-scope`, sheet gone (0 in the DOM), the marked heading `Contractor scope` at top 45 px, in view. Reopening: the same 3 chips. The same chip again: sheet gone, heading in view. - Alias path (S1): the object read is served with the app's NAME (`showcase_app`) as its package, so the chip lands on `/apps/showcase_app/…` and the app shell REPLACEs it with `/apps/com.example.showcase/…`. Sheet gone, heading at top 45 px, in view; reopening shows the same chips; the same chip again closes it again. - Screenshots: `objectstack-seat5/ai-36996/shots-37556/` in the project files (`phone-dock-*.png` and `phone-alias-dock-*.png`, four each, plus the script). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CXDoFxnz75MqdAxLSW)_ <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CXDoFxnz75MqdAxLSW --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent bebc2cf commit 1afb6d4

3 files changed

Lines changed: 390 additions & 2 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(console): on a phone, a page the AI assistant opens closes the assistant sheet so the page shows
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
On a phone the assistant is a bottom sheet over the page. Clicking a citation chip in an answer opened the cited record section underneath, but the sheet stayed open over it, so the marked heading was hidden and the click looked like it did nothing. Now a navigation the assistant makes on a phone (a citation chip, a record or list link, opening a form) closes the sheet, including a second click on the same chip. The conversation is kept: reopening the assistant shows the same thread. On a desktop the assistant is a panel beside the page and stays open, as before.
Lines changed: 297 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,297 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#37556 — on a phone the assistant drawer is a bottom sheet over
5+
* the page. A citation chip in it navigates to the cited record section, and
6+
* the sheet must get out of the way so the marked heading is visible; on a
7+
* desktop the drawer is a rail beside the page and stays open.
8+
*
9+
* ## Real subjects
10+
*
11+
* The real `useConsoleChatDock` host, the real `useChatDockState`, the real
12+
* router. `useIsMobile` is a stand-in with the real hook's timing: `false` on
13+
* a host's first render, the window's width from its mount effect on, and
14+
* again on every resize. The sheet and the rail are stand-ins that show
15+
* whether the host mounts them open: which chrome is open is the subject, not
16+
* the chat inside. The chip is a stand-in that navigates the way the chat's
17+
* record-citation door does (a PUSH to the record route with fresh router
18+
* state).
19+
*/
20+
21+
import '@testing-library/jest-dom/vitest';
22+
import { describe, it, expect, vi, afterEach } from 'vitest';
23+
import React from 'react';
24+
import { render, screen, fireEvent, cleanup, act } from '@testing-library/react';
25+
import { MemoryRouter, Route, Routes, useLocation, useNavigate, useParams } from 'react-router-dom';
26+
27+
// `settleLate` holds a newly mounted host's first measurement back one task,
28+
// so a REPLACE its page makes on mount lands while the flag still reads
29+
// `false`: the order the console can take, pinned here deterministically.
30+
let settleLate = false;
31+
vi.mock('@object-ui/components', async (importOriginal) => {
32+
const R = await import('react');
33+
return {
34+
...(await importOriginal<Record<string, unknown>>()),
35+
useIsMobile: () => {
36+
const [mobile, setMobile] = R.useState<boolean | undefined>(undefined);
37+
R.useEffect(() => {
38+
const measure = () => setMobile(window.innerWidth < 768);
39+
const late = settleLate ? setTimeout(measure, 0) : undefined;
40+
if (!settleLate) measure();
41+
window.addEventListener('resize', measure);
42+
return () => {
43+
clearTimeout(late);
44+
window.removeEventListener('resize', measure);
45+
};
46+
}, []);
47+
return !!mobile;
48+
},
49+
};
50+
});
51+
52+
vi.mock('../ChatDock', async (importOriginal) => ({
53+
...(await importOriginal<Record<string, unknown>>()),
54+
ChatDockPanel: () => <aside data-testid="chat-dock-panel" />,
55+
ChatDockMobileSheet: ({ open, target }: { open: boolean; target?: { conversationId?: string } }) => (
56+
<div
57+
data-testid="chat-dock-mobile-sheet"
58+
data-open={String(open)}
59+
data-conversation={target?.conversationId ?? ''}
60+
/>
61+
),
62+
}));
63+
64+
import { useConsoleChatDock } from '../useConsoleChatDock';
65+
66+
const HOME = '/home';
67+
const CITED = '/apps/crm/account/record/a1?section=pricing';
68+
// The app named by an alias: the app shell moves it to the package address on
69+
// mount, with a REPLACE (`AppContent`'s alias redirect).
70+
const CITED_BY_ALIAS = '/apps/crm-alias/account/record/a1?section=pricing';
71+
72+
function setWidth(width: number) {
73+
Object.defineProperty(window, 'innerWidth', { configurable: true, writable: true, value: width });
74+
}
75+
76+
function resize(width: number) {
77+
setWidth(width);
78+
act(() => {
79+
window.dispatchEvent(new Event('resize'));
80+
});
81+
}
82+
83+
function Host({ children }: { children?: React.ReactNode }) {
84+
const { control, rail, sheet } = useConsoleChatDock({ enabled: true, appPackageId: 'crm' });
85+
const navigate = useNavigate();
86+
const location = useLocation();
87+
return (
88+
<>
89+
<button data-testid="open-dock" onClick={() => control?.open({ conversationId: 'conv-1' })} />
90+
{/* The robot: opens the drawer on whatever it shows, naming no target. */}
91+
<button data-testid="reopen-dock" onClick={() => control?.open()} />
92+
<button data-testid="chip" onClick={() => navigate(CITED, { state: { opened: Math.random() } })} />
93+
<button
94+
data-testid="chip-by-alias"
95+
onClick={() => navigate(CITED_BY_ALIAS, { state: { opened: Math.random() } })}
96+
/>
97+
<button data-testid="back" onClick={() => navigate(-1)} />
98+
<button
99+
data-testid="replace-same-page"
100+
onClick={() =>
101+
navigate({ pathname: location.pathname, search: location.search }, { replace: true, state: null })
102+
}
103+
/>
104+
<output data-testid="location">{`${location.pathname}${location.search}`}</output>
105+
{rail}
106+
{sheet}
107+
{children}
108+
</>
109+
);
110+
}
111+
112+
/**
113+
* `AppContent`'s alias redirect: on mount, an alias app segment is replaced by
114+
* the package's. Like `AppContent`, it is the PARENT of the layout that hosts
115+
* the drawer, so its mount effect runs after the host's first one.
116+
*/
117+
function AliasRedirect({ children }: { children: React.ReactNode }) {
118+
const { app } = useParams();
119+
const location = useLocation();
120+
const navigate = useNavigate();
121+
React.useEffect(() => {
122+
if (app !== 'crm-alias') return;
123+
navigate(
124+
{ pathname: location.pathname.replace('/apps/crm-alias/', '/apps/crm/'), search: location.search },
125+
{ replace: true, state: location.state },
126+
);
127+
}, [app, location, navigate]);
128+
return <>{children}</>;
129+
}
130+
131+
function mount(entries: string[] = [HOME]) {
132+
return render(
133+
<MemoryRouter initialEntries={entries} initialIndex={entries.length - 1}>
134+
<Host />
135+
</MemoryRouter>,
136+
);
137+
}
138+
139+
// Home and an app are two layouts, each hosting its own drawer: a chip on Home
140+
// that opens an app's record unmounts one host and mounts another.
141+
function mountTwoLayouts() {
142+
return render(
143+
<MemoryRouter initialEntries={[HOME]}>
144+
<Routes>
145+
<Route path="/home" element={<Host key="home-layout" />} />
146+
<Route
147+
path="/apps/:app/*"
148+
element={
149+
<AliasRedirect key="app-layout">
150+
<Host />
151+
</AliasRedirect>
152+
}
153+
/>
154+
</Routes>
155+
</MemoryRouter>,
156+
);
157+
}
158+
159+
const click = (id: string) => act(() => fireEvent.click(screen.getByTestId(id)));
160+
const sheet = () => screen.getByTestId('chat-dock-mobile-sheet');
161+
162+
const realSessionStorage = Object.getOwnPropertyDescriptor(window, 'sessionStorage')!;
163+
164+
afterEach(() => {
165+
cleanup();
166+
settleLate = false;
167+
Object.defineProperty(window, 'sessionStorage', realSessionStorage);
168+
window.sessionStorage.clear();
169+
setWidth(1024);
170+
});
171+
172+
describe('a chat navigation closes the phone sheet, not the desktop rail (objectstack#37556)', () => {
173+
it('a chip click on a phone closes the sheet, and reopening shows the same conversation', () => {
174+
setWidth(375);
175+
mount();
176+
click('open-dock');
177+
expect(sheet()).toHaveAttribute('data-open', 'true');
178+
expect(sheet()).toHaveAttribute('data-conversation', 'conv-1');
179+
180+
click('chip');
181+
expect(screen.getByTestId('location')).toHaveTextContent(CITED);
182+
expect(sheet()).toHaveAttribute('data-open', 'false');
183+
184+
click('reopen-dock');
185+
expect(sheet()).toHaveAttribute('data-open', 'true');
186+
expect(sheet()).toHaveAttribute('data-conversation', 'conv-1');
187+
});
188+
189+
it('clicking the same chip again (same URL, a PUSH) closes the reopened sheet again', () => {
190+
setWidth(375);
191+
mount([CITED]);
192+
click('open-dock');
193+
expect(sheet()).toHaveAttribute('data-open', 'true');
194+
195+
click('chip');
196+
expect(screen.getByTestId('location')).toHaveTextContent(CITED);
197+
expect(sheet()).toHaveAttribute('data-open', 'false');
198+
});
199+
200+
it('Back (a POP) away from the page the sheet was shown on closes it', () => {
201+
setWidth(375);
202+
mount([HOME, CITED]);
203+
click('open-dock');
204+
expect(sheet()).toHaveAttribute('data-open', 'true');
205+
206+
click('back');
207+
expect(screen.getByTestId('location')).toHaveTextContent(HOME);
208+
expect(sheet()).toHaveAttribute('data-open', 'false');
209+
});
210+
211+
it('a chip that leaves Home for an app (another layout, another host) closes the sheet too', () => {
212+
setWidth(375);
213+
mountTwoLayouts();
214+
click('open-dock');
215+
expect(sheet()).toHaveAttribute('data-open', 'true');
216+
217+
click('chip');
218+
expect(screen.getByTestId('location')).toHaveTextContent(CITED);
219+
expect(sheet()).toHaveAttribute('data-open', 'false');
220+
221+
click('reopen-dock');
222+
expect(sheet()).toHaveAttribute('data-open', 'true');
223+
expect(sheet()).toHaveAttribute('data-conversation', 'conv-1');
224+
});
225+
226+
it("…and so does one naming the app by an alias, whose landing REPLACEs its address while the new host's phone flag is unsettled", async () => {
227+
setWidth(375);
228+
mountTwoLayouts();
229+
click('open-dock');
230+
expect(sheet()).toHaveAttribute('data-open', 'true');
231+
232+
settleLate = true;
233+
click('chip-by-alias');
234+
expect(screen.getByTestId('location')).toHaveTextContent(CITED);
235+
// The REPLACE has landed and the new host still reads "not a phone".
236+
expect(screen.queryByTestId('chat-dock-mobile-sheet')).not.toBeInTheDocument();
237+
await act(async () => {
238+
await new Promise((resolve) => setTimeout(resolve, 0));
239+
});
240+
expect(sheet()).toHaveAttribute('data-open', 'false');
241+
});
242+
243+
// Across layouts the drawer's own open state does not survive without
244+
// storage either, so the case that pins the in-memory copy is the same host.
245+
it('with sessionStorage throwing, a chip click still closes the sheet', () => {
246+
// Private mode in some browsers: reading `window.sessionStorage` throws.
247+
Object.defineProperty(window, 'sessionStorage', {
248+
configurable: true,
249+
get() {
250+
throw new DOMException('denied', 'SecurityError');
251+
},
252+
});
253+
setWidth(375);
254+
mount();
255+
click('open-dock');
256+
expect(sheet()).toHaveAttribute('data-open', 'true');
257+
258+
click('chip');
259+
expect(screen.getByTestId('location')).toHaveTextContent(CITED);
260+
expect(sheet()).toHaveAttribute('data-open', 'false');
261+
});
262+
263+
it('a REPLACE that keeps the page (the handoff hand-over) leaves the sheet open', () => {
264+
setWidth(375);
265+
mount();
266+
click('open-dock');
267+
click('replace-same-page');
268+
expect(sheet()).toHaveAttribute('data-open', 'true');
269+
});
270+
271+
it('turning a tablet to landscape and back does not close the drawer on the turn', () => {
272+
setWidth(375);
273+
mount();
274+
click('open-dock');
275+
expect(sheet()).toHaveAttribute('data-open', 'true');
276+
277+
resize(1024);
278+
expect(screen.getByTestId('chat-dock-panel')).toBeInTheDocument();
279+
click('chip');
280+
expect(screen.getByTestId('chat-dock-panel')).toBeInTheDocument();
281+
282+
resize(375);
283+
expect(sheet()).toHaveAttribute('data-open', 'true');
284+
});
285+
286+
it('control: on a desktop the rail stays open after the same chip click', () => {
287+
setWidth(1024);
288+
mount();
289+
click('open-dock');
290+
expect(screen.getByTestId('chat-dock-panel')).toBeInTheDocument();
291+
292+
click('chip');
293+
expect(screen.getByTestId('location')).toHaveTextContent(CITED);
294+
expect(screen.getByTestId('chat-dock-panel')).toBeInTheDocument();
295+
expect(screen.queryByTestId('chat-dock-mobile-sheet')).not.toBeInTheDocument();
296+
});
297+
});

0 commit comments

Comments
 (0)