diff --git a/.changeset/37556-phone-dock-closes-on-citation.md b/.changeset/37556-phone-dock-closes-on-citation.md new file mode 100644 index 00000000000..d80988a2521 --- /dev/null +++ b/.changeset/37556-phone-dock-closes-on-citation.md @@ -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. diff --git a/ui/packages/app-shell/src/layout/__tests__/useConsoleChatDock.phoneCollapseOnNavigate-37556.test.tsx b/ui/packages/app-shell/src/layout/__tests__/useConsoleChatDock.phoneCollapseOnNavigate-37556.test.tsx new file mode 100644 index 00000000000..9f7044affb0 --- /dev/null +++ b/ui/packages/app-shell/src/layout/__tests__/useConsoleChatDock.phoneCollapseOnNavigate-37556.test.tsx @@ -0,0 +1,297 @@ +// 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. `useIsMobile` is a stand-in with the real hook's timing: `false` on + * a host's first render, the window's width from its mount effect on, and + * again on every resize. 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 } from 'vitest'; +import React from 'react'; +import { render, screen, fireEvent, cleanup, act } from '@testing-library/react'; +import { MemoryRouter, Route, Routes, useLocation, useNavigate, useParams } from 'react-router-dom'; + +// `settleLate` holds a newly mounted host's first measurement back one task, +// so a REPLACE its page makes on mount lands while the flag still reads +// `false`: the order the console can take, pinned here deterministically. +let settleLate = false; +vi.mock('@object-ui/components', async (importOriginal) => { + const R = await import('react'); + return { + ...(await importOriginal>()), + useIsMobile: () => { + const [mobile, setMobile] = R.useState(undefined); + R.useEffect(() => { + const measure = () => setMobile(window.innerWidth < 768); + const late = settleLate ? setTimeout(measure, 0) : undefined; + if (!settleLate) measure(); + window.addEventListener('resize', measure); + return () => { + clearTimeout(late); + window.removeEventListener('resize', measure); + }; + }, []); + return !!mobile; + }, + }; +}); + +vi.mock('../ChatDock', async (importOriginal) => ({ + ...(await importOriginal>()), + ChatDockPanel: () =>