From c51aa3cb05806ff747f184bbe66125060106b9d9 Mon Sep 17 00:00:00 2001 From: Michael Yong Date: Tue, 27 Oct 2026 15:08:41 -0700 Subject: [PATCH 1/2] Keep the timeline pinned when content collapses for a single task Two causes unpinned a thread scrolled to the bottom with no input: - A footer or row that collapses and regrows within one task, while something forces a layout, lets the browser clamp scrollTop. The clamp scroll arrives after the content regrew, with no input and no size change, so the keeper reads it as navigation and detaches. The timeline now holds a floor under its scroll extent: a spacer, cancelled by a negative margin, sized to the content at the last ResizeObserver delivery. One-task collapses no longer lower the extent; lasting shrinks lower the floor before reconciling. - Markdown links, inline code, images and mention pills were component closures rebuilt whenever link routing or mentions changed identity, so every message remounted them (twice per thread open, and on background events). iOS WebKit moves the scroller when links remount. They are now module-level components that read per-message options from context. Co-Authored-By: Claude Opus 5.5 --- .../promptbox/banner/QueuedMessagesList.tsx | 27 +- ...versationMessageContent.streaming.test.tsx | 3 +- .../timeline/TimelineWindowedItems.test.tsx | 1 + .../timeline/useAutoLoadOlderRows.test.tsx | 1 + .../thread/timeline/useStickyBottomScroll.ts | 1 + .../useThreadTimelineController.test.tsx | 1 + .../ui/bottom-anchored-scroll-body.tsx | 7 + .../components/ui/markdown-preview.test.tsx | 57 ++ .../src/components/ui/markdown-preview.tsx | 642 +++++++++--------- .../ui/markdown-prompt-mentions.tsx | 50 +- .../ui/markdown-thread-mentions.tsx | 190 +++--- .../ui/scroll-position-keeper.model.test.ts | 40 +- .../ui/scroll-position-keeper.test.ts | 61 +- .../components/ui/scroll-position-keeper.ts | 42 +- apps/app/src/test/fake-flow-layout.ts | 95 ++- apps/app/src/test/scroll-position-keeper.ts | 1 + docs/timeline-pagination.md | 21 +- 17 files changed, 753 insertions(+), 487 deletions(-) diff --git a/apps/app/src/components/promptbox/banner/QueuedMessagesList.tsx b/apps/app/src/components/promptbox/banner/QueuedMessagesList.tsx index 79f25f26950..b29ad27cb76 100644 --- a/apps/app/src/components/promptbox/banner/QueuedMessagesList.tsx +++ b/apps/app/src/components/promptbox/banner/QueuedMessagesList.tsx @@ -106,7 +106,8 @@ import { shiftMentionsToTextRange, } from "@/components/thread/timeline/ConversationMessageMentions"; import { - buildPromptMentionComponent, + PromptMentionElement, + PromptMentionsContext, remarkPromptMentions, substitutePromptMentions, } from "@/components/ui/markdown-prompt-mentions"; @@ -234,6 +235,7 @@ const QUEUED_MARKDOWN_COMPONENTS: Components = { thead: ({ children }) => {children}, tr: ({ children }) => {children} , ul: ({ children }) => {children}, + "bb-prompt-mention": PromptMentionElement, }; function CompactQueuedMarkdownPreview({ @@ -254,25 +256,24 @@ function CompactQueuedMarkdownPreview({ normalizePromptBlockquoteBoundaries(promptMentionSubstitution.content), [promptMentionSubstitution.content], ); - const components = useMemo( + const promptMentions = useMemo( () => ({ - ...QUEUED_MARKDOWN_COMPONENTS, - "bb-prompt-mention": buildPromptMentionComponent({ - mentions: promptMentionSubstitution.mentions, - resolveMentionLink, - }), + mentions: promptMentionSubstitution.mentions, + resolveMentionLink, }), [promptMentionSubstitution.mentions, resolveMentionLink], ); return ( - - {markdownContent} - + + + {markdownContent} + + ); } diff --git a/apps/app/src/components/thread/timeline/ConversationMessageContent.streaming.test.tsx b/apps/app/src/components/thread/timeline/ConversationMessageContent.streaming.test.tsx index 6ba563b541d..bccfce01d71 100644 --- a/apps/app/src/components/thread/timeline/ConversationMessageContent.streaming.test.tsx +++ b/apps/app/src/components/thread/timeline/ConversationMessageContent.streaming.test.tsx @@ -104,7 +104,8 @@ describe("ConversationMessageContent streaming split", () => { ]); expect(markdownRenders).toEqual([ "Para two.\n\n", - "Para three.\n\nPara four", + "Para three.\n\n", + "Para four", ]); markdownRenders.length = 0; diff --git a/apps/app/src/components/thread/timeline/TimelineWindowedItems.test.tsx b/apps/app/src/components/thread/timeline/TimelineWindowedItems.test.tsx index cbe4d585b7b..13ea6a19109 100644 --- a/apps/app/src/components/thread/timeline/TimelineWindowedItems.test.tsx +++ b/apps/app/src/components/thread/timeline/TimelineWindowedItems.test.tsx @@ -50,6 +50,7 @@ function setup({ bottomThresholdPx: 4, deferWritesWhileScrolling: false, getContentElement: () => content, + getFloorElement: () => null, getFooterElement: () => null, getScrollElement: () => (rootReady ? scrollElement : null), getTopLevelRows: () => diff --git a/apps/app/src/components/thread/timeline/useAutoLoadOlderRows.test.tsx b/apps/app/src/components/thread/timeline/useAutoLoadOlderRows.test.tsx index 9a38fac47d8..a2e94bf0419 100644 --- a/apps/app/src/components/thread/timeline/useAutoLoadOlderRows.test.tsx +++ b/apps/app/src/components/thread/timeline/useAutoLoadOlderRows.test.tsx @@ -15,6 +15,7 @@ function createBottomAnchor( bottomThresholdPx: 4, deferWritesWhileScrolling: false, getContentElement: () => null, + getFloorElement: () => null, getFooterElement: () => null, getScrollElement: () => scrollElement, getTopLevelRows: () => [], diff --git a/apps/app/src/components/thread/timeline/useStickyBottomScroll.ts b/apps/app/src/components/thread/timeline/useStickyBottomScroll.ts index bfb94d0a2f6..9e575e7a908 100644 --- a/apps/app/src/components/thread/timeline/useStickyBottomScroll.ts +++ b/apps/app/src/components/thread/timeline/useStickyBottomScroll.ts @@ -34,6 +34,7 @@ export function useStickyBottomScroll({ bottomThresholdPx: STICKY_BOTTOM_THRESHOLD_PX, deferWritesWhileScrolling: isIOSWebKit(navigator), getContentElement: () => contentRef.current, + getFloorElement: () => null, getFooterElement: () => null, getScrollElement: () => scrollRef.current, getTopLevelRows, diff --git a/apps/app/src/components/thread/timeline/useThreadTimelineController.test.tsx b/apps/app/src/components/thread/timeline/useThreadTimelineController.test.tsx index 91a96a3d119..d5fc27b0167 100644 --- a/apps/app/src/components/thread/timeline/useThreadTimelineController.test.tsx +++ b/apps/app/src/components/thread/timeline/useThreadTimelineController.test.tsx @@ -242,6 +242,7 @@ function installAutoLoadEnvironment() { bottomThresholdPx: 4, deferWritesWhileScrolling: false, getContentElement: () => null, + getFloorElement: () => null, getFooterElement: () => null, getScrollElement: () => scrollElement, getTopLevelRows: () => [], diff --git a/apps/app/src/components/ui/bottom-anchored-scroll-body.tsx b/apps/app/src/components/ui/bottom-anchored-scroll-body.tsx index 72637cc1c06..38d1ee31f0b 100644 --- a/apps/app/src/components/ui/bottom-anchored-scroll-body.tsx +++ b/apps/app/src/components/ui/bottom-anchored-scroll-body.tsx @@ -107,6 +107,7 @@ export function BottomAnchoredScrollBody({ const scrollContentRef = useRef(null); const pageContentRef = useRef(null); const scrollFooterRef = useRef(null); + const scrollFloorRef = useRef(null); const hasFooter = Boolean(footer); const scrollAnchorCaptureThrottleRef = useRef<{ lastWriteAt: number; @@ -131,6 +132,7 @@ export function BottomAnchoredScrollBody({ bottomThresholdPx: BOTTOM_ANCHOR_THRESHOLD_PX, deferWritesWhileScrolling: isIOSWebKit(navigator), getContentElement: () => pageContentRef.current, + getFloorElement: () => scrollFloorRef.current, getFooterElement: () => scrollFooterRef.current, getScrollElement: () => scrollAreaRef.current, getTopLevelRows, @@ -338,6 +340,11 @@ export function BottomAnchoredScrollBody({ ref={scrollContentRef} className="flex min-h-full min-w-0 flex-col" > +