Skip to content
Source
Sign inSign up
pingdotgg/t3code

Stabilize chat scroll anchoring after send #3564

Mergedjuliusmarmingemerged 6 commits intomain fromrefs/pull/3564/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Summary

  • Stabilizes chat scroll behavior after sending a message so the timeline keeps its place more predictably during updates.
  • Simplifies several ACP/provider test fixtures and adapter code by removing brittle scenario branches that were no longer needed.
  • Tightens the chat timeline logic and component wiring around message ordering and scroll anchoring.
  • Reduces a large amount of test-only complexity across server and web layers while keeping the core send flow intact.

Testing

  • Not run locally in this branch summary.
  • Repository requirement: vp check
  • Repository requirement: vp run typecheck
  • If mobile code is affected, also run vp run lint:mobile

Note

Medium Risk Touches core chat list scroll behavior on web and mobile (anchoring, streaming layout, disclosure), where regressions are easy to miss; logic changes are covered by new timeline/feed tests but UX edge cases remain.

Overview Web chat no longer jumps to the list bottom when you send a message. ChatView sets a timeline anchor on the optimistic user row, scrolls it into place once LegendList measures it (onAnchorReady / onAnchorSizeChanged), and restores scroll offset while the anchor row resizes during streaming. MessagesTimeline drops maintainScrollAtEnd in favor of maintainVisibleContentPosition with size: false and [overflow-anchor:none].

Work log overflow is no longer an inline “show more” inside WorkGroupSection / ThreadWorkLog. deriveMessagesTimelineRows and deriveThreadFeedPresentation now emit a work-toggle row (and split overflow into per-entry rows when collapsed), with expandedWorkGroupIds driving expansion. Toggles adjust scroll so the control stays put (web: flushSync + delta scroll; mobile: disclosure settling + selective shouldRestorePosition).

Mobile mirrors the same feed modeling via ThreadWorkGroupToggle, tighter work-row styling, and shared disclosure scroll suspension for turn folds, work groups, and row expand.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 6809aff1e2a195cef8e6cc3a492327662c1b2e5c. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Stabilize chat scroll anchoring after message send and work group expansion

  • On web, sending a message now animates the list to place the sent row at a fixed offset and preserves scroll position as the row's height settles, replacing the previous end-scroll pin approach.
  • Work log overflow in both web and mobile is now modeled as explicit work-toggle list rows; expanding a group inserts earlier entries inline while keeping the toggle control anchored on screen.
  • WorkGroupSection on web and ThreadWorkLog on mobile no longer manage their own expand/collapse state; overflow is delegated to the feed/timeline presentation layer via deriveMessagesTimelineRows and deriveThreadFeedPresentation.
  • On mobile, disclosure toggles (fold, work group, work row) temporarily suppress end-scroll maintenance for two animation frames via a new suspendEndScrollMaintenanceForDisclosure helper.
  • Behavioral Change: maintainScrollAtEnd is no longer used during disclosure animations on either platform; maintainVisibleContentPosition is used instead, which may change scroll behavior in edge cases.
Macroscope summarized 6809aff.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: 5fab2c50-e611-4399-b3d9-546a58d0008a

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `t3code/legendlist-sticky-scroll`

      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. @@ -289,10 +266,13 @@
      289266 ],
      290267 );
      291268 const rows = useStableRows(rawRows);
      292- const anchoredEndSpace = useMemo(
      293- () =>
      294- resolveChatListAnchoredEndSpace(rows, anchorMessageId, (row) =>
      295- row.kind === "message" ? row.message.id : null,
      296- ),
      297- [anchorMessageId, rows],
      298- );
      269+ const handleAnchorReady = useCallback(() => {
      270+ if (anchorMessageId !== null) {
      271+ onAnchorReady(anchorMessageId);
      272+ }
      273+ }, [anchorMessageId, onAnchorReady]);
      274+ const anchoredEndSpace = useMemo(() => {
      275+ const config = resolveChatListAnchoredEndSpace(rows, anchorMessageId, (row) =>
      276+ row.kind === "message" ? row.message.id : null,
      277+ );
      278+ return config ? { ...config, onReady: handleAnchorReady } : undefined;
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High chat/MessagesTimeline.tsx:278

      @legendapp/list's anchoredEndSpace does not support an onReady property — it only recognizes anchorIndex, anchorOffset, anchorMaxSize, and onSizeChanged. As a result, handleAnchorReady is never called and onAnchorReady never fires, so the parent's anchor-based scroll stabilization after send never executes. Consider using the library's onSizeChanged callback instead of onReady.

      Suggested change
      278- return config ? { ...config, onReady: handleAnchorReady } : undefined;
      278+ return config ? { ...config, onSizeChanged: handleAnchorReady } : undefined;
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/web/src/components/chat/MessagesTimeline.tsx around line 278:
      
      `@legendapp/list`'s `anchoredEndSpace` does not support an `onReady` property — it only recognizes `anchorIndex`, `anchorOffset`, `anchorMaxSize`, and `onSizeChanged`. As a result, `handleAnchorReady` is never called and `onAnchorReady` never fires, so the parent's anchor-based scroll stabilization after send never executes. Consider using the library's `onSizeChanged` callback instead of `onReady`.
    4. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Autofix Details

      Bugbot Autofix prepared a fix for the issue found in the latest run.

      • ✅ Fixed: Stale anchor ready scrolls
        • Added an activeTimelineAnchorRef that tracks the current timelineAnchorMessageId, and the onTimelineAnchorReady callback now rejects any incoming messageId that doesn't match the active anchor, preventing stale onReady callbacks from triggering unwanted scrolls.

      Create PR

      Or push these changes by commenting:

      @cursor push e9fae8e9fa
      Preview (pingdotgg/t3code@e9fae8e9fa)
      diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
      --- a/apps/web/src/components/ChatView.tsx
      +++ b/apps/web/src/components/ChatView.tsx
      @@ -3152,10 +3152,15 @@
           void legendListRef.current?.scrollToEnd?.({ animated });
         }, []);
         const positionedTimelineAnchorRef = useRef<MessageId | null>(null);
      +  const activeTimelineAnchorRef = useRef<MessageId | null>(timelineAnchorMessageId);
      +  activeTimelineAnchorRef.current = timelineAnchorMessageId;
         const onTimelineAnchorReady = useCallback((messageId: MessageId) => {
           if (positionedTimelineAnchorRef.current === messageId) {
             return;
           }
      +    if (activeTimelineAnchorRef.current !== messageId) {
      +      return;
      +    }
           positionedTimelineAnchorRef.current = messageId;
           void legendListRef.current?.scrollToEnd?.({ animated: false });
         }, []);
      You can send follow-ups to the cloud agent here.
    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      4 blocking correctness issues found. Multiple unresolved review comments identify potential bugs in the scroll anchoring implementation, including an onReady callback that may never fire and anchor key mismatches that could cause scroll jumping. These substantive issues require human review before merge.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

      Autofix Details

      Bugbot Autofix prepared fixes for both issues found in the latest run.

      • ✅ Fixed: Anchor restore ignores newer offsets
        • Removed the if (pendingAnchorScrollRestoreRef.current === null) guard so every onSizeChanged call updates the pending offset, ensuring the rAF callback always restores the most recent scroll position.
      • ✅ Fixed: Stale anchor work after thread switch
        • Added cleanup of positionedTimelineAnchorRef, settledTimelineAnchorRef, pendingAnchorScrollRestoreRef, and cancellation of any pending anchorScrollRestoreFrameRef rAF in the activeThread?.id effect, preventing stale scroll operations from applying to a new thread.

      Create PR

      Or push these changes by commenting:

      @cursor push 6f7a63c6f7
      Preview (pingdotgg/t3code@6f7a63c6f7)
      diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
      --- a/apps/web/src/components/ChatView.tsx
      +++ b/apps/web/src/components/ChatView.tsx
      @@ -3209,9 +3209,7 @@
           if (scrollOffset === undefined) {
             return;
           }
      -    if (pendingAnchorScrollRestoreRef.current === null) {
      -      pendingAnchorScrollRestoreRef.current = { messageId, offset: scrollOffset };
      -    }
      +    pendingAnchorScrollRestoreRef.current = { messageId, offset: scrollOffset };
           if (anchorScrollRestoreFrameRef.current !== null) {
             return;
           }
      @@ -3247,6 +3245,13 @@
           isAtEndRef.current = true;
           showScrollDebouncer.current.cancel();
           setShowScrollToBottom(false);
      +    positionedTimelineAnchorRef.current = null;
      +    settledTimelineAnchorRef.current = null;
      +    pendingAnchorScrollRestoreRef.current = null;
      +    if (anchorScrollRestoreFrameRef.current !== null) {
      +      cancelAnimationFrame(anchorScrollRestoreFrameRef.current);
      +      anchorScrollRestoreFrameRef.current = null;
      +    }
           if (planSidebarOpenOnNextThreadRef.current) {
             planSidebarOpenOnNextThreadRef.current = false;
             if (activeThreadRef) {
      You can send follow-ups to the cloud agent here.
      @@ -3152,0 +3197,21 @@
      3197+ animated: true,
      3198+ viewPosition: 0,
      3199+ viewOffset: CHAT_LIST_ANCHOR_OFFSET,
      3200+ });
      3201+ });
      3202+ });
      3203+ }, []);
      3204+ const onTimelineAnchorSizeChanged = useCallback((messageId: MessageId) => {
      3205+ if (settledTimelineAnchorRef.current !== messageId) {
      3206+ return;
      3207+ }
      3208+ const scrollOffset = legendListRef.current?.getState().scroll;
      3209+ if (scrollOffset === undefined) {
      3210+ return;
      3211+ }
      3212+ if (pendingAnchorScrollRestoreRef.current === null) {
      3213+ pendingAnchorScrollRestoreRef.current = { messageId, offset: scrollOffset };
      3214+ }
      3215+ if (anchorScrollRestoreFrameRef.current !== null) {
      3216+ return;
      3217+ }

      Anchor restore ignores newer offsets

      Medium Severity

      When onTimelineAnchorSizeChanged fires multiple times before the scroll restore requestAnimationFrame runs, pendingAnchorScrollRestoreRef only captures the initial offset. This can lead to restoring a stale scroll position, causing incorrect scrolling after subsequent layout shifts, especially during streaming.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 2609ff7a4f92d78938c8ae91f0b78882eebd9014. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -3152,0 +3204,21 @@
      3204+ const onTimelineAnchorSizeChanged = useCallback((messageId: MessageId) => {
      3205+ if (settledTimelineAnchorRef.current !== messageId) {
      3206+ return;
      3207+ }
      3208+ const scrollOffset = legendListRef.current?.getState().scroll;
      3209+ if (scrollOffset === undefined) {
      3210+ return;
      3211+ }
      3212+ if (pendingAnchorScrollRestoreRef.current === null) {
      3213+ pendingAnchorScrollRestoreRef.current = { messageId, offset: scrollOffset };
      3214+ }
      3215+ if (anchorScrollRestoreFrameRef.current !== null) {
      3216+ return;
      3217+ }
      3218+ anchorScrollRestoreFrameRef.current = requestAnimationFrame(() => {
      3219+ anchorScrollRestoreFrameRef.current = null;
      3220+ const pending = pendingAnchorScrollRestoreRef.current;
      3221+ pendingAnchorScrollRestoreRef.current = null;
      3222+ if (pending && settledTimelineAnchorRef.current === pending.messageId) {
      3223+ void legendListRef.current?.scrollToOffset({ offset: pending.offset, animated: false });
      3224+ }

      Stale anchor work after thread switch

      Medium Severity

      The component's scroll anchoring state and pending scroll restoration timers aren't cleared when the active thread changes. This can cause scroll operations from the previous thread to incorrectly apply to the new thread, resulting in unexpected scroll positions.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 2609ff7a4f92d78938c8ae91f0b78882eebd9014. Configure [here](https://www.cursor.com/dashboard/bugbot).
    7. @@ -364,0 +380,21 @@
      380+ nextRows.push({
      381+ kind: "work",
      382+ id: timelineEntry.id,
      383+ createdAt: timelineEntry.createdAt,
      384+ groupedEntries: visibleGroupedEntries,
      385+ });
      386+ } else {
      387+ const groupId = `work-group:${timelineEntry.id}`;
      388+ const expanded = input.expandedWorkGroupIds?.has(groupId) ?? false;
      389+ const hiddenEntries = visibleGroupedEntries.slice(0, -MAX_VISIBLE_WORK_LOG_ENTRIES);
      390+ const visibleEntries = visibleGroupedEntries.slice(-MAX_VISIBLE_WORK_LOG_ENTRIES);
      391+ const renderedEntries = expanded ? [...hiddenEntries, ...visibleEntries] : visibleEntries;
      392+
      393+ for (const workEntry of renderedEntries) {
      394+ nextRows.push({
      395+ kind: "work",
      396+ id: workEntry.id,
      397+ createdAt: workEntry.createdAt,
      398+ groupedEntries: [workEntry],
      399+ });
      400+ }
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium chat/MessagesTimeline.logic.ts:393

      When a work group overflows and is collapsed, the single visible work row uses workEntry.id as its row id. As new work entries arrive, the newest visible entry changes, so the row id changes on every update. Since row.id is passed to LegendList's keyExtractor, this produces remove+insert churn instead of an in-place update, breaking scroll anchoring and visible-content preservation during active work. Consider using a stable id derived from the group anchor for collapsed rows (e.g. work-visible:${timelineEntry.id}:${renderIndex}) and keeping workEntry.id only when expanded.

      Suggested change
      393- for (const workEntry of renderedEntries) {
      394- nextRows.push({
      395- kind: "work",
      396- id: workEntry.id,
      397- createdAt: workEntry.createdAt,
      398- groupedEntries: [workEntry],
      399- });
      400- }
      393+ for (const [renderIndex, workEntry] of renderedEntries.entries()) {
      394+ nextRows.push({
      395+ kind: "work",
      396+ id: expanded ? workEntry.id : `work-visible:${timelineEntry.id}:${renderIndex}`,
      397+ createdAt: workEntry.createdAt,
      398+ groupedEntries: [workEntry],
      399+ });
      400+ }
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/web/src/components/chat/MessagesTimeline.logic.ts around lines 393-400:
      
      When a work group overflows and is collapsed, the single visible `work` row uses `workEntry.id` as its row id. As new work entries arrive, the newest visible entry changes, so the row id changes on every update. Since `row.id` is passed to `LegendList`'s `keyExtractor`, this produces remove+insert churn instead of an in-place update, breaking scroll anchoring and visible-content preservation during active work. Consider using a stable id derived from the group anchor for collapsed rows (e.g. `work-visible:${timelineEntry.id}:${renderIndex}`) and keeping `workEntry.id` only when expanded.
    8. Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.

      There are 5 total unresolved issues (including 2 from previous reviews).

      Autofix Details

      Bugbot Autofix prepared fixes for all 3 issues found in the latest run.

      • ✅ Fixed: Work row keys change at overflow
        • Changed the overflow branch to use the stable timelineEntry.id for the always-visible tail work row so keys remain consistent when crossing the overflow threshold during streaming, preventing LegendList scroll drift.
      • ✅ Fixed: Incorrect log entry pluralization
        • Replaced the naive s suffix with the correct irregular plural form (log entries) matching the already-correct expanded label.
      • ✅ Fixed: Work toggle scroll runs early
        • Wrapped the scroll offset compensation in requestAnimationFrame so LegendList has time to measure newly inserted virtualized rows before the bounding rect delta is computed.

      Create PR

      Or push these changes by commenting:

      @cursor push a0a9e2143b
      Preview (pingdotgg/t3code@a0a9e2143b)
      diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts
      --- a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts
      +++ b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts
      @@ -933,7 +933,10 @@
             expandedWorkGroupIds: new Set(["work-group:work-entry-1"]),
           });
       
      -    expect(collapsedRows.map((row) => row.id)).toEqual(["work-3", "work-toggle:work-entry-1"]);
      +    expect(collapsedRows.map((row) => row.id)).toEqual([
      +      "work-entry-1",
      +      "work-toggle:work-entry-1",
      +    ]);
           expect(collapsedRows.find((row) => row.kind === "work-toggle")).toMatchObject({
             groupId: "work-group:work-entry-1",
             hiddenCount: 2,
      @@ -943,7 +946,7 @@
           expect(expandedRows.map((row) => row.id)).toEqual([
             "work-1",
             "work-2",
      -      "work-3",
      +      "work-entry-1",
             "work-toggle:work-entry-1",
           ]);
           expect(expandedRows.find((row) => row.kind === "work-toggle")).toMatchObject({
      
      diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.ts
      --- a/apps/web/src/components/chat/MessagesTimeline.logic.ts
      +++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts
      @@ -390,10 +390,12 @@
                 const visibleEntries = visibleGroupedEntries.slice(-MAX_VISIBLE_WORK_LOG_ENTRIES);
                 const renderedEntries = expanded ? [...hiddenEntries, ...visibleEntries] : visibleEntries;
       
      -          for (const workEntry of renderedEntries) {
      +          for (let i = 0; i < renderedEntries.length; i++) {
      +            const workEntry = renderedEntries[i]!;
      +            const isStableTail = i === renderedEntries.length - 1;
                   nextRows.push({
                     kind: "work",
      -              id: workEntry.id,
      +              id: isStableTail ? timelineEntry.id : workEntry.id,
                     createdAt: workEntry.createdAt,
                     groupedEntries: [workEntry],
                   });
      
      diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx
      --- a/apps/web/src/components/chat/MessagesTimeline.tsx
      +++ b/apps/web/src/components/chat/MessagesTimeline.tsx
      @@ -236,16 +236,18 @@
               return;
             }
       
      -      const delta = anchorElement.getBoundingClientRect().bottom - anchorBottomBeforeToggle;
      -      if (Math.abs(delta) < 0.5) {
      -        return;
      -      }
      +      requestAnimationFrame(() => {
      +        const delta = anchorElement.getBoundingClientRect().bottom - anchorBottomBeforeToggle;
      +        if (Math.abs(delta) < 0.5) {
      +          return;
      +        }
       
      -      const list = listRef.current;
      -      const currentScroll = list?.getState?.().scroll;
      -      if (list && typeof currentScroll === "number") {
      -        list.scrollToOffset({ offset: currentScroll + delta, animated: false });
      -      }
      +        const list = listRef.current;
      +        const currentScroll = list?.getState?.().scroll;
      +        if (list && typeof currentScroll === "number") {
      +          list.scrollToOffset({ offset: currentScroll + delta, animated: false });
      +        }
      +      });
           },
           [listRef],
         );
      @@ -825,8 +827,8 @@
               </span>
             ) : (
               <span className="font-medium text-foreground/82">
      -          +{row.hiddenCount} previous {labelNoun}
      -          {row.hiddenCount === 1 ? "" : "s"}
      +          +{row.hiddenCount} previous{" "}
      +          {row.hiddenCount === 1 ? labelNoun : row.onlyToolEntries ? "tool calls" : "log entries"}
               </span>
             )}
           </button>
      You can send follow-ups to the cloud agent here.
      @@ -364,0 +380,21 @@
      380+ nextRows.push({
      381+ kind: "work",
      382+ id: timelineEntry.id,
      383+ createdAt: timelineEntry.createdAt,
      384+ groupedEntries: visibleGroupedEntries,
      385+ });
      386+ } else {
      387+ const groupId = `work-group:${timelineEntry.id}`;
      388+ const expanded = input.expandedWorkGroupIds?.has(groupId) ?? false;
      389+ const hiddenEntries = visibleGroupedEntries.slice(0, -MAX_VISIBLE_WORK_LOG_ENTRIES);
      390+ const visibleEntries = visibleGroupedEntries.slice(-MAX_VISIBLE_WORK_LOG_ENTRIES);
      391+ const renderedEntries = expanded ? [...hiddenEntries, ...visibleEntries] : visibleEntries;
      392+
      393+ for (const workEntry of renderedEntries) {
      394+ nextRows.push({
      395+ kind: "work",
      396+ id: workEntry.id,
      397+ createdAt: workEntry.createdAt,
      398+ groupedEntries: [workEntry],
      399+ });
      400+ }
      cursor[bot](GitHub profile, opens in a new tab)commented

      Work row keys change at overflow

      Medium Severity

      Enabling maintainVisibleContentPosition: { data: true } in LegendList causes scroll drift. Dynamic work group row changes trigger list scroll adjustments, which conflict with the parent's scroll anchoring that only responds to size changes.

      Additional Locations (1)
      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e36998c5321c49d45087777c31d0b5381661dcb7. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -834,0 +810,21 @@
      810+ event.currentTarget.closest<HTMLElement>("[data-timeline-row-id]") ?? event.currentTarget;
      811+ ctx.onToggleWorkGroup(row.groupId, anchorElement);
      812+ }}
      813+ >
      814+ <span className="flex size-5 shrink-0 items-center justify-center text-muted-foreground/65">
      815+ <ChevronDownIcon
      816+ className={cn(
      817+ "size-3.5 shrink-0 opacity-70 transition-transform duration-200",
      818+ row.expanded && "rotate-180",
      819+ )}
      820+ />
      821+ </span>
      822+ {row.expanded ? (
      823+ <span className="font-medium text-foreground/82">
      824+ Show fewer {row.onlyToolEntries ? "tool calls" : "log entries"}
      825+ </span>
      826+ ) : (
      827+ <span className="font-medium text-foreground/82">
      828+ +{row.hiddenCount} previous {labelNoun}
      829+ {row.hiddenCount === 1 ? "" : "s"}
      830+ </span>
      cursor[bot](GitHub profile, opens in a new tab)commented

      Incorrect log entry pluralization

      Low Severity

      For non–tool-only work groups, the collapsed toggle label builds plurals by appending s to log entry, which yields log entrys when hiddenCount is greater than one. The expanded label correctly uses log entries, so the collapsed copy is grammatically wrong for mixed work logs.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e36998c5321c49d45087777c31d0b5381661dcb7. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -233,7 +234,15 @@
      233- return () => {
      234- window.cancelAnimationFrame(firstFrameId);
      235- if (secondFrameId !== null) {
      236- window.cancelAnimationFrame(secondFrameId);
      234+
      235+ if (anchorBottomBeforeToggle === null || !anchorElement) {
      236+ return;
      237237 }
      238- };
      239- }, [foldToggleSettling]);
      238+
      239+ const delta = anchorElement.getBoundingClientRect().bottom - anchorBottomBeforeToggle;
      240+ if (Math.abs(delta) < 0.5) {
      241+ return;
      242+ }
      243+
      244+ const list = listRef.current;
      245+ const currentScroll = list?.getState?.().scroll;
      246+ if (list && typeof currentScroll === "number") {
      247+ list.scrollToOffset({ offset: currentScroll + delta, animated: false });
      248+ }

      Work toggle scroll runs early

      Medium Severity

      Work-group expand/collapse applies scrollToOffset in the click handler right after flushSync, but LegendList may not have measured newly inserted virtualized rows yet. The prior useLayoutEffect-based compensation ran after layout; here a zero or stale delta skips correction or applies the wrong offset, so the toggle row can jump when showing or hiding tool calls.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e36998c5321c49d45087777c31d0b5381661dcb7. Configure [here](https://www.cursor.com/dashboard/bugbot).
    9. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      There are 6 total unresolved issues (including 5 from previous reviews).

      Autofix Details

      Bugbot Autofix prepared a fix for the issue found in the latest run.

      • ✅ Fixed: Work toggle ignores scroll settling
        • Added the same foldToggleSettling guard (set true, cancel pending frames, schedule two-frame reset) to onToggleWorkGroup that onToggleTurnFold already uses, so maintainScrollAtEnd is suppressed during work group expansion/collapse.

      Create PR

      Or push these changes by commenting:

      @cursor push a14e381e51
      Preview (pingdotgg/t3code@a14e381e51)
      diff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsx
      --- a/apps/mobile/src/features/threads/ThreadFeed.tsx
      +++ b/apps/mobile/src/features/threads/ThreadFeed.tsx
      @@ -1299,6 +1299,13 @@
         }, []);
       
         const onToggleWorkGroup = useCallback((groupId: string) => {
      +    setFoldToggleSettling(true);
      +    if (foldSettleFrameRef.current !== null) {
      +      cancelAnimationFrame(foldSettleFrameRef.current);
      +    }
      +    if (foldSettleSecondFrameRef.current !== null) {
      +      cancelAnimationFrame(foldSettleSecondFrameRef.current);
      +    }
           setInteractionState((current) => ({
             ...current,
             expandedWorkGroups: {
      @@ -1306,6 +1313,13 @@
               [groupId]: !(current.expandedWorkGroups[groupId] ?? false),
             },
           }));
      +    foldSettleFrameRef.current = requestAnimationFrame(() => {
      +      foldSettleSecondFrameRef.current = requestAnimationFrame(() => {
      +        setFoldToggleSettling(false);
      +        foldSettleFrameRef.current = null;
      +        foldSettleSecondFrameRef.current = null;
      +      });
      +    });
         }, []);
       
         const onToggleWorkRow = useCallback((rowId: string) => {
      You can send follow-ups to the cloud agent here.
    10. @@ -1182,12 +1190,20 @@
      11821190 }),
      11831191 [
      11841192 copiedRowId,
      1185- expandedWorkGroups,
      11861193 expandedWorkRows,
      11871194 iconSubtleColor,
      11881195 markdownStyles,
      11891196 reviewCommentColors,
      11901197 userBubbleColor,
      11911198 ],
      11921199 );
      1200+ const expandedWorkGroupIds = useMemo(() => {
      1201+ const ids = new Set<string>();
      1202+ for (const [groupId, expanded] of Object.entries(expandedWorkGroups)) {
      1203+ if (expanded) {
      1204+ ids.add(groupId);
      1205+ }
      1206+ }
      1207+ return ids;
      1208+ }, [expandedWorkGroups]);
      11931209 const presentedFeed = useMemo(
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium threads/ThreadFeed.tsx:1209

      Passing expandedWorkGroupIds to deriveThreadFeedPresentation causes an expanded activity-group to be split into multiple single-activity entries. Each of those entries is rendered by renderFeedEntry as its own ThreadWorkLog, which adds the "work log" header and outer margins (-mx-1 mb-3) per entry. For groups containing non-tool rows, this repeats the header on every row and inserts extra spacing between rows that should appear as one contiguous log, breaking the timeline layout. Consider keeping an expanded group as a single activity-group entry containing all activities so it renders as one ThreadWorkLog.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/mobile/src/features/threads/ThreadFeed.tsx around line 1209:
      
      Passing `expandedWorkGroupIds` to `deriveThreadFeedPresentation` causes an expanded `activity-group` to be split into multiple single-activity entries. Each of those entries is rendered by `renderFeedEntry` as its own `ThreadWorkLog`, which adds the "work log" header and outer margins (`-mx-1 mb-3`) per entry. For groups containing non-tool rows, this repeats the header on every row and inserts extra spacing between rows that should appear as one contiguous log, breaking the timeline layout. Consider keeping an expanded group as a single `activity-group` entry containing all activities so it renders as one `ThreadWorkLog`.
    11. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      There are 6 total unresolved issues (including 5 from previous reviews).

      Fix All in Cursor

      Bugbot Autofix prepared a fix for the issue found in the latest run.

      • ✅ Fixed: Work row anchor key mismatch
        • Updated the single-row path in appendPresentedFeedEntry to use the first visible activity's id as the entry id, ensuring the scroll anchor key set by onToggleWorkRow matches the LegendList entry id.

      Create PR

      Or push these changes by commenting:

      @cursor push c857557976
      Preview (pingdotgg/t3code@c857557976)
      diff --git a/apps/mobile/src/lib/threadActivity.ts b/apps/mobile/src/lib/threadActivity.ts
      --- a/apps/mobile/src/lib/threadActivity.ts
      +++ b/apps/mobile/src/lib/threadActivity.ts
      @@ -1158,6 +1158,7 @@
         if (activities.length <= MAX_VISIBLE_WORK_LOG_ENTRIES) {
           result.push({
             ...entry,
      +      id: activities[0]!.id,
             activities,
           });
           return;
      You can send follow-ups to the cloud agent here. Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 6809aff1e2a195cef8e6cc3a492327662c1b2e5c. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -1288,10 +1340,12 @@
      1340+ expandedWorkGroups: {
      1341+ ...current.expandedWorkGroups,
      1342+ [groupId]: !(current.expandedWorkGroups[groupId] ?? false),
      1343+ },
      1344+ }));
      1345+ },
      1346+ [suspendEndScrollMaintenanceForDisclosure],
      1347+ );
      12881348
      1289- const onToggleWorkRow = useCallback((rowId: string) => {
      1290- setInteractionState((current) => ({
      1291- ...current,
      1292- expandedWorkRows: {
      1293- ...current.expandedWorkRows,
      1294- [rowId]: !(current.expandedWorkRows[rowId] ?? false),
      1295- },
      1296- }));
      1297- }, []);
      1349+ const onToggleWorkRow = useCallback(
      1350+ (rowId: string) => {
      1351+ suspendEndScrollMaintenanceForDisclosure(rowId);

      Work row anchor key mismatch

      Medium Severity

      Expanding work-log rows sets a scroll anchor using the specific row's ID, but the LegendList's entry.id for grouped activities often differs. This mismatch prevents shouldRestoreVisibleContentPosition from finding the anchored item, causing scroll anchoring to fail and the viewport to jump.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 6809aff1e2a195cef8e6cc3a492327662c1b2e5c. Configure [here](https://www.cursor.com/dashboard/bugbot).
    12. @@ -1261,0 +1287,21 @@
      1287+ setDisclosureToggleSettling(true);
      1288+ if (foldSettleFrameRef.current !== null) {
      1289+ cancelAnimationFrame(foldSettleFrameRef.current);
      1290+ }
      1291+ if (foldSettleSecondFrameRef.current !== null) {
      1292+ cancelAnimationFrame(foldSettleSecondFrameRef.current);
      1293+ }
      1294+ foldSettleFrameRef.current = requestAnimationFrame(() => {
      1295+ foldSettleSecondFrameRef.current = requestAnimationFrame(() => {
      1296+ disclosureAnchorKeyRef.current = null;
      1297+ setDisclosureToggleSettling(false);
      1298+ foldSettleFrameRef.current = null;
      1299+ foldSettleSecondFrameRef.current = null;
      1300+ });
      1301+ });
      1302+ }, []);
      1303+
      1304+ const shouldRestoreVisibleContentPosition = useCallback((entry: ThreadFeedEntry) => {
      1305+ const disclosureAnchorKey = disclosureAnchorKeyRef.current;
      1306+ return disclosureAnchorKey === null || entry.id === disclosureAnchorKey;
      1307+ }, []);

      🟡 Medium threads/ThreadFeed.tsx:1304

      onToggleWorkRow anchors scroll restoration to the activity rowId (i.e. activity.id), but the list item rendered for a work-log group uses the group entry's id, not the individual activity id. So when a row inside a work-log group is expanded, shouldRestoreVisibleContentPosition compares the group entry id against the activity id and never matches, causing the chat to jump instead of preserving the tapped row's position. Consider also checking entry.activities for a matching activity id when the entry is an activity-group.

      -  const shouldRestoreVisibleContentPosition = useCallback((entry: ThreadFeedEntry) => {
      -    const disclosureAnchorKey = disclosureAnchorKeyRef.current;
      -    return disclosureAnchorKey === null || entry.id === disclosureAnchorKey;
      -  }, []);
      +  const shouldRestoreVisibleContentPosition = useCallback((entry: ThreadFeedEntry) => {
      +    const disclosureAnchorKey = disclosureAnchorKeyRef.current;
      +    if (disclosureAnchorKey === null || entry.id === disclosureAnchorKey) {
      +      return true;
      +    }
      +    if (entry.type === "activity-group") {
      +      return entry.activities.some((activity) => activity.id === disclosureAnchorKey);
      +    }
      +    return false;
      +  }, []);
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/mobile/src/features/threads/ThreadFeed.tsx around lines 1304-1307:
      
      `onToggleWorkRow` anchors scroll restoration to the activity `rowId` (i.e. `activity.id`), but the list item rendered for a work-log group uses the group entry's `id`, not the individual activity id. So when a row inside a work-log group is expanded, `shouldRestoreVisibleContentPosition` compares the group entry id against the activity id and never matches, causing the chat to jump instead of preserving the tapped row's position. Consider also checking `entry.activities` for a matching activity id when the entry is an `activity-group`.
    13. juliusmarminge merged this24abab7

    14. juliusmarminge closed this

Sign in to join this conversation.