Skip to content

Fix iOS scroll jumps while loading windowed history - #5022

Merged
ymichael merged 3 commits into
mainfrom
bb/fix-abrupt-scrolling-jumps-on-ios-thr_pzbsbkuecv
Oct 6, 2026
Merged

ymichael merged 3 commits into
mainfrom
bb/fix-abrupt-scrolling-jumps-on-ios-thr_pzbsbkuecv

Conversation

@ymichael

@ymichael ymichael commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Loading older messages could move the reader to a different part of the conversation. The saved anchor could outlive its request and apply on an unrelated render. Full-app reproduction also exposed two additional causes: inserting a page during iOS touch/momentum scrolling, and subsequent windowed-row measurements changing the virtual content height. Native Safari swipes on an 80-turn fixture jumped from around Checkpoint 74 to Checkpoint 3 and cascaded through multiple older pages.

What changed

Fetch older history ahead of time, then commit after touch ends and scrolling has been idle for 200 ms. Capture the current visible row immediately before the synchronous page update and pin it in the existing timeline virtualizer. Preserve its screen coordinate while virtual heights settle, for up to 500 ms; new touch, pointer, wheel, keyboard, or explicit navigation immediately releases that hold. Use the height delta fallback when there is no measurable row.

Scope anchors to their update and clear them on failure/cancellation instead of consuming them on unrelated shell renders. Keep request overlap protection and abort a deferred commit when the load control unmounts.

How you verified

  • Full source app, server pagination, real timeline renderer/windowing, and native Maestro swipes in iOS 26.5 Simulator Safari. Used an isolated database with 80 synthetic turns. This supersedes the initial isolated non-windowed reproduction; no physical iPhone was used.
  • Tested the first older page, which transitions the compact initial history into windowing, and a subsequent page with windowing already active. Each added 40 rows with 21 mounted afterward. Visible anchors stayed at exactly the same screen coordinates: Checkpoint 73 at -100 px and Checkpoint 53 findings at -119 px (0 px drift for each). The second test started from a scripted reading offset and triggered pagination with a native swipe.
  • Native composer focus and keyboard dismissal also preserved the reading position. Captured before/after recordings and screenshots, plus DOM telemetry. Evidence is linked in the originating BB thread.
  • 122 relevant tests passed across 11 files, covering scroll preservation, request success/failure/empty/cancellation, delayed commits, virtual measurements, interruption by new user input, final-page unmount, windowing, and pending-interaction/footer behavior. New regressions fail against the earlier PR implementation and pass with this fix.
  • pnpm exec turbo run lint typecheck --filter=@bb/app passed (249 existing lint warnings, no errors); git diff --check passed.

Rebase and CI follow-up

Rebased onto origin/main at e3b8caa22c. The Windows app-3 failure came from a test assigning scrollTop without dispatching user scroll input while initial bottom-restoration animation frames were still queued. Settle initialization, dispatch wheel and scroll events, and advance fake timers through pagination and subsequent frames so the last-page reading-position assertion is deterministic.

Verified 397 tests across 42 files with shuffled seed 4721 and two workers; app lint/typecheck passed (250 existing warnings, no errors). The original test race was reproduced locally before the fixture repair. Production behavior is unchanged by this follow-up.

Fixes #4793

AGENT GENERATED

@ymichael ymichael changed the title Fix scroll jumps from stale older-message anchors Fix iOS scroll jumps while loading windowed history Oct 6, 2026
@ymichael
ymichael force-pushed the bb/fix-abrupt-scrolling-jumps-on-ios-thr_pzbsbkuecv branch from b28fd35 to 25d3605 Compare October 6, 2026 18:10
@ymichael
ymichael merged commit 9cb923a into main Oct 6, 2026
41 checks passed
@ymichael
ymichael deleted the bb/fix-abrupt-scrolling-jumps-on-ios-thr_pzbsbkuecv branch October 6, 2026 18:23
ymichael added a commit that referenced this pull request Oct 8, 2026
…5231)

## Human comments

## What was wrong

#5022 made the timeline wait to insert a fetched older page until
scrolling had been idle for 200 ms, with no touch in progress. The wait
applies on every platform. Desktop wheel and trackpad scrolling
(including macOS momentum) keeps firing `scroll` events, so the
prefetched page stays uncommitted for as long as the reader keeps
scrolling. `isLoadingOlderTimelineRows` stays true until the commit, so
readers scrolling up now reach the "Loading older messages…" indicator
and stall there. Before #5022, rows were inserted as soon as the
response arrived, so the 600 px prefetch margin usually hid the load.
Only one load can be pending at a time, so the next page also can't
prefetch while the reader keeps scrolling.

## What changed

Reverts #5022 (9cb923a) in full. One conflict in
`useThreadTimelineController.ts` was resolved by keeping #5068's removal
of the `useRef` import. This brings back the behaviour #5022 fixed: the
iOS momentum-scroll jumps and the stale scroll-anchor yank reported in
#4793.

## How you verified

- `pnpm exec turbo run typecheck lint --filter=@bb/app` passes: 0
errors, 250 existing warnings.
- Timeline, bottom-anchored scroll body, pending-interaction and
user-question suites in `apps/app`: 447 tests in 48 files pass.
- Not manually scroll-tested in the app.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: qa <qa@x>
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.

Chat view gets displaced when a stale "load older rows" scroll anchor is consumed on a later commit

1 participant