From e689243d9d0b0ff5d33bb75530497acaccab9137 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Thu, 1 Oct 2026 19:58:38 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=A2=20feat:=20Collapse=20Activity=20Fo?= =?UTF-8?q?lds=20From=20Their=20Rails=20(#16637)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🪢 feat: Collapse Activity Folds From Their Rails Hovering an open fold's rail lights the line and swaps the header's glyph for a collapse knob; clicking the rail collapses that fold and brings its header back into view. * fix: Stabilize Fold Rail Hover and Header Reveal * fix: Reserve the Chat Toolbar When Revealing Folds --------- Co-authored-by: Lia --- .../Messages/Content/ActivityPhaseGroup.tsx | 86 +++++++---- .../Chat/Messages/Content/ProgressText.tsx | 5 +- .../Chat/Messages/Content/ToolCallGroup.tsx | 73 +++++---- .../__tests__/ActivityPhaseGroup.test.tsx | 27 ++++ .../Content/__tests__/ToolCallGroup.test.tsx | 52 +++++++ .../Messages/Content/__tests__/rail.test.tsx | 130 ++++++++++++++++ .../components/Chat/Messages/Content/rail.tsx | 143 ++++++++++++++++++ .../components/Chat/Messages/Content/rows.ts | 16 +- e2e/specs/mock/activity-fold.spec.ts | 86 +++++++++++ 9 files changed, 551 insertions(+), 67 deletions(-) create mode 100644 client/src/components/Chat/Messages/Content/__tests__/rail.test.tsx create mode 100644 client/src/components/Chat/Messages/Content/rail.tsx diff --git a/client/src/components/Chat/Messages/Content/ActivityPhaseGroup.tsx b/client/src/components/Chat/Messages/Content/ActivityPhaseGroup.tsx index 014afa47a1..0962d5db9b 100644 --- a/client/src/components/Chat/Messages/Content/ActivityPhaseGroup.tsx +++ b/client/src/components/Chat/Messages/Content/ActivityPhaseGroup.tsx @@ -5,6 +5,7 @@ import { ContentTypes } from 'librechat-data-provider'; import { Check, Lightbulb, ChevronDown, TriangleAlert } from 'lucide-react'; import type { TAttachment, TMessageContentParts } from 'librechat-data-provider'; import type { CSSProperties, ReactNode } from 'react'; +import type { RailHover } from './rail'; import { useLocalize, useExpandCollapse, @@ -19,6 +20,7 @@ import { LIVE_ACTIVITY_THROTTLE_MS, LIVE_REASONING_HOLD_MS, } from './live'; +import { FoldRail, RailGlyph, FoldHeaderContext, revealFoldHeader, useRailHover } from './rail'; import { FailedRevealContext, FailedRevealPill, useFailedRevealTrigger } from './reveal'; import { FOLD_RAIL_CLASSES, ROW_GLYPH_SLOT, TOOL_ROW_CLASSES } from './rows'; import useSmoothStreaming from '~/hooks/Messages/useSmoothStreaming'; @@ -273,6 +275,7 @@ function LivePhaseHeader({ detailId, attachments, onAnnounce, + railHover, }: { parts: ReadonlyArray; animate: boolean; @@ -284,6 +287,7 @@ function LivePhaseHeader({ detailId: string; attachments?: TAttachment[]; onAnnounce: (text: string) => void; + railHover: RailHover; }) { const localize = useLocalize(); const mcpIconMap = useMCPIconMap(); @@ -359,28 +363,30 @@ function LivePhaseHeader({ return ( <> - {iconNames.length === 0 ? ( - /** A span that is only reasoning so far has no tool to show; it takes - * the glyph the reasoning row itself uses. */ - - ) : ( - - )} + + {iconNames.length === 0 ? ( + /** A span that is only reasoning so far has no tool to show; it takes + * the glyph the reasoning row itself uses. */ + + ) : ( + + )} + {/** The multiplier counts the line it is printed next to, so it travels * with that line instead of sitting out at the row's right edge beside * the chevron, where it read as a property of the row. `Create File ×2` @@ -586,6 +592,9 @@ export default function ActivityPhaseGroup({ const [isExpanded, setIsExpanded] = useState(foldsIn); const [isSettled, setIsSettled] = useState(!foldsIn); const rootRef = useRef(null); + const headerRef = useRef(null); + const railHover = useRailHover(); + const railScope = useMemo(() => ({ header: headerRef, expanded: isExpanded }), [isExpanded]); const panelId = useId(); const lineId = useId(); const comboId = useId(); @@ -664,6 +673,16 @@ export default function ActivityPhaseGroup({ setIsExpanded(!isExpanded); }, [mountBody, isExpanded, onExpansionChange]); + /** The rail stays drawn while the panel animates shut, so a second click on + * it must not reopen what the first one closed. */ + const handleRailCollapse = useCallback(() => { + if (!isExpanded) { + return; + } + revealFoldHeader(rootRef.current, headerRef.current); + handleToggle(); + }, [isExpanded, handleToggle]); + /** One click to the error from a closed card: open the card the way a * toggle would, then ask every failed row below to open its own panel. */ const handleRevealFailed = useCallback(() => { @@ -797,6 +816,7 @@ export default function ActivityPhaseGroup({ {announcement}
) : ( <> - {outcomeParts != null && !hasFailure ? ( - - ) : ( - - )} + + {outcomeParts != null && !hasFailure ? ( + + ) : ( + + )} + )} @@ -873,9 +896,12 @@ export default function ActivityPhaseGroup({ > {shouldRenderBody && (
- - {children} - + + + + {children} + +
)}
diff --git a/client/src/components/Chat/Messages/Content/ProgressText.tsx b/client/src/components/Chat/Messages/Content/ProgressText.tsx index fc93aed638..8f605a06b8 100644 --- a/client/src/components/Chat/Messages/Content/ProgressText.tsx +++ b/client/src/components/Chat/Messages/Content/ProgressText.tsx @@ -26,9 +26,10 @@ const contentClass = * sits under a header and in the gutter when it stands alone, so a failure * is findable by shape before its text is read. A pseudo-element rather than * a border: the row's content is absolutely positioned against the padding - * box, so a border would push it and change the row's geometry. */ + * box, so a border would push it and change the row's geometry. It lies over + * the rail's hit area, so it lets the pointer through to the rail. */ const failedStripeClass = - "before:absolute before:-left-3 before:top-0 before:h-full before:w-0.5 before:rounded-full before:bg-status-error before:content-['']"; + "before:pointer-events-none before:absolute before:-left-3 before:top-0 before:h-full before:w-0.5 before:rounded-full before:bg-status-error before:content-['']"; const Wrapper = ({ popover, diff --git a/client/src/components/Chat/Messages/Content/ToolCallGroup.tsx b/client/src/components/Chat/Messages/Content/ToolCallGroup.tsx index 5f85df97c1..f21405de25 100644 --- a/client/src/components/Chat/Messages/Content/ToolCallGroup.tsx +++ b/client/src/components/Chat/Messages/Content/ToolCallGroup.tsx @@ -21,6 +21,7 @@ import { useFailedRevealTrigger, } from './reveal'; import { useLocalize, useExpandCollapse, scheduleMessageContentLayoutReconcile } from '~/hooks'; +import { FoldRail, RailGlyph, FoldHeaderContext, revealFoldHeader, useRailHover } from './rail'; import { ASK_USER_QUESTION, getSubmittedAskAnswer } from '~/utils/approval'; import { ToolAuthWarning, ToolAuthWarningContext } from './auth'; import { useMCPIconMap, useMCPServerNames } from '~/hooks/MCP'; @@ -92,6 +93,9 @@ export default function ToolCallGroup({ const mcpIconMap = useMCPIconMap(); const mcpServerNames = useMCPServerNames(); const rootRef = useRef(null); + const headerRef = useRef(null); + const railHover = useRailHover(); + const phaseHeader = useContext(FoldHeaderContext); const cancelLayoutReconcileRef = useRef<(() => void) | null>(null); const retainedForPendingApprovalRef = useRef(false); @@ -346,6 +350,16 @@ export default function ToolCallGroup({ onExpansionChange?.({ isExpanded: nextExpanded, userOverride: true }); }, [isExpanded, onExpansionChange]); + /** The rail stays drawn while the panel animates shut, so a second click on + * it must not reopen what the first one closed. */ + const handleRailCollapse = useCallback(() => { + if (!isExpanded) { + return; + } + revealFoldHeader(rootRef.current, headerRef.current, phaseHeader?.header.current); + handleToggle(); + }, [isExpanded, handleToggle, phaseHeader]); + const handleToolExpand = useCallback(() => { setUserOverride(true); setShouldRenderBody(true); @@ -541,7 +555,7 @@ export default function ToolCallGroup({ return (
-
+
+ ); +} + +/** + * Collapsing from a rail far down a long fold would leave the reader below the + * point where the fold now ends, so its header comes back into view first. A + * pinned (sticky) header sits below its card's top; scrolling the card to the + * start puts the header where it will rest once the rows are gone. + */ +export function revealFoldHeader( + root: HTMLElement | null, + header: HTMLElement | null, + stickyHeader?: HTMLElement | null, +) { + if (root == null || header == null || typeof root.scrollIntoView !== 'function') { + return; + } + const pinned = root.getBoundingClientRect().top < header.getBoundingClientRect().top; + const target = pinned ? root : header; + const previousMargin = target.style.scrollMarginTop; + /** The host message's scroll margin reserves its overlaid chat toolbar. */ + const message = root.closest('.message-render'); + const hostMargin = + message == null ? 0 : parseFloat(getComputedStyle(message).scrollMarginTop) || 0; + const targetMargin = parseFloat(getComputedStyle(target).scrollMarginTop) || 0; + target.style.scrollMarginTop = `${Math.max( + targetMargin, + hostMargin + (stickyHeader?.getBoundingClientRect().height ?? 0), + )}px`; + try { + target.scrollIntoView({ block: pinned ? 'start' : 'nearest', behavior: 'instant' }); + } finally { + target.style.scrollMarginTop = previousMargin; + } +} diff --git a/client/src/components/Chat/Messages/Content/rows.ts b/client/src/components/Chat/Messages/Content/rows.ts index dab9bf588f..ae9acb48b1 100644 --- a/client/src/components/Chat/Messages/Content/rows.ts +++ b/client/src/components/Chat/Messages/Content/rows.ts @@ -21,13 +21,11 @@ export const ROW_GLYPH_SLOT = 'flex h-5 min-w-6 shrink-0 items-center justify-ce /** * The panel under an open header: its rows step in by one glyph slot and a - * hairline hangs from the header's glyph down their left, so what is under the - * header reads as under it. Carried by the panel's clipping wrapper, the one - * `overflow-hidden` element the fold animation needs: the inset then lies - * INSIDE the clip, which is what lets a failed row's stripe, drawn 12px left - * of the row, show at all. The line is a pseudo-element, out of flow, so the - * height animation is untouched; it starts at the wrapper's top and stops - * short of the last row's bottom margin. + * hairline (`FoldRail`) hangs from the header's glyph down their left, so what + * is under the header reads as under it. Carried by the panel's clipping + * wrapper, the one `overflow-hidden` element the fold animation needs: the + * inset then lies INSIDE the clip, which is what lets a failed row's stripe, + * drawn 12px left of the row, show at all. The rail is absolutely positioned + * in that inset, out of flow, so the height animation is untouched. */ -export const FOLD_RAIL_CLASSES = - "relative pl-6 before:absolute before:bottom-1.5 before:left-[11px] before:top-0.5 before:w-px before:bg-border-medium before:content-['']"; +export const FOLD_RAIL_CLASSES = 'relative pl-6'; diff --git a/e2e/specs/mock/activity-fold.spec.ts b/e2e/specs/mock/activity-fold.spec.ts index 233f1bd009..b42b663558 100644 --- a/e2e/specs/mock/activity-fold.spec.ts +++ b/e2e/specs/mock/activity-fold.spec.ts @@ -139,6 +139,38 @@ test.describe('activity fold', () => { await expect(panel).toContainText(/error/i); await shot(page, 'revealed-by-pill'); + /** Each open fold's rail lights up under the pointer, swaps ITS header's + * glyph for a collapse knob, and collapses only that fold. */ + const knobs = messagesView(page).getByTestId('fold-rail-knob'); + const phaseRail = messagesView(page) + .getByTestId('activity-phase-panel') + .locator('> div > [data-testid="fold-rail"]'); + const groupPanel = messagesView(page) + .getByTestId('tool-call-group-panel') + .filter({ has: page.getByTestId('tool-call').filter({ hasText: /^Failed:/ }) }); + const groupRail = groupPanel.locator('> div > [data-testid="fold-rail"]'); + const groupHeader = groupPanel.locator('xpath=preceding-sibling::div[1]').getByRole('button'); + const lineColor = (railLocator: typeof groupRail) => + railLocator.locator('span').evaluate((line) => getComputedStyle(line).backgroundColor); + const restingLine = await lineColor(groupRail); + await expect(knobs).toHaveCount(0); + await groupRail.hover(); + await expect(knobs).toHaveCount(1); + await expect(groupHeader.getByTestId('fold-rail-knob')).toBeVisible(); + await expect.poll(() => lineColor(groupRail)).not.toBe(restingLine); + await shot(page, 'group-rail-hover'); + await phaseRail.hover(); + await expect(knobs).toHaveCount(1); + await expect(header.getByTestId('fold-rail-knob')).toBeVisible(); + await shot(page, 'phase-rail-hover'); + await groupRail.click(); + await expect(groupHeader).toHaveAttribute('aria-expanded', 'false'); + await expect(header).toHaveAttribute('aria-expanded', 'true'); + await phaseRail.click(); + await expect(header).toHaveAttribute('aria-expanded', 'false'); + await expect(knobs).toHaveCount(0); + await shot(page, 'rail-collapsed'); + /** Survives a reload from the persisted message. */ await page.reload(); const reloaded = messagesView(page).getByRole('button', { name: PHASE_LABEL, exact: true }); @@ -185,6 +217,60 @@ test.describe('activity fold', () => { await groupHeader.click(); await expect(messagesView(page).locator('[data-testid="tool-call"]').first()).toBeVisible(); await shot(page, 'clean-open-group'); + + const phaseRail = messagesView(page) + .getByTestId('activity-phase-panel') + .locator('> div > [data-testid="fold-rail"]'); + const groupRail = group.locator('> div > [data-testid="fold-rail"]'); + const phaseLabel = header.getByText(PHASE_LABEL, { exact: true }); + const beforeHover = await phaseLabel.boundingBox(); + await phaseRail.hover(); + await expect(header.getByTestId('fold-rail-knob')).toBeVisible(); + expect(await phaseLabel.boundingBox()).toEqual(beforeHover); + + const groupLabel = groupHeader.locator('[role="status"]'); + const beforeGroupHover = await groupLabel.boundingBox(); + await groupRail.hover(); + await expect(groupHeader.getByTestId('fold-rail-knob')).toBeVisible(); + expect(await groupLabel.boundingBox()).toEqual(beforeGroupHover); + + /** Keep room below the historical fold so collapse cannot clamp away an overlap. */ + const phaseCard = messagesView(page).getByTestId('activity-phase-card'); + await phaseCard.evaluate((card) => { + const spacer = document.createElement('div'); + spacer.style.height = '1200px'; + card.after(spacer); + }); + await group.locator('> div > div').evaluate((rows) => { + (rows as HTMLElement).style.paddingBottom = '1200px'; + }); + await groupRail.click({ position: { x: 12, y: 900 } }); + await expect(groupHeader).toHaveAttribute('aria-expanded', 'false'); + await expect(header).toHaveAttribute('aria-expanded', 'true'); + await expect + .poll(async () => { + const phaseBox = await header.boundingBox(); + const groupBox = await groupHeader.boundingBox(); + return phaseBox != null && groupBox != null && groupBox.y >= phaseBox.y + phaseBox.height; + }) + .toBe(true); + const isPointerAccessible = (button: typeof header) => + button.evaluate((element) => { + const box = element.getBoundingClientRect(); + return element.contains(document.elementFromPoint(box.left + 12, box.top + box.height / 2)); + }); + await expect(groupHeader).toBeInViewport(); + await expect.poll(() => isPointerAccessible(groupHeader)).toBe(true); + await shot(page, 'nested-rail-revealed'); + + await phaseRail.locator('..').evaluate((rows) => { + (rows as HTMLElement).style.paddingBottom = '1200px'; + }); + await phaseRail.click({ position: { x: 12, y: 900 } }); + await expect(header).toHaveAttribute('aria-expanded', 'false'); + await expect(header).toBeInViewport(); + await expect.poll(() => isPointerAccessible(header)).toBe(true); + await shot(page, 'phase-rail-revealed'); expect(problems.filter((line) => !line.includes('favicon'))).toEqual([]); }); });