From 3de571a4199dd5d5484f6c8956b9e12f0735be4a Mon Sep 17 00:00:00 2001 From: yannickmonney Date: Mon, 12 Oct 2026 17:33:56 +0200 Subject: [PATCH 1/5] fix(platform): scroll a task's thread by trackpad in the board dialog The board's task dialog locks the page's scroll, and the lock cancels an upward wheel or touch unless the scrollport under it has room above: it reads `scrollTop` above 0 as room. The thread column was a `column-reverse` scrollport, which rests at `scrollTop` 0 and scrolls into negative offsets, so every upward gesture over the thread was cancelled. The lock only intercepts wheel and touch events, so a trackpad could not scroll the open task at all. The column is an ordinary scrollport now, held on its newest end by `useThreadScroll`: it opens there, follows the thread and its own box while the reader is at the end, and leaves a reader who scrolled up where they are. Safari has no scroll anchoring, which the reversed scrollport made unnecessary by growing upward, so there the hook also moves the scrollport by how far a row above the reader changed height (a row skipped by `content-visibility` is drawn at its real height as it nears). It stands down while a history load holds the place itself. Tests drive a real wheel in a dialog hosted like the board's, and the column's follow, hold and place-holding rules, in real Chromium. The history tests now read the conversation in the real column. --- .../task-conversation.browser.test.tsx | 170 +++++------ .../task-thread-column.browser.test.tsx | 282 +++++++++++++++++- .../tasks/components/task-thread-column.tsx | 20 +- .../tasks/hooks/use-task-history-anchor.ts | 18 +- .../features/tasks/hooks/use-thread-scroll.ts | 150 ++++++++++ .../manual/reference/automation/tasks.md | 1 + .../platform/tests/manual/suites/tasks.md | 10 + 7 files changed, 547 insertions(+), 104 deletions(-) create mode 100644 services/platform/app/features/tasks/hooks/use-thread-scroll.ts diff --git a/services/platform/app/features/tasks/components/task-conversation.browser.test.tsx b/services/platform/app/features/tasks/components/task-conversation.browser.test.tsx index 0c5f017450..6fcf7647d8 100644 --- a/services/platform/app/features/tasks/components/task-conversation.browser.test.tsx +++ b/services/platform/app/features/tasks/components/task-conversation.browser.test.tsx @@ -8,6 +8,7 @@ import { act, cleanup, render, screen, waitFor } from '@/tests/utils/render'; import type { TaskCommentData } from './task-comments'; import { TaskConversation } from './task-conversation'; +import { TaskThreadColumn } from './task-thread-column'; import '@/app/globals.css'; @@ -109,30 +110,35 @@ vi.mock( }), ); -function renderHistory(reverse = true) { +/** The history in the column a task is read in, on the page and in the dialog. */ +function renderHistory() { const rendered = render( -
-
-
Task brief
- -
+
+ Task brief
} + conversation={ + + } + />
, ); return { ...rendered, - scroller: screen.getByTestId('task-history-scroll'), + scroller: screen.getByTestId('task-thread-scrollport'), }; } +/** How far the reader is from the newest end of a scrollport. */ +function distanceToEnd(scroller: HTMLElement) { + return scroller.scrollHeight - scroller.clientHeight - scroller.scrollTop; +} + function commentRow(index: number) { const paragraph = screen.getByText(`Report ${index}`); const row = paragraph.closest('[class~="group/comment"]'); @@ -164,35 +170,32 @@ afterEach(() => { }); describe('TaskConversation long history (Chromium)', () => { - it.each([false, true])( - 'keeps the earlier-history button focused through a pending page and blocks repeat activation (reverse scrollport: %s)', - async (reverse) => { - const pending = Promise.withResolvers(); - reads.pendingPage = pending.promise; - renderHistory(reverse); - const earlier = screen.getByRole('button', { - name: 'Show earlier comments', - }); - earlier.focus(); - await userEvent.keyboard('{Enter}'); - await waitFor(() => expect(earlier).toHaveAttribute('aria-busy', 'true')); - expect(earlier).toHaveFocus(); - await userEvent.keyboard('{Enter}'); - // Browser automation treats aria-disabled as inert before dispatch; - // the native click proves our handler also rejects activation itself. - earlier.click(); - expect(reads.pageRequests).toHaveBeenCalledTimes(1); - await act(async () => { - pending.resolve(); - await pending.promise; - }); - await waitFor(() => expect(earlier).not.toHaveAttribute('aria-busy')); - expect(earlier).toHaveFocus(); - await waitFor(() => - expect(screen.getByText('Report 99')).toBeInTheDocument(), - ); - }, - ); + it('keeps the earlier-history button focused through a pending page and blocks repeat activation', async () => { + const pending = Promise.withResolvers(); + reads.pendingPage = pending.promise; + renderHistory(); + const earlier = screen.getByRole('button', { + name: 'Show earlier comments', + }); + earlier.focus(); + await userEvent.keyboard('{Enter}'); + await waitFor(() => expect(earlier).toHaveAttribute('aria-busy', 'true')); + expect(earlier).toHaveFocus(); + await userEvent.keyboard('{Enter}'); + // Browser automation treats aria-disabled as inert before dispatch; + // the native click proves our handler also rejects activation itself. + earlier.click(); + expect(reads.pageRequests).toHaveBeenCalledTimes(1); + await act(async () => { + pending.resolve(); + await pending.promise; + }); + await waitFor(() => expect(earlier).not.toHaveAttribute('aria-busy')); + expect(earlier).toHaveFocus(); + await waitFor(() => + expect(screen.getByText('Report 99')).toBeInTheDocument(), + ); + }); it('skips offscreen layout while preserving newest anchoring and added-page parse bounds', async () => { const { container, scroller } = renderHistory(); await settledLayout(); @@ -219,14 +222,14 @@ describe('TaskConversation long history (Chromium)', () => { expect(reads.directory).toHaveBeenCalledTimes(1); expect(reads.editMutation).not.toHaveBeenCalled(); expect(reads.markdown).toHaveBeenCalledTimes(600); - expect(scroller.scrollTop).toBe(0); + expect(distanceToEnd(scroller)).toBeLessThan(2); act(() => reads.loadEarlier()); await settledLayout(); expect(reads.markdown).toHaveBeenCalledTimes(1200); expect(reads.directory).toHaveBeenCalledTimes(1); expect(newest.getBoundingClientRect().top).toBeCloseTo(before, 0); - expect(scroller.scrollTop).toBe(0); + expect(distanceToEnd(scroller)).toBeLessThan(2); const region = screen.getByRole('region'); expect(region.textContent?.indexOf('Report 99')).toBeLessThan( region.textContent?.indexOf('Report 0') ?? 0, @@ -249,7 +252,7 @@ describe('TaskConversation long history (Chromium)', () => { await userEvent.fill(field, 'Keep this unfinished review'); expect(getComputedStyle(newest).contentVisibility).toBe('visible'); - scroller.scrollTop = -scroller.scrollHeight; + scroller.scrollTop = 0; await settledLayout(); act(() => reads.loadEarlier()); await settledLayout(); @@ -271,45 +274,44 @@ describe('TaskConversation long history (Chromium)', () => { ); }); - it.each(['reverse', 'forward'])( - 'loads earlier comments from the keyboard without moving the read comment in the %s scrollport', - async (direction) => { - const { scroller } = renderHistory(direction === 'reverse'); - await settledLayout(); - scroller.scrollTop = direction === 'reverse' ? -scroller.scrollHeight : 0; - await settledLayout(); - const earlier = screen.getByRole('button', { - name: 'Show earlier comments', - }); - earlier.focus(); - await settledLayout(); - const oldest = commentRow(49); - await Promise.all( - oldest.parentElement - ?.getAnimations() - .map((animation) => animation.finished) ?? [], - ); - const before = oldest.getBoundingClientRect().top; - const parses = reads.markdown.mock.calls.length; + it('loads earlier comments from the keyboard without moving the read comment', async () => { + const { scroller } = renderHistory(); + await settledLayout(); + scroller.scrollTop = 0; + await settledLayout(); + const earlier = screen.getByRole('button', { + name: 'Show earlier comments', + }); + earlier.focus(); + await settledLayout(); + const oldest = commentRow(49); + await Promise.all( + oldest.parentElement + ?.getAnimations() + .map((animation) => animation.finished) ?? [], + ); + const before = oldest.getBoundingClientRect().top; + const parses = reads.markdown.mock.calls.length; - await userEvent.keyboard('{Enter}'); - await settledLayout(); - expect(earlier).toHaveFocus(); - expect(commentRow(49)).toBe(oldest); - await expect - .poll(() => oldest.getBoundingClientRect().top) - .toBeCloseTo(before, 0); - expect(reads.markdown).toHaveBeenCalledTimes(parses + 600); - const band = oldest.closest('ol')?.parentElement; - const divider = (day: Element | null | undefined) => - day?.querySelector('[data-slot="thread-day-divider"]')?.textContent; - expect(divider(band)).toContain('September 23'); - expect(divider(band?.previousElementSibling)).toContain('September 22'); - }, - ); + await userEvent.keyboard('{Enter}'); + await settledLayout(); + expect(earlier).toHaveFocus(); + expect(commentRow(49)).toBe(oldest); + await expect + .poll(() => oldest.getBoundingClientRect().top) + .toBeCloseTo(before, 0); + expect(reads.markdown).toHaveBeenCalledTimes(parses + 600); + const band = oldest.closest('ol')?.parentElement; + const divider = (day: Element | null | undefined) => + day?.querySelector('[data-slot="thread-day-divider"]')?.textContent; + expect(divider(band)).toContain('September 23'); + expect(divider(band?.previousElementSibling)).toContain('September 22'); + }); it('gives scroll control back immediately when the reader steers during anchor settling', async () => { - const { scroller } = renderHistory(false); + const { scroller } = renderHistory(); + await settledLayout(); + scroller.scrollTop = 0; await settledLayout(); const earlier = screen.getByRole('button', { name: 'Show earlier comments', diff --git a/services/platform/app/features/tasks/components/task-thread-column.browser.test.tsx b/services/platform/app/features/tasks/components/task-thread-column.browser.test.tsx index 23595712a5..f6b47866b9 100644 --- a/services/platform/app/features/tasks/components/task-thread-column.browser.test.tsx +++ b/services/platform/app/features/tasks/components/task-thread-column.browser.test.tsx @@ -1,15 +1,32 @@ import '@testing-library/jest-dom/vitest'; -import { afterEach, describe, expect, it } from 'vitest'; +import { + ResponsiveDialog, + ResponsiveDialogContent, + ResponsiveDialogDescription, + ResponsiveDialogTitle, +} from '@tale/ui/responsive-dialog'; +import { useState } from 'react'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { page, userEvent } from 'vitest/browser'; -import { cleanup, render, screen } from '@/tests/utils/render'; +import { cleanup, render, screen, waitFor } from '@/tests/utils/render'; +import { HELD_SCROLLPORTS } from '../hooks/use-task-history-anchor'; import { TaskThreadColumn } from './task-thread-column'; import '@/app/globals.css'; // Real-Chromium coverage for the column the task page and the board's dialog -// share: where it opens, and that the composer stays in view. -afterEach(cleanup); +// share: where it opens, that it stays on its newest end while the thread or +// its own box changes, that the composer stays in view, and that a wheel or a +// trackpad scrolls it wherever it is hosted. +beforeEach(async () => { + await page.viewport(1280, 800); +}); +afterEach(() => { + cleanup(); + vi.restoreAllMocks(); +}); function Thread({ rows }: { rows: number }) { return ( @@ -23,6 +40,36 @@ function Thread({ rows }: { rows: number }) { ); } +/** A thread that grows by five comments, and a composer that grows to six + * times its height, on the buttons above the column. */ +function Growing({ rows }: { rows: number }) { + const [count, setCount] = useState(rows); + const [composerHeight, setComposerHeight] = useState(40); + return ( +
+
+ + +
+
+ The brief

} + conversation={} + composer={ +