Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/37556-phone-dock-closes-on-citation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@object-ui/app-shell': patch
---

fix(console): on a phone, a page the AI assistant opens closes the assistant sheet so the page shows

Clause-②: no
Metadata-protocol: none

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* objectstack#37556 — on a phone the assistant drawer is a bottom sheet over
* the page. A citation chip in it navigates to the cited record section, and
* the sheet must get out of the way so the marked heading is visible; on a
* desktop the drawer is a rail beside the page and stays open.
*
* ## Real subjects
*
* The real `useConsoleChatDock` host, the real `useChatDockState`, the real
* router. The sheet and the rail are stand-ins that show whether the host
* mounts them open: which chrome is open is the subject, not the chat inside.
* The chip is a stand-in that navigates the way the chat's record-citation
* door does (a PUSH to the record route with fresh router state).
*/

import '@testing-library/jest-dom/vitest';
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
import React from 'react';
import { render, screen, fireEvent, cleanup, act } from '@testing-library/react';
import { MemoryRouter, Route, Routes, useLocation, useNavigate } from 'react-router-dom';

let mobile = true;
vi.mock('@object-ui/components', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useIsMobile: () => mobile,
}));

vi.mock('../ChatDock', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
ChatDockPanel: () => <aside data-testid="chat-dock-panel" />,
ChatDockMobileSheet: ({ open, target }: { open: boolean; target?: { conversationId?: string } }) => (
<div
data-testid="chat-dock-mobile-sheet"
data-open={String(open)}
data-conversation={target?.conversationId ?? ''}
/>
),
}));

import { useConsoleChatDock } from '../useConsoleChatDock';

const HOME = '/apps/crm';
const CITED = '/apps/crm/account/record/a1?section=pricing';

function Host() {
const { control, rail, sheet } = useConsoleChatDock({ enabled: true, appPackageId: 'crm' });
const navigate = useNavigate();
const location = useLocation();
return (
<>
<button
data-testid="open-dock"
onClick={() => control?.open({ conversationId: 'conv-1' })}
/>
{/* The robot: opens the drawer on whatever it shows, naming no target. */}
<button data-testid="reopen-dock" onClick={() => control?.open()} />
<button
data-testid="chip"
onClick={() => navigate(CITED, { state: { opened: Math.random() } })}
/>
<button
data-testid="replace-same-page"
onClick={() =>
navigate({ pathname: location.pathname, search: location.search }, { replace: true, state: null })
}
/>
<output data-testid="location">{`${location.pathname}${location.search}`}</output>
{rail}
{sheet}
</>
);
}

function mount(at = HOME) {
return render(
<MemoryRouter initialEntries={[at]}>
<Host />
</MemoryRouter>,
);
}

// Home and an app are two layouts, each hosting its own drawer: a chip on Home
// that opens an app's record unmounts one host and mounts another.
function mountTwoLayouts() {
return render(
<MemoryRouter initialEntries={['/home']}>
<Routes>
<Route path="/home" element={<Host key="home-layout" />} />
<Route path="/apps/*" element={<Host key="app-layout" />} />
</Routes>
</MemoryRouter>,
);
}

const click = (id: string) => act(() => fireEvent.click(screen.getByTestId(id)));

beforeEach(() => {
mobile = true;
});

afterEach(() => {
cleanup();
window.sessionStorage.clear();
});

describe('a chat navigation closes the phone sheet, not the desktop rail (objectstack#37556)', () => {
it('a chip click on a phone closes the sheet, and reopening shows the same conversation', () => {
mount();
click('open-dock');
const sheet = () => screen.getByTestId('chat-dock-mobile-sheet');
expect(sheet()).toHaveAttribute('data-open', 'true');
expect(sheet()).toHaveAttribute('data-conversation', 'conv-1');

click('chip');
expect(screen.getByTestId('location')).toHaveTextContent(CITED);
expect(sheet()).toHaveAttribute('data-open', 'false');

click('reopen-dock');
expect(sheet()).toHaveAttribute('data-open', 'true');
expect(sheet()).toHaveAttribute('data-conversation', 'conv-1');
});

it('clicking the same chip again (same URL, a PUSH) closes the reopened sheet again', () => {
mount(CITED);
click('open-dock');
expect(screen.getByTestId('chat-dock-mobile-sheet')).toHaveAttribute('data-open', 'true');

click('chip');
expect(screen.getByTestId('location')).toHaveTextContent(CITED);
expect(screen.getByTestId('chat-dock-mobile-sheet')).toHaveAttribute('data-open', 'false');
});

it('a chip that leaves Home for an app (another layout, another host) closes the sheet too', () => {
mountTwoLayouts();
click('open-dock');
expect(screen.getByTestId('chat-dock-mobile-sheet')).toHaveAttribute('data-open', 'true');

click('chip');
expect(screen.getByTestId('location')).toHaveTextContent(CITED);
expect(screen.getByTestId('chat-dock-mobile-sheet')).toHaveAttribute('data-open', 'false');

click('reopen-dock');
expect(screen.getByTestId('chat-dock-mobile-sheet')).toHaveAttribute('data-open', 'true');
expect(screen.getByTestId('chat-dock-mobile-sheet')).toHaveAttribute('data-conversation', 'conv-1');
});

it('a REPLACE that keeps the page (the handoff hand-over) leaves the sheet open', () => {
mount();
click('open-dock');
click('replace-same-page');
expect(screen.getByTestId('chat-dock-mobile-sheet')).toHaveAttribute('data-open', 'true');
});

it('control: on a desktop the rail stays open after the same chip click', () => {
mobile = false;
mount();
click('open-dock');
expect(screen.getByTestId('chat-dock-panel')).toBeInTheDocument();

click('chip');
expect(screen.getByTestId('location')).toHaveTextContent(CITED);
expect(screen.getByTestId('chat-dock-panel')).toBeInTheDocument();
expect(screen.queryByTestId('chat-dock-mobile-sheet')).not.toBeInTheDocument();
});
});
56 changes: 54 additions & 2 deletions ui/packages/app-shell/src/layout/useConsoleChatDock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* load, so it imports no chat code (objectui#13410).
*/
import * as React from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { NavigationType, useLocation, useNavigate, useNavigationType } from 'react-router-dom';
import { useIsMobile } from '@object-ui/components';
import { useAssistant } from '../assistant/assistantBus.js';
import { useChatDockState, ChatDockPanel, ChatDockMobileSheet } from './ChatDock.js';
Expand Down Expand Up @@ -56,6 +56,31 @@ export interface ConsoleChatDock {
sheet: React.ReactNode;
}

/**
* objectstack#37556 — the history entry (`location.key`) the phone sheet was
* last shown open on, per tab (sessionStorage, like the drawer's own state).
* Absent while the sheet is closed. A private-mode storage failure just means
* a navigation that remounts the layout does not close the sheet.
*/
const DOCK_SHEET_SHOWN_AT_STORAGE_KEY = 'ai-chat-dock-sheet-shown-at';

function readSheetShownAt(): string | null {
try {
return window.sessionStorage.getItem(DOCK_SHEET_SHOWN_AT_STORAGE_KEY);
} catch {
return null;
}
}

function writeSheetShownAt(key: string | null): void {
try {
if (key === null) window.sessionStorage.removeItem(DOCK_SHEET_SHOWN_AT_STORAGE_KEY);
else window.sessionStorage.setItem(DOCK_SHEET_SHOWN_AT_STORAGE_KEY, key);
} catch {
/* private mode */
}
}

function hasHandoff(state: BuilderHandoffState | undefined): state is BuilderHandoffState {
return Boolean(state && (state.handoffPrompt || state.parentConversationId));
}
Expand Down Expand Up @@ -119,7 +144,7 @@ export function useConsoleChatDock({
}
}, []);

const { expand, toggle, fullWindow, setFullWindow, expanded } = dock;
const { expand, collapse, toggle, fullWindow, setFullWindow, expanded } = dock;
const open = React.useCallback(
(next?: ChatDockTarget | null, nextHandoff?: BuilderHandoffState) => {
if (next === null) setTarget(undefined);
Expand Down Expand Up @@ -154,6 +179,33 @@ export function useConsoleChatDock({
if (fullWindow) setFullWindow(false);
}, [page, fullWindow, setFullWindow]);

// objectstack#37556 — on a phone the drawer is a sheet over the page, so a
// page the chat opens (a citation chip's cited section, a record, a list)
// stays hidden under it. A PUSH or POP away from the history entry the sheet
// was shown on closes it, a PUSH onto the same URL included (clicking the
// same chip again opens its section again); the conversation is kept, so
// reopening shows it. A REPLACE (a page rewriting its own query, the handoff
// hand-over above, an old `/ai…` link landing with the drawer armed open)
// leaves it open. The entry is kept per tab, not in this hook: a chip that
// opens another app's record, or leaves Home for an app, mounts another
// layout, and this host with it. The desktop rail sits beside the page and
// stays as it is.
const navigationType = useNavigationType();
React.useEffect(() => {
if (!enabled || !isMobile) return;
if (!expanded) {
writeSheetShownAt(null);
return;
}
const shownAt = readSheetShownAt();
if (shownAt !== null && shownAt !== location.key && navigationType !== NavigationType.Replace) {
writeSheetShownAt(null);
collapse();
return;
}
writeSheetShownAt(location.key);
}, [enabled, isMobile, expanded, location.key, navigationType, collapse]);

// A designer surface can ask the assistant to open through the assistant bus
// (e.g. an "Ask AI" button).
const { openSeq } = useAssistant();
Expand Down
Loading