fix(desktop): match expanded thread margins to docked sidebar

Signed-off-by: Logan Johnson <loganj@squareup.com>
This commit is contained in:
Logan Johnson
2026-09-01 09:12:21 -04:00
parent 571c1902d0
commit e3baba744e
8 changed files with 166 additions and 66 deletions

View File

@@ -98,6 +98,7 @@ export default defineConfig({
"**/thread-reply-anchor-roleplay.spec.ts",
"**/threadpane-ultrawide.spec.ts",
"**/thread-focus-mode.spec.ts",
"**/thread-focus-margins.spec.ts",
"**/animated-avatar.spec.ts",
"**/reminders.spec.ts",
"**/reminder-click-repro.spec.ts",

View File

@@ -16,16 +16,6 @@
*/
export const THREAD_FOCUS_SLIVER_WIDTH_PX = 72;
/**
* Max width of the centered message column inside the focus drawer.
*
* The drawer itself spans nearly the whole channel content area, but message
* text set that wide is unreadable. The list and composer share this max width
* with auto horizontal margins so the reading measure stays comfortable no
* matter how wide the window gets.
*/
export const THREAD_FOCUS_COLUMN_MAX_WIDTH_PX = 880;
/**
* Horizontal distance the focus drawer travels on enter/exit.
*

View File

@@ -1,10 +1,7 @@
import type * as React from "react";
import { THREAD_FOCUS_COLUMN_MAX_WIDTH_PX } from "@/features/channels/lib/threadFocusLayout";
export type ThreadPanelLayoutProps = {
canResetWidth?: boolean;
columnMaxWidthPx?: number;
enterMotion?: boolean;
headerLeading?: React.ReactNode;
/** Replaces the default "Thread" label. Channel threads leave this unset. */
@@ -38,7 +35,6 @@ export function getThreadPanelLayout({
}: ThreadPanelLayoutOptions): ThreadPanelLayoutProps {
return isFocusDrawer
? {
columnMaxWidthPx: THREAD_FOCUS_COLUMN_MAX_WIDTH_PX,
headerLeading,
isFocusMode: true,
isSinglePanelView: true,
@@ -46,7 +42,6 @@ export function getThreadPanelLayout({
transparentChrome: false,
}
: {
columnMaxWidthPx: undefined,
headerLeading,
isFocusMode: false,
isSinglePanelView: useSplitAuxiliaryPane ? false : isSinglePanelView,

View File

@@ -8,11 +8,3 @@ export const THREAD_PANEL_MESSAGE_GUTTER_CLASS = "px-2";
/** Inline gutter around the thread composer and its activity row. */
export const THREAD_PANEL_COMPOSER_GUTTER_CLASS = "px-5";
/**
* Centers the reading column when a `columnMaxWidthPx` is supplied (focus-mode
* drawer). `px-10` (40px) is the inline gutter between the column and the drawer
* edges; the max-width itself is applied inline since it is a caller-provided
* pixel value.
*/
export const THREAD_PANEL_COLUMN_CLASS = "mx-auto w-full px-10";

View File

@@ -26,7 +26,6 @@ import { cn } from "@/shared/lib/cn";
import { AuxiliaryPanel } from "@/shared/layout/AuxiliaryPanel";
import { AuxiliaryPanelBody } from "@/shared/layout/AuxiliaryPanel";
import {
THREAD_PANEL_COLUMN_CLASS,
THREAD_PANEL_COMPOSER_GUTTER_CLASS,
THREAD_PANEL_MESSAGE_GUTTER_CLASS,
} from "@/features/messages/lib/messageThreadPanelLayout";
@@ -145,7 +144,6 @@ export function MessageThreadPanel({
channel,
channelId,
channelName,
columnMaxWidthPx,
currentPubkey,
disabled = false,
firstUnreadReplyId,
@@ -226,7 +224,6 @@ export function MessageThreadPanel({
onClose,
!isHuddleTranscript && (isOverlay || isSinglePanelView || isFocusMode),
);
const hasConstrainedColumn = columnMaxWidthPx != null;
// Whether the composer dock trades its quiet-state spacer for the
// conditional activity accessory (agent working and/or someone typing).
const hasComposerBottomActivity =
@@ -515,14 +512,7 @@ export function MessageThreadPanel({
{/* The gallery is intentionally DOM-scoped: only media currently rendered
in this open thread participates. Collapsed or unloaded descendants
join only after the thread UI renders them. */}
<div
className={cn(hasConstrainedColumn && THREAD_PANEL_COLUMN_CLASS)}
data-image-gallery-scope="thread"
ref={threadContentRef}
style={
hasConstrainedColumn ? { maxWidth: columnMaxWidthPx } : undefined
}
>
<div data-image-gallery-scope="thread" ref={threadContentRef}>
{isHuddleTranscript ? (
<div className={cn(THREAD_PANEL_MESSAGE_GUTTER_CLASS, "pb-2 pt-4")}>
<HuddleTranscriptIntro />
@@ -816,12 +806,7 @@ export function MessageThreadPanel({
data-testid="thread-composer-overlay"
ref={threadComposerWrapperRef}
>
<div
className={cn(hasConstrainedColumn && THREAD_PANEL_COLUMN_CLASS)}
style={
hasConstrainedColumn ? { maxWidth: columnMaxWidthPx } : undefined
}
>
<div>
<div
className={cn(
"composer-dock composer-overlay-corner-masks relative pointer-events-auto",

View File

@@ -0,0 +1,39 @@
import assert from "node:assert/strict";
import test from "node:test";
import { JSDOM } from "jsdom";
import React from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { getThreadPanelLayout } from "../../channels/lib/threadPanelLayout.ts";
import { MessageThreadPanelSkeleton } from "./MessageThreadPanelSkeleton.tsx";
function renderSkeleton(isFocusDrawer) {
const html = renderToStaticMarkup(
React.createElement(MessageThreadPanelSkeleton, {
...getThreadPanelLayout({
isFocusDrawer,
isSinglePanelView: false,
useSplitAuxiliaryPane: true,
}),
widthPx: 480,
onClose: () => {},
}),
);
return new JSDOM(html).window.document;
}
test("focus and split loading states use identical message and composer gutters", () => {
const focus = renderSkeleton(true);
const split = renderSkeleton(false);
for (const selector of [
'[data-testid="message-thread-loading"] > div',
".pointer-events-none.bottom-0 > .pointer-events-auto",
]) {
const focusedContent = focus.querySelector(selector);
const splitContent = split.querySelector(selector);
assert.ok(focusedContent, `Missing focused skeleton: ${selector}`);
assert.ok(splitContent, `Missing split skeleton: ${selector}`);
assert.equal(focusedContent.outerHTML, splitContent.outerHTML);
}
});

View File

@@ -1,7 +1,6 @@
import type * as React from "react";
import type { ThreadPanelLayoutProps } from "@/features/channels/lib/threadPanelLayout";
import {
THREAD_PANEL_COLUMN_CLASS,
THREAD_PANEL_COMPOSER_GUTTER_CLASS,
THREAD_PANEL_MESSAGE_GUTTER_CLASS,
} from "@/features/messages/lib/messageThreadPanelLayout";
@@ -105,24 +104,10 @@ export function ThreadMessageSkeleton({
);
}
function ThreadComposerSkeleton({
columnMaxWidthPx,
}: {
columnMaxWidthPx?: number;
}) {
const hasConstrainedColumn = columnMaxWidthPx != null;
function ThreadComposerSkeleton() {
return (
<div className="pointer-events-none absolute inset-x-0 bottom-0 z-10">
<div
className={cn(
"pointer-events-auto",
hasConstrainedColumn && THREAD_PANEL_COLUMN_CLASS,
)}
style={
hasConstrainedColumn ? { maxWidth: columnMaxWidthPx } : undefined
}
>
<div className="pointer-events-auto">
<div
className={cn(
"relative z-10 shrink-0 bg-transparent pb-2 pt-0",
@@ -152,7 +137,6 @@ function ThreadComposerSkeleton({
/** Loading state for the thread panel, in every layout the real panel supports. */
export function MessageThreadPanelSkeleton({
canResetWidth,
columnMaxWidthPx,
enterMotion,
headerLeading,
headerTitle,
@@ -171,7 +155,6 @@ export function MessageThreadPanelSkeleton({
transparentChrome = false,
}: MessageThreadPanelSkeletonProps) {
const isOverlay = useIsThreadPanelOverlay();
const hasConstrainedColumn = columnMaxWidthPx != null;
useEscapeKey(onClose, isOverlay || isSinglePanelView || isFocusMode);
const threadBody = (
@@ -179,12 +162,7 @@ export function MessageThreadPanelSkeleton({
className="overflow-y-auto overflow-x-hidden overscroll-contain pb-24"
data-testid="message-thread-loading"
>
<div
className={cn(hasConstrainedColumn && THREAD_PANEL_COLUMN_CLASS)}
style={
hasConstrainedColumn ? { maxWidth: columnMaxWidthPx } : undefined
}
>
<div>
<div
className={cn(THREAD_PANEL_MESSAGE_GUTTER_CLASS, "pb-1 pt-0")}
data-testid="message-thread-head-loading"
@@ -214,7 +192,7 @@ export function MessageThreadPanelSkeleton({
canResetWidth={canResetWidth}
className="relative"
enterMotion={enterMotion ?? !isFocusMode}
footer={<ThreadComposerSkeleton columnMaxWidthPx={columnMaxWidthPx} />}
footer={<ThreadComposerSkeleton />}
header={
<MessageThreadPanelHeader
headerLeading={headerLeading}

View File

@@ -0,0 +1,120 @@
import { expect, test, type Page } from "@playwright/test";
import { waitForAnimations } from "../helpers/animations";
import { installMockBridge } from "../helpers/bridge";
async function openThread(page: Page) {
await page.addInitScript(() => {
localStorage.setItem("buzz.channels.threadViewMode", "split");
});
await installMockBridge(page);
await page.goto("/");
await expect
.poll(() =>
page.evaluate(
() => typeof window.__BUZZ_E2E_EMIT_MOCK_MESSAGE__ === "function",
),
)
.toBe(true);
await page.evaluate(() => {
window.__BUZZ_E2E_EMIT_MOCK_MESSAGE__?.({
channelName: "general",
parentEventId: "mock-general-welcome",
content: [
"The thread should use the available panel width in both layouts. Expanding it keeps the channel visible behind the drawer, while messages and the reply composer retain their normal edge spacing.",
"## Validation notes",
"| Check | Result |\n| --- | --- |\n| Message margins | Match the split pane |\n| Reply composer | Uses the same edge spacing |\n| Channel sliver | Still visible behind the drawer |\n| Long content | Wraps within the panel |",
"This longer paragraph makes the reading measure visible. Switching back to the split pane should preserve the conversation and return to the same pane width, without changing the channel navigation or the drawer’s outer position.",
].join("\n\n"),
});
});
await page.getByTestId("channel-general").click();
const root = page.locator(
'[data-testid="message-row"][data-message-id="mock-general-welcome"]',
);
await root.hover();
await root.getByRole("button", { name: "Reply", exact: true }).click();
await expect(page.getByTestId("message-thread-body")).toBeVisible();
}
async function geometry(page: Page) {
return page.getByTestId("message-thread-body").evaluate((body) => {
const panel = body.closest('[data-testid="message-thread-panel"]');
const row = body.querySelector('[data-message-id="mock-general-welcome"]');
const composer = panel?.querySelector('[data-testid="message-composer"]');
if (!panel || !row || !composer) throw new Error("Missing thread geometry");
const outer = panel.getBoundingClientRect();
const message = row.getBoundingClientRect();
const input = composer.getBoundingClientRect();
return {
panel: { x: outer.x, width: outer.width },
row: {
left: message.left - outer.left,
right: outer.right - message.right,
},
composer: {
left: input.left - outer.left,
right: outer.right - input.right,
},
overflow: body.scrollWidth - body.clientWidth,
};
});
}
for (const width of [1280, 1720, 2560]) {
test(`focus content keeps split gutters at ${width}px`, async ({
page,
}, testInfo) => {
await page.setViewportSize({ width, height: 900 });
await openThread(page);
await waitForAnimations(page);
const split = await geometry(page);
await page.screenshot({ path: testInfo.outputPath("split.png") });
await page
.getByRole("button", { name: "Expand thread", exact: true })
.click();
await expect(page.getByTestId("focus-thread-drawer")).toBeVisible();
await waitForAnimations(page);
// Motion's transform can finish on a later animation frame than CSS animations.
await expect
.poll(async () => {
const drawer = await page
.getByTestId("focus-thread-drawer")
.boundingBox();
const overlay = await page
.getByTestId("focus-thread-drawer-overlay")
.boundingBox();
return Math.abs((drawer?.x ?? 0) - (overlay?.x ?? 0) - 72);
})
.toBeLessThan(0.01);
const focus = await geometry(page);
await page.screenshot({ path: testInfo.outputPath("focus.png") });
await testInfo.attach("geometry", {
body: JSON.stringify({ split, focus }, null, 2),
contentType: "application/json",
});
expect(focus.panel.width).toBeGreaterThan(split.panel.width);
expect(focus.overflow).toBe(0);
for (const edge of ["left", "right"] as const) {
expect(focus.row[edge]).toBeCloseTo(split.row[edge], 1);
expect(focus.composer[edge]).toBeCloseTo(split.composer[edge], 1);
}
// Keep the outer drawer position: the existing 72px channel sliver.
const overlay = await page
.getByTestId("focus-thread-drawer-overlay")
.boundingBox();
expect(overlay).not.toBeNull();
expect(focus.panel.x - (overlay?.x ?? 0)).toBeCloseTo(72, 1);
expect(focus.panel.width).toBeCloseTo((overlay?.width ?? 0) - 72, 1);
await page
.getByRole("button", { name: "Show thread beside channel", exact: true })
.click();
await expect(page.getByTestId("focus-thread-drawer")).toHaveCount(0);
await waitForAnimations(page);
expect(await geometry(page)).toEqual(split);
});
}