feat(desktop): pin day header overlay and lift expanded-diff modal

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 <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
2026-06-17 20:12:55 -04:00
co-authored by Will Pfleger
parent 8a4ef01cff
commit 6cf3fde90a
7 changed files with 212 additions and 23 deletions
@@ -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}`);
});
@@ -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
@@ -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,
+12 -22
View File
@@ -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<void>;
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<string | null>(
null,
);
const [badgeBurstEmoji, setBadgeBurstEmoji] = React.useState<string | null>(
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}
</p>
) : null}
{expandedDiffId === message.id ? (
<React.Suspense
fallback={
<div className="p-3 text-sm text-muted-foreground">
Loading diff viewer…
</div>
}
>
<DiffMessageExpanded
content={message.body}
filePath={getTag("file")}
onClose={() => {
setExpandedDiffId(null);
}}
/>
</React.Suspense>
) : null}
</>
);
@@ -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<string>;
channel: Channel | null;
@@ -315,6 +318,13 @@ export function MessageThreadPanel({
}: MessageThreadPanelProps) {
const threadBodyRef = React.useRef<HTMLDivElement>(null);
const threadComposerWrapperRef = React.useRef<HTMLDivElement>(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<ExpandedDiff | null>(
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 ? (
<React.Suspense fallback={null}>
<DiffMessageExpanded
content={expandedDiff.content}
filePath={expandedDiff.filePath}
onClose={() => setExpandedDiff(null)}
/>
</React.Suspense>
) : null;
const threadHeaderContent = (
<>
<AuxiliaryPanelHeaderGroup>
@@ -679,6 +701,7 @@ export function MessageThreadPanel({
<AuxiliaryPanelHeader>{threadHeaderContent}</AuxiliaryPanelHeader>
{threadScrollRegion}
{threadFooter}
{diffModal}
</div>
);
}
@@ -714,6 +737,7 @@ export function MessageThreadPanel({
{threadScrollRegion}
{threadFooter}
</aside>
{diffModal}
</>
);
}
@@ -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<string>;
channelId?: string | null;
@@ -158,6 +164,14 @@ export const MessageTimeline = React.memo(function MessageTimeline({
const scrollContainerRef = externalScrollRef ?? internalScrollRef;
const topSentinelRef = React.useRef<HTMLDivElement>(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<ExpandedDiff | null>(
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({
</Button>
</div>
) : 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.
<div
className={cn(
"pointer-events-none absolute inset-x-0 z-10 flex justify-center px-2",
channelChrome.top,
)}
data-testid="message-timeline-day-divider-pinned"
>
<DayDivider label={formatDayHeading(activeDay.headingTimestamp)} />
</div>
) : null}
<div
className={cn(
"absolute inset-0 overflow-y-auto overflow-x-hidden overscroll-contain px-2 pt-1 [overflow-anchor:none]",
@@ -551,6 +592,7 @@ export const MessageTimeline = React.memo(function MessageTimeline({
>
<TimelineMessageList
agentPubkeys={agentPubkeys}
activeDayKey={activeDay?.key ?? null}
channelId={channelId}
channelName={channelName}
channelType={channelType}
@@ -566,6 +608,7 @@ export const MessageTimeline = React.memo(function MessageTimeline({
onEdit={onEdit}
onMarkUnread={onMarkUnread}
onReply={onReply}
onExpandDiff={setExpandedDiff}
isSendingVideoReviewComment={isSendingVideoReviewComment}
onSendVideoReviewComment={onSendVideoReviewComment}
onToggleReaction={onToggleReaction}
@@ -608,6 +651,15 @@ export const MessageTimeline = React.memo(function MessageTimeline({
</Button>
</div>
) : null}
{expandedDiff ? (
<React.Suspense fallback={null}>
<DiffMessageExpanded
content={expandedDiff.content}
filePath={expandedDiff.filePath}
onClose={() => setExpandedDiff(null)}
/>
</React.Suspense>
) : null}
</div>
</TooltipProvider>
);
@@ -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<string>;
/**
* 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-`<section>` 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 (
<div className="relative before:absolute before:inset-x-0 before:top-[15px] before:h-px before:bg-border/35 before:content-['']">
<div
className={cn(
"relative before:absolute before:inset-x-0 before:top-[15px] before:h-px before:bg-border/35 before:content-['']",
item.key === activeDayKey && "invisible",
)}
>
<DayDivider label={formatDayHeading(item.headingTimestamp)} />
</div>
);
@@ -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}