Skip to content

Fix follow-up scroll jumps in long threads - #1750

Closed
ymichael wants to merge 1 commit into
mainfrom
bb/fix-intermittent-follow-up-message-truncation-thr_vvsyycy72x
Closed

ymichael wants to merge 1 commit into
mainfrom
bb/fix-intermittent-follow-up-message-truncation-thr_vvsyycy72x

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Summary

  • clear stale older-page scroll anchors when the reader explicitly returns to the bottom
  • snap newly submitted user rows and the working indicator into the timeline so bottom restoration happens before paint
  • preserve animated assistant streaming while adding regressions for both stale-anchor paths

Testing

  • pnpm exec turbo run test --filter=@bb/app --force -- --run src/components/ui/bottom-anchored-scroll-body.scroll-preservation.test.tsx src/components/ui/height-transition.test.tsx src/components/thread/timeline/ThreadTimelineRows.actions.test.tsx
  • pnpm exec turbo run typecheck --filter=@bb/app
  • reproduced with 856 mounted rows using dev-browser; the former bottom-to-802-to-bottom scroll excursion no longer occurs

AGENT GENERATED: by GPT-5

@bb-slop-cop

bb-slop-cop Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

I am the SlopCop. I am reviewing this change for security, code quality, performance, architecture, and end-to-end behavior.

// Reaching the bottom after the native-anchor guard above is an
// authoritative bottom position. A pending prepend restore must not
// survive and reinterpret a later follow-up as older-page growth.
cancelPendingPrependAnchor();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 slopcop/review — Real user scrolls bypass this cancellation.

The guard above returns while wheel, touch, keyboard, or pointer intent is recent. A manual scroll to the bottom therefore never reaches this new cancellation. The new test fires only a scroll event, so it misses this path. Later height growth can still apply the stale prepend anchor. Check the bottom position before the guard, or cancel the anchor inside the guarded bottom path.

pendingScrollRestoreRef.current = null;
}, []);

const cancelPendingPrependAnchor = useCallback(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 slopcop/review — Failed older-page loads leave the stale anchor active.

The loader captures a prepend anchor before each request. Its rejection path only disables automatic loads. This cancel operation stays private, so that path cannot clear the anchor. A later timeline height increase can then look like older-page growth and move the viewport. Provide a paired cancel operation or a request-scoped anchor transaction, and cancel it when the load fails.

let lastWidth: number | null = null;
let pendingVisibilitySnap = false;
const snapState: SnapState = { savedDuration: null, restoreFrame: null };
applyHeight(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 slopcop/review — Exit animations now snap too.

This call also handles visible changes from true to false. applyHeight treats that decrease as a snap and sets transitionDuration to 0s. This disables both the height and opacity exit transitions. The old code assigned the height directly, and snapOnEnter only promises an entry snap. Keep the direct assignment for normal exits, or pass a snap rule that affects entry only. Add an exit test because the new test covers only entry.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

Plain-English summary

This change prevents long threads from jumping after a user loads older messages and sends a follow-up.

It clears old scroll positions and adds immediate layout updates for new prompts and work indicators.

Findings

I found three medium issues.

  • A manual bottom scroll can bypass the new stale-anchor cancellation.
  • A failed older-page request can keep its stale anchor active.
  • Every HeightTransition exit now skips its height and opacity animation.

I left an inline comment for each issue.

The security review found no security, privacy, or trust-boundary risks.

The scan found no exact copy of this change. However, two height components repeat observer, visibility, snap, and cleanup logic.

A shared measured-height controller could reduce future policy differences after these fixes.

Validation

  • All 52 focused tests passed.
  • The @bb/app type check passed.
  • All GitHub checks passed.
  • The browser test loaded 191 rows and then sent a follow-up after an older-page load.
  • The viewport stayed within one pixel of the bottom during that primary path.

The synthetic fixture rejected provider execution because its workspace was unavailable. The optimistic user-row path still ran.

Please address the three inline findings before merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant