From 6cf3fde90ad56f20ca823193725c5e941c785b17 Mon Sep 17 00:00:00 2001 From: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 Date: Wed, 17 Jun 2026 20:12:55 -0400 Subject: [PATCH] feat(desktop): pin day header overlay and lift expanded-diff modal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Virtualizing the timeline made the legacy sticky DayDivider impossible: position:sticky cannot work on a position:absolute virtual row. Restore the pinned-date UX with the standard virtualized sticky-group-header pattern instead — selectActiveDayHeading derives the day group owning the topmost rendered row (index-based, measurement-free), and the timeline paints ONE header in a sibling layer pinned at the measured channel-chrome top. The matching inline divider is hidden with invisible so its label never doubles while keeping its measured height (no scroll jump). The expanded-diff viewer is a Radix Dialog portal, so its open state must live above the virtualized rows — otherwise scrolling the triggering row out of the window unmounts it and the open modal vanishes. Lift ownership to both surfaces via an onExpandDiff callback. A single ExpandedDiff value (not a Set) is the faithful model: the modal backdrop makes more than one open structurally impossible. Co-authored-by: Will Pfleger Signed-off-by: Will Pfleger --- .../messages/lib/timelineSnapshot.test.mjs | 55 +++++++++++++++++++ .../features/messages/lib/timelineSnapshot.ts | 30 ++++++++++ .../messages/ui/DiffMessageExpanded.tsx | 13 +++++ .../src/features/messages/ui/MessageRow.tsx | 34 ++++-------- .../messages/ui/MessageThreadPanel.tsx | 24 ++++++++ .../features/messages/ui/MessageTimeline.tsx | 52 ++++++++++++++++++ .../messages/ui/TimelineMessageList.tsx | 27 ++++++++- 7 files changed, 212 insertions(+), 23 deletions(-) diff --git a/desktop/src/features/messages/lib/timelineSnapshot.test.mjs b/desktop/src/features/messages/lib/timelineSnapshot.test.mjs index 22af80ec2..ca7c29ac5 100644 --- a/desktop/src/features/messages/lib/timelineSnapshot.test.mjs +++ b/desktop/src/features/messages/lib/timelineSnapshot.test.mjs @@ -8,6 +8,7 @@ import { buildTimelineVirtualItems, isNearBottomMetrics, resolveDeepLinkTarget, + selectActiveDayHeading, selectDeferredListRenderState, selectLatestMessageKey, } from "./timelineSnapshot.ts"; @@ -463,3 +464,57 @@ test("thread-items: reply key prefers renderKey for optimistic-send identity", ( ]); assert.equal(items[0].key, "local-key"); }); + +// --- pinned day-header overlay (option B sticky-overlay) -------------------- +// +// selectActiveDayHeading derives which day group owns the topmost rendered row +// so the timeline can paint ONE pinned header outside the virtualizer's +// absolute flow (a per-row `position:sticky` cannot work on an absolute row). +// It walks back from the top rendered index to the nearest preceding day item. + +test("active-day: null when nothing is rendered", () => { + const items = buildTimelineVirtualItems([ + entry({ id: "a", createdAt: dayAt(2026, 6, 14) }), + ]); + assert.equal(selectActiveDayHeading(items, undefined), null); +}); + +test("active-day: the day item itself is its own active heading", () => { + // items: [day, message]; top rendered = index 0 (the day divider) + const ts = dayAt(2026, 6, 14); + const items = buildTimelineVirtualItems([entry({ id: "a", createdAt: ts })]); + const active = selectActiveDayHeading(items, 0); + assert.equal(active.key, `day-${ts}`); + assert.equal(active.headingTimestamp, ts); +}); + +test("active-day: a message row resolves to its enclosing day", () => { + // items: [day, message]; top rendered = index 1 (the message) → its day + const ts = dayAt(2026, 6, 14); + const items = buildTimelineVirtualItems([entry({ id: "a", createdAt: ts })]); + const active = selectActiveDayHeading(items, 1); + assert.equal(active.key, `day-${ts}`); + assert.equal(active.headingTimestamp, ts); +}); + +test("active-day: picks the most recent day boundary at or above the top row", () => { + // items: [day1, msg, msg, day2, msg]; top rendered inside day2's group + const day1 = dayAt(2026, 6, 14); + const day2 = dayAt(2026, 6, 15); + const items = buildTimelineVirtualItems([ + entry({ id: "a", createdAt: day1 }), + entry({ id: "b", createdAt: dayAt(2026, 6, 14, 13) }), + entry({ id: "c", createdAt: day2 }), + ]); + // indices: 0 day1, 1 msg a, 2 msg b, 3 day2, 4 msg c + assert.equal(selectActiveDayHeading(items, 2).key, `day-${day1}`); + assert.equal(selectActiveDayHeading(items, 4).key, `day-${day2}`); + assert.equal(selectActiveDayHeading(items, 3).key, `day-${day2}`); +}); + +test("active-day: a top index past the end clamps to the last item's day", () => { + const ts = dayAt(2026, 6, 14); + const items = buildTimelineVirtualItems([entry({ id: "a", createdAt: ts })]); + // index 99 is out of range; the helper clamps and still finds the day + assert.equal(selectActiveDayHeading(items, 99).key, `day-${ts}`); +}); diff --git a/desktop/src/features/messages/lib/timelineSnapshot.ts b/desktop/src/features/messages/lib/timelineSnapshot.ts index 356b02da2..f35bc6986 100644 --- a/desktop/src/features/messages/lib/timelineSnapshot.ts +++ b/desktop/src/features/messages/lib/timelineSnapshot.ts @@ -228,6 +228,36 @@ export function buildTimelineVirtualItems( return items; } +/** + * The day heading that should be pinned to the top of the viewport: the day + * group that owns the topmost rendered row. `topRenderedIndex` is the index of + * the first item in the virtualizer's rendered window (`getVirtualItems()[0]`). + * We walk back from it to the nearest preceding `day` item — that group is the + * one currently being scrolled through, so its heading is what a sticky day + * header would show. Index-based (not offset-based) so it never depends on row + * measurement: the pinned label is correct even when the day divider has + * scrolled far above the rendered window. + * + * Returns `null` when there is no rendered row or no day item at/above it (an + * empty list, or rows before the first day boundary — which never happens since + * a day item always opens the list). + */ +export function selectActiveDayHeading( + items: readonly TimelineVirtualItem[], + topRenderedIndex: number | undefined, +): { key: string; headingTimestamp: number } | null { + if (topRenderedIndex === undefined) { + return null; + } + for (let i = Math.min(topRenderedIndex, items.length - 1); i >= 0; i--) { + const item = items[i]; + if (item.kind === "day") { + return { key: item.key, headingTimestamp: item.headingTimestamp }; + } + } + return null; +} + /** * One row in the flattened, virtualizer-ready thread reply list. The thread * pane has a simpler shape than the main timeline — no day grouping, no system diff --git a/desktop/src/features/messages/ui/DiffMessageExpanded.tsx b/desktop/src/features/messages/ui/DiffMessageExpanded.tsx index 15ce1703e..a74f771db 100644 --- a/desktop/src/features/messages/ui/DiffMessageExpanded.tsx +++ b/desktop/src/features/messages/ui/DiffMessageExpanded.tsx @@ -16,6 +16,19 @@ type DiffMessageExpandedProps = { onClose: () => void; }; +/** + * The data needed to render an expanded diff modal, lifted out of the row that + * triggered it. The modal is a Radix `Dialog` portal, so its open state must + * live ABOVE the virtualized rows — otherwise scrolling the triggering row out + * of the window unmounts the row and the open modal vanishes. Only one diff can + * be open at a time (the modal backdrop blocks every other row), so a single + * value, not a set, is the faithful model. + */ +export type ExpandedDiff = { + content: string; + filePath?: string; +}; + export default function DiffMessageExpanded({ content, filePath, diff --git a/desktop/src/features/messages/ui/MessageRow.tsx b/desktop/src/features/messages/ui/MessageRow.tsx index 869ef0cb4..bd7dfb116 100644 --- a/desktop/src/features/messages/ui/MessageRow.tsx +++ b/desktop/src/features/messages/ui/MessageRow.tsx @@ -2,6 +2,7 @@ import * as React from "react"; import type { TimelineMessage } from "@/features/messages/types"; import { MessageReactions } from "@/features/messages/ui/MessageReactions"; +import type { ExpandedDiff } from "@/features/messages/ui/DiffMessageExpanded"; import { useReactionHandler } from "@/features/messages/ui/useReactionHandler"; import type { UserProfileLookup } from "@/features/profile/lib/identity"; import { UserProfilePopover } from "@/features/profile/ui/UserProfilePopover"; @@ -26,7 +27,6 @@ import { MessageTimestamp } from "./MessageTimestamp"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/shared/ui/tooltip"; const DiffMessage = React.lazy(() => import("./DiffMessage")); -const DiffMessageExpanded = React.lazy(() => import("./DiffMessageExpanded")); const MESSAGE_TEXT_OFFSET_PX = 54; const NESTED_REPLY_OFFSET_PX = 28; @@ -47,6 +47,7 @@ export const MessageRow = React.memo( onToggleReaction, onReply, onUnfollowThread, + onExpandDiff, profiles, searchQuery, showDepthGuides = true, @@ -72,14 +73,17 @@ export const MessageRow = React.memo( ) => Promise; onReply?: (message: TimelineMessage) => void; onUnfollowThread?: (message: TimelineMessage) => void; + /** + * Open the expanded diff modal for this row. Lifted to the surface so the + * modal (a Radix portal) survives this row unmounting when scrolled out of + * the virtualized window. + */ + onExpandDiff?: (diff: ExpandedDiff) => void; profiles?: UserProfileLookup; searchQuery?: string; showDepthGuides?: boolean; videoReviewContext?: VideoReviewContext; }) { - const [expandedDiffId, setExpandedDiffId] = React.useState( - null, - ); const [badgeBurstEmoji, setBadgeBurstEmoji] = React.useState( null, ); @@ -185,7 +189,10 @@ export const MessageRow = React.memo( description={getTag("description")} filePath={getTag("file")} onExpand={() => { - setExpandedDiffId(message.id); + onExpandDiff?.({ + content: message.body, + filePath: getTag("file"), + }); }} repoUrl={getTag("repo")} truncated={getTag("truncated") === "true"} @@ -339,23 +346,6 @@ export const MessageRow = React.memo( {reactionErrorMessage}

) : null} - {expandedDiffId === message.id ? ( - - Loading diff viewer… - - } - > - { - setExpandedDiffId(null); - }} - /> - - ) : null} ); diff --git a/desktop/src/features/messages/ui/MessageThreadPanel.tsx b/desktop/src/features/messages/ui/MessageThreadPanel.tsx index a15e76aa3..245e34b45 100644 --- a/desktop/src/features/messages/ui/MessageThreadPanel.tsx +++ b/desktop/src/features/messages/ui/MessageThreadPanel.tsx @@ -26,6 +26,7 @@ import { import { Skeleton } from "@/shared/ui/skeleton"; import type { VideoReviewContext } from "@/shared/ui/VideoPlayer"; import { MessageComposer } from "./MessageComposer"; +import type { ExpandedDiff } from "./DiffMessageExpanded"; import { MessageRow } from "./MessageRow"; import { MessageThreadSummaryRow } from "./MessageThreadSummaryRow"; import { TypingIndicatorRow } from "./TypingIndicatorRow"; @@ -38,6 +39,8 @@ import { selectLatestMessageKey, } from "@/features/messages/lib/timelineSnapshot"; +const DiffMessageExpanded = React.lazy(() => import("./DiffMessageExpanded")); + type MessageThreadPanelProps = { agentPubkeys?: ReadonlySet; channel: Channel | null; @@ -315,6 +318,13 @@ export function MessageThreadPanel({ }: MessageThreadPanelProps) { const threadBodyRef = React.useRef(null); const threadComposerWrapperRef = React.useRef(null); + + // Expanded-diff modal owned at the panel level (above the virtualized reply + // rows) so an open diff survives its row scrolling out of the window. One at + // a time — the modal backdrop blocks every other row. + const [expandedDiff, setExpandedDiff] = React.useState( + null, + ); const isOverlay = useIsThreadPanelOverlay(); const isFloatingOverlay = isOverlay && !isSinglePanelView; const isSplitLayout = layout === "split"; @@ -465,6 +475,7 @@ export function MessageThreadPanel({ } onMarkUnread={onMarkUnread} onReply={onSelectReplyTarget} + onExpandDiff={setExpandedDiff} onToggleReaction={onToggleReaction} profiles={profiles} /> @@ -515,6 +526,7 @@ export function MessageThreadPanel({ } onMarkUnread={onMarkUnread} onToggleReaction={onToggleReaction} + onExpandDiff={setExpandedDiff} onUnfollowThread={ onUnfollowThread ? (_msg) => onUnfollowThread() : undefined } @@ -641,6 +653,16 @@ export function MessageThreadPanel({ ); + const diffModal = expandedDiff ? ( + + setExpandedDiff(null)} + /> + + ) : null; + const threadHeaderContent = ( <> @@ -679,6 +701,7 @@ export function MessageThreadPanel({ {threadHeaderContent} {threadScrollRegion} {threadFooter} + {diffModal} ); } @@ -714,6 +737,7 @@ export function MessageThreadPanel({ {threadScrollRegion} {threadFooter} + {diffModal} ); } diff --git a/desktop/src/features/messages/ui/MessageTimeline.tsx b/desktop/src/features/messages/ui/MessageTimeline.tsx index a46f66a46..206cd99e8 100644 --- a/desktop/src/features/messages/ui/MessageTimeline.tsx +++ b/desktop/src/features/messages/ui/MessageTimeline.tsx @@ -2,9 +2,11 @@ import * as React from "react"; import { ArrowDown, ArrowUp, Hash } from "lucide-react"; import { getDmParticipantPreview } from "@/features/channels/lib/dmParticipantDisplay"; +import { formatDayHeading } from "@/features/messages/lib/dateFormatters"; import { buildMainTimelineEntries } from "@/features/messages/lib/threadPanel"; import { buildTimelineVirtualItems, + selectActiveDayHeading, selectLatestMessageKey, } from "@/features/messages/lib/timelineSnapshot"; import type { TimelineMessage } from "@/features/messages/types"; @@ -17,10 +19,14 @@ import { Spinner } from "@/shared/ui/spinner"; import { SkeletonReveal } from "@/shared/ui/skeleton"; import { TooltipProvider } from "@/shared/ui/tooltip"; import { UserAvatar } from "@/shared/ui/UserAvatar"; +import { DayDivider } from "./DayDivider"; +import type { ExpandedDiff } from "./DiffMessageExpanded"; import { TimelineSkeleton, useTimelineSkeletonRows } from "./TimelineSkeleton"; import { TimelineMessageList } from "./TimelineMessageList"; import { useChatScrollVirtualizer } from "./useChatScrollVirtualizer"; +const DiffMessageExpanded = React.lazy(() => import("./DiffMessageExpanded")); + type MessageTimelineProps = { agentPubkeys?: ReadonlySet; channelId?: string | null; @@ -158,6 +164,14 @@ export const MessageTimeline = React.memo(function MessageTimeline({ const scrollContainerRef = externalScrollRef ?? internalScrollRef; const topSentinelRef = React.useRef(null); + // The expanded-diff modal (a Radix portal) is owned here, ABOVE the + // virtualized rows, so the open modal survives the triggering row scrolling + // out of the window and unmounting. Only one is open at a time (the modal + // backdrop blocks every other row). + const [expandedDiff, setExpandedDiff] = React.useState( + null, + ); + // Gate the heavy timeline render (each row runs a synchronous // react-markdown parse) behind React concurrency. `useDeferredValue` lets the // commit that rebuilds the message list yield to higher-priority work, so the @@ -227,6 +241,17 @@ export const MessageTimeline = React.memo(function MessageTimeline({ onTargetReached, }); + // The pinned day header (option B sticky-overlay). A virtual row is + // `position:absolute`, so a per-row `position:sticky` cannot work; instead we + // derive the day group that owns the topmost rendered row and paint ONE + // header in a sibling layer pinned below the channel chrome, mirroring the + // legacy `sticky` DayDivider. Reading `getVirtualItems()[0]` each render keeps + // it live — the virtualizer re-renders this component on every scroll/measure. + const activeDay = selectActiveDayHeading( + items, + virtualizer.getVirtualItems()[0]?.index, + ); + // Deep-link to `targetMessageId` once it resolves against the rendered // snapshot. `resolveDeepLinkTarget` reads the same `deferredMessages` the // rows came from, so the jump never fires against an uncommitted row; the @@ -377,6 +402,22 @@ export const MessageTimeline = React.memo(function MessageTimeline({ ) : null} + {showMessageList && activeDay ? ( + // Option B sticky-overlay: one pinned day header in a sibling layer + // outside the virtualizer's absolute flow, replacing the legacy + // per-row `sticky` DayDivider (impossible on an absolute virtual row). + // The matching inline divider is suppressed via `activeDayKey` so the + // label never doubles — exactly one visible heading per day, as before. +
+ +
+ ) : null}
) : null} + {expandedDiff ? ( + + setExpandedDiff(null)} + /> + + ) : null} ); diff --git a/desktop/src/features/messages/ui/TimelineMessageList.tsx b/desktop/src/features/messages/ui/TimelineMessageList.tsx index a0d4ba6aa..fab81c912 100644 --- a/desktop/src/features/messages/ui/TimelineMessageList.tsx +++ b/desktop/src/features/messages/ui/TimelineMessageList.tsx @@ -12,6 +12,7 @@ import type { ChannelType } from "@/shared/api/types"; import { cn } from "@/shared/lib/cn"; import type { ChatVirtualizer } from "./useChatScrollVirtualizer"; import { DayDivider } from "./DayDivider"; +import type { ExpandedDiff } from "./DiffMessageExpanded"; import { MessageRow } from "./MessageRow"; import { MessageThreadSummaryRow } from "./MessageThreadSummaryRow"; import { SystemMessageRow } from "./SystemMessageRow"; @@ -19,6 +20,12 @@ import { UnreadDivider } from "./UnreadDivider"; type TimelineMessageListProps = { agentPubkeys?: ReadonlySet; + /** + * Key of the day group whose heading is currently pinned in the overlay + * (option B sticky-overlay). The matching inline day divider is hidden so the + * label never doubles — the overlay is its stand-in while it would be pinned. + */ + activeDayKey?: string | null; channelId?: string | null; channelName?: string; channelType?: ChannelType | null; @@ -34,6 +41,11 @@ type TimelineMessageListProps = { onEdit?: (message: TimelineMessage) => void; onMarkUnread?: (message: TimelineMessage) => void; onReply?: (message: TimelineMessage) => void; + /** + * Open the expanded diff modal. Forwarded to each `MessageRow`; the surface + * owns the modal so it survives a row scrolling out of the virtual window. + */ + onExpandDiff?: (diff: ExpandedDiff) => void; isSendingVideoReviewComment?: boolean; onSendVideoReviewComment?: ( message: TimelineMessage, @@ -77,6 +89,7 @@ type TimelineMessageListProps = { export const TimelineMessageList = React.memo(function TimelineMessageList({ agentPubkeys, + activeDayKey = null, channelId, channelName, channelType, @@ -90,6 +103,7 @@ export const TimelineMessageList = React.memo(function TimelineMessageList({ onEdit, onMarkUnread, onReply, + onExpandDiff, isSendingVideoReviewComment = false, onSendVideoReviewComment, onToggleReaction, @@ -154,8 +168,17 @@ export const TimelineMessageList = React.memo(function TimelineMessageList({ // The thin connector line that the legacy day-`
` drew behind // the centered pill is re-homed onto this row so the divider keeps its // rule-behind-label look without the group wrapper. + // + // When this is the active (pinned) day, the overlay header above is its + // stand-in, so we hide the inline label with `invisible` — the row keeps + // its measured height (no scroll jump) but never shows a second copy. return ( -
+
); @@ -218,6 +241,7 @@ export const TimelineMessageList = React.memo(function TimelineMessageList({ onMarkUnread={onMarkUnread} onToggleReaction={onToggleReaction} onReply={onReply} + onExpandDiff={onExpandDiff} onUnfollowThread={ unfollowThreadById ? () => unfollowThreadById(message.id) @@ -265,6 +289,7 @@ export const TimelineMessageList = React.memo(function TimelineMessageList({ onMarkUnread={onMarkUnread} onToggleReaction={onToggleReaction} onReply={onReply} + onExpandDiff={onExpandDiff} profiles={profiles} searchQuery={isSearchMatch ? searchQuery : undefined} showDepthGuides={false}