Files
PaperClipAI/ui/src/components/Layout.viewport.test.tsx
T
commitperclip[bot] 47ce5459c9 fix: Keep tablet task composers above the keyboard and release sizing during pinch zoom (#19725)
> [!NOTE]
> Opened by Prospector's automated issue-fix pipeline. A maintainer
reviews and decides; nothing here merges on its own.

> [!WARNING]
> This change crosses a trust boundary. See Risks.

## Thinking Path

- Issue #17866 reports a defect in paperclipai/paperclip.
- Root cause, as the fixing agent read it: Viewport observation and
conversation sizing were tied to the mobile navigation breakpoint. The
earlier attempt also retained keyboard state during zoom and excluded
classic task threads from keyboard sizing.
- This pull request: Keep tablet task composers above the keyboard and
release sizing during pinch zoom

## What Changed

- `ui/src/components/Layout.tsx`: Retain viewport observation
independent of navigation width.
- `ui/src/components/Layout.production.tsx`: Apply the same viewport
observation to the production layout.
- `ui/src/hooks/useMobileVisualViewport.ts`: Clear keyboard state during
pinch zoom and handle Safari document panning for classic conversation
shells.
- `ui/src/pages/IssueDetail.tsx`: Mark desktop-width classic chat pages
for keyboard sizing while preserving phone layouts and other tabs.
- `ui/src/index.css`: Constrain classic conversation shells during
keyboard display, retain main-content scrolling, and keep their sticky
composer inside the visible area.
- `ui/src/hooks/useMobileVisualViewport.test.tsx`: Reproduce stale
keyboard state after zoom and verify recovery.
- `ui/src/components/Layout.viewport.test.tsx`: Cover both layouts, both
conversation shells, zoom recovery, and document pan correction.
- `ui/src/pages/IssueDetail.test.tsx`: Verify classic sizing eligibility
at desktop and phone widths. Regression tests, existing thread tests,
and typecheck passed.

## Verification

- Reproducing test(s), added in this PR:
`ui/src/hooks/useMobileVisualViewport.test.tsx`,
`ui/src/pages/IssueDetail.test.tsx`,
`ui/src/components/Layout.viewport.test.tsx`,
`ui/src/components/Layout.test.tsx`
- They fail on the base commit and pass with the fix, each twice in a
fresh sandbox.
- 3 independent attempts wrote 3 reproductions; this fix passes every
one of them.
- The repository's compile command passes with the fix applied.
- 10 existing test file(s) near the change passed.
- The full test suite passes except for the 15 file(s) that already fail
on the base commit.
- Revised in 1 round(s) of automated code review.

## Risks

- Written by an automated pipeline, not a person: review it as you would
an outside contribution.
- Risk tier of the touched paths: 3.
- The scope reviewer found it also changes, beyond the report: Enabled
hook callers entering zoom after keyboard detection: both Layout
variants, hook test hosts, and task-chat-mobile-follow Storybook
- The scope reviewer found it also changes, beyond the report: Missing
visualViewport or shell; disabled hook; zero, negative, non-finite, or
missing viewport height; missing or malformed scale
- It crosses a trust boundary. Check each crossing against what the
issue asked for, and against who asked:
- validation (ui/src/components/Layout.tsx:155): Passing true removes
the mobile-width eligibility check for viewport keyboard handling.
- validation (ui/src/components/Layout.production.tsx:182): Passing true
removes the mobile-width eligibility check in the production layout.
- validation (ui/src/hooks/useMobileVisualViewport.ts:12, not asked for
by the report): The scroll-reset guard now accepts classic task shells
as well as task-chat shells.

## Model Used

- codex:gpt-6.1-sol, opus, sonnet (Anthropic Claude, via Claude Code;
OpenAI, via the Codex CLI), writing and checking the change in an
isolated sandbox.
- opus (Anthropic Claude, via Claude Code), reviewing it independently.

## Linked Issues

Fixes #17866

A search of paperclipai/paperclip's open and closed pull requests found
no other pull request that names #17866.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [ ] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with 'Fixes: #' / 'Closes
#' / 'Refs #' OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub '#NNN' / 'github.com/paperclipai/paperclip'
URLs)
- [ ] My branch name describes the change (e.g. 'docs/...', 'fix/...')
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [ ] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [ ] I will address all Greptile and reviewer comments before
requesting merge

<!-- prospector:issue-fix v1 issue=17866 base=f8cb4957dcd9
report=8607f5fafe77c2be -->

Co-authored-by: commitperclip[bot] <284812584+commitperclip[bot]@users.noreply.github.com>
2026-11-13 12:57:20 -06:00

89 lines
5.8 KiB
TypeScript

// @vitest-environment jsdom
import { act } from "react";
import { createRoot } from "react-dom/client";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { expect, it, vi } from "vitest";
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { Layout } from "./Layout";
import { Layout as ProductionLayout } from "./Layout.production";
vi.mock("@/hooks/useCoordinatorWorkspaceEnabled", () => ({ useCoordinatorWorkspaceEnabled: () => ({ enabled: false, loaded: true }) }));
vi.mock("@/context/DesignSandboxContext", () => ({ useDesignSandbox: () => false }));
vi.mock("@/lib/router", () => ({
Outlet: () => <div data-task-chat-shell="" />,
useLocation: () => ({ pathname: "/PAP/issues/PAP-1", search: "", hash: "", state: null }),
useNavigate: () => vi.fn(), useNavigationType: () => "PUSH", useParams: () => ({ companyPrefix: "PAP" }),
}));
vi.mock("./Sidebar", () => ({ Sidebar: () => null }));
vi.mock("./Sidebar.production", () => ({ Sidebar: () => null }));
vi.mock("./BreadcrumbBar", () => ({ BreadcrumbBar: () => null }));
vi.mock("./BreadcrumbBar.production", () => ({ BreadcrumbBar: () => null }));
vi.mock("./PropertiesPanel", () => ({ PropertiesPanel: () => null }));
vi.mock("./PluginAppShellOverlays", () => ({ PluginAppShellOverlays: () => null }));
vi.mock("./CommandPalette", () => ({ CommandPalette: () => null }));
vi.mock("./BoardDialogs", () => ({ BoardDialogs: () => null }));
vi.mock("./KeyboardShortcutsCheatsheet", () => ({ KeyboardShortcutsCheatsheet: () => null }));
vi.mock("./ToastViewport", () => ({ ToastViewport: () => null }));
vi.mock("./AnnouncementWell", () => ({ AnnouncementWell: () => null }));
vi.mock("./MobileBottomNav", () => ({ MobileBottomNav: () => null }));
vi.mock("./WorktreeBanner", () => ({ WorktreeBanner: () => null }));
vi.mock("./DevRestartBanner", () => ({ DevRestartBanner: () => null }));
vi.mock("./SidebarAccountMenu", () => ({ SidebarAccountMenu: () => null }));
vi.mock("./SidebarAccountMenu.production", () => ({ SidebarAccountMenu: () => null }));
vi.mock("../context/DialogContext", () => ({ useDialogActions: () => ({ openNewIssue: vi.fn(), openOnboarding: vi.fn() }) }));
vi.mock("../context/PanelContext", () => ({ usePanel: () => ({ togglePanelVisible: vi.fn(), setPanelVisible: vi.fn() }) }));
vi.mock("../context/CompanyContext", () => ({ useCompany: () => ({
companies: [{ id: "company-1", issuePrefix: "PAP" }], selectedCompany: { id: "company-1", issuePrefix: "PAP" },
selectedCompanyId: "company-1", loading: false, setSelectedCompanyId: vi.fn(),
}) }));
vi.mock("../context/SidebarContext", () => ({ useSidebar: () => ({
isMobile: false, sidebarOpen: true, collapsed: false, peeking: false,
setSidebarOpen: vi.fn(), setPeeking: vi.fn(), setForceCollapsed: vi.fn(), setRouteRequestsCollapsed: vi.fn(),
}) }));
vi.mock("../hooks/useKeyboardShortcuts", () => ({ useKeyboardShortcuts: () => undefined }));
vi.mock("../hooks/useCompanyPageMemory", () => ({ useCompanyPageMemory: () => undefined }));
vi.mock("../api/health", () => ({ healthApi: { get: async () => ({ status: "ok" }) } }));
vi.mock("../api/instanceSettings", () => ({ instanceSettingsApi: { getGeneral: async () => ({}), getExperimental: async () => ({}) } }));
vi.mock("../lib/company-selection", () => ({ shouldSyncCompanySelectionFromRoute: () => false, resolveArchivedCompanyBounce: () => null }));
vi.mock("../lib/main-content-focus", () => ({ scheduleMainContentFocus: () => () => undefined }));
vi.mock("../plugins/slots", () => ({ usePluginSlots: () => ({ slots: [] }), resolveRouteSidebarSlot: () => null, PluginSlotMount: () => null }));
it.each([["standard", Layout], ["production", ProductionLayout]] as const)("sizes desktop-width conversations above the keyboard in %s", async (_, Shell) => {
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
const viewport = Object.assign(new EventTarget(), { height: 1024, scale: 1 });
vi.stubGlobal("visualViewport", viewport);
vi.stubGlobal("innerWidth", 1366);
Object.defineProperty(document.documentElement, "clientHeight", { configurable: true, value: 1024 });
const container = document.createElement("div");
document.body.append(container);
const root = createRoot(container);
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
try {
await act(async () => root.render(<QueryClientProvider client={queryClient}><Shell /></QueryClientProvider>));
const shell = container.querySelector<HTMLElement>(".paperclip-app-shell")!;
const conversation = shell.querySelector<HTMLElement>("[data-task-chat-shell]")!;
await act(async () => { viewport.height = 600; viewport.dispatchEvent(new Event("resize")); });
expect(shell.dataset.mobile).toBeUndefined();
expect(shell.dataset.keyboardOpen).toBe("true");
expect(shell.style.getPropertyValue("--mobile-chat-viewport-height")).toBe("600px");
const stylesheet = readFileSync(resolve("ui/src/index.css"), "utf8");
const sizingRule = stylesheet.match(/([^{}]+)\{[^{}]*height: var\(--mobile-chat-viewport-height\);[^{}]*\}/)!;
expect(shell.matches(sizingRule[1].trim())).toBe(true);
conversation.remove();
expect(shell.matches(sizingRule[1].trim())).toBe(false);
shell.append(conversation);
await act(async () => { viewport.scale = 2; viewport.height = 300; viewport.dispatchEvent(new Event("resize")); });
expect(shell.style.getPropertyValue("--mobile-chat-viewport-height")).toBe("600px");
await act(async () => { viewport.scale = 1; viewport.height = 1024; viewport.dispatchEvent(new Event("resize")); });
expect(shell.dataset.keyboardOpen).toBeUndefined();
expect(shell.matches(sizingRule[1].trim())).toBe(false);
} finally {
await act(async () => root.unmount());
queryClient.clear();
container.remove();
Reflect.deleteProperty(document.documentElement, "clientHeight");
vi.unstubAllGlobals();
}
});