diff --git a/services/platform/app/features/tasks/components/task-comments.tsx b/services/platform/app/features/tasks/components/task-comments.tsx index c12128b336..9d37595a43 100644 --- a/services/platform/app/features/tasks/components/task-comments.tsx +++ b/services/platform/app/features/tasks/components/task-comments.tsx @@ -34,6 +34,7 @@ import { withTaskActorDirectory, } from '../hooks/task-actor-directory-context'; import { taskCommentDraftKey } from '../lib/draft-key'; +import { LAZY_COMMENT_LAYOUT } from '../lib/lazy-layout'; import { pickCommentBody, type CommentBodyByLocale, @@ -177,13 +178,10 @@ function TaskCommentViewContent({ variant={own && !editing ? 'own' : 'other'} continuation={continuation} // Keep offscreen history in the DOM for browser find, keyboard access - // and draft state, while letting the browser skip its layout/paint. - // Editing needs normal layout so its mention menu may overflow the row. - className={cn( - 'group/comment', - !editing && - '[contain-intrinsic-block-size:auto_8rem] [content-visibility:auto]', - )} + // and draft state, while letting the browser skip its layout/paint + // where it anchors scrolling. Editing needs normal layout so its + // mention menu may overflow the row. + className={cn('group/comment', !editing && LAZY_COMMENT_LAYOUT)} avatar={ { + if (property.includes('overflow-anchor')) return false; + return value === undefined + ? supports(property) + : supports(property, value); + }, + ); + } const rendered = render( -
-
-
Task brief
- -
+
+ Task brief
} + conversation={ + + } + {...(safari ? { scrollerClassName: '[overflow-anchor:none]' } : {})} + />
, ); 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"]'); @@ -160,39 +180,37 @@ beforeEach(async () => { }); afterEach(() => { cleanup(); + vi.restoreAllMocks(); localStorage.removeItem('user-locale'); }); 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 +237,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 +267,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,12 +289,15 @@ 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'); + it.each([ + { browser: 'a browser that anchors scrolling', safari: false }, + { browser: 'Safari', safari: true }, + ])( + 'loads earlier comments from the keyboard without moving the read comment, in $browser', + async ({ safari }) => { + const { scroller } = renderHistory({ safari }); await settledLayout(); - scroller.scrollTop = direction === 'reverse' ? -scroller.scrollHeight : 0; + scroller.scrollTop = 0; await settledLayout(); const earlier = screen.getByRole('button', { name: 'Show earlier comments', @@ -309,7 +330,9 @@ describe('TaskConversation long history (Chromium)', () => { ); 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..a62283ca03 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 { useEffect, 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,37 @@ function Thread({ rows }: { rows: number }) { ); } +/** A thread that grows by five comments, and a composer that grows to six + * times its height and shrinks back, 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={ +