Repository navigation
fix(threads): keep the reading position when older rows are measured - #721
Merged
Merged
Conversation
Scrolling up a long thread could snap the view back to the end or jump it by hundreds of rows as older rows were measured. - Re-estimated rows above can shorten the scroll range below the reading position. The browser clamps to the new end; during a gesture that clamp counted as the reader reaching the end and turned following back on. A clamp is now layout: the anchor is restored. - A smooth scroll (wheel, Page Up) moves ahead of its scroll events. When settle took such a scroll in after a re-estimate, it recaptured the anchor from rows not yet corrected, often finding none. The anchor now moves by the reader's distance and settle corrects the rest in the same frame. Related: #687, #707
nixuuu
force-pushed
the
fix/thread-scroll-anchor
branch
from
November 14, 2026 13:29
70706db to
3f88136
Compare
nixuuu
added a commit
that referenced
this pull request
Nov 14, 2026
Opening or closing mobile tool details, tool groups and work segments can jump to unrelated history. This change computes an absolute scroll target from the tapped header's position within its actual inverted FlatList cell, so repeated measurements keep the header under the finger instead of accumulating scroll corrections. Fixes: #554 Related: #689, #701, #721 ### Root cause and evidence - Extracted the supplied 11.24-second iPhone recording at 12 fps (135 frames). Around 0.9–1.1 seconds the view changes from the latest “Worked for 10s” segment to earlier “Worked for 19s” history, back to the expanded segment and then to unrelated newer content. The composer/navigation remain fixed while timeline content moves in both directions. Later toggles also move surrounding messages, rather than only the disclosed body. The recording cannot establish native offsets, React render counts or which native anchor ran. - The list is an inverted native FlatList, virtualized by **turn**, with variable measured heights; no FlashList, estimated `getItemLayout` or fold-dependent turn keys. #689 retains fold choices outside virtual cells. #701's `ui/Accordion` is used by scheduled-task settings, not the timeline. Timeline work/groups use the height animation from #554; individual item details mount directly and share its anchor hook. - In pinned Reanimated 4.7.1, native `measure` reads `UIManager::getRelativeLayoutMetrics`, whose page coordinates include the Fabric scroll-state checkpoint. Native `scrollTo` and the checkpoint are not one atomic measurement. The old frame callback subtracted `pageY - originalPageY` from an optimistically updated offset every frame. Re-reading an unchanged checkpoint therefore compounded the same correction. This is a code-established failure path consistent with the recording, not a device reproduction. - React Native 0.88.1's iOS maintain-visible implementation captures its first-visible frame before mounting and applies it afterward. Disabling then re-enabling the prop can apply the old frame on the enabling commit. Keep it configured, suppress autoscroll during the manual session, and keep iOS keyboard chats configured without zero-target autoscroll. ### Implementation Measure both header and actual cell on UI. Their page-coordinate difference cancels the common scroll checkpoint; cell layout Y/height locate the header within inverted content. Preserve the session's initial offset/position and derive each target from that origin. Identical layout always gives an identical target, even if scroll events are delayed or native cell anchoring also adjusts the offset. Changes before the turn are included; height added above a nested header cancels naturally. Use `createAnimatedComponent(FlatList)` with a stable component identity, since Reanimated's convenience `Animated.FlatList` unconditionally replaces `CellRendererComponent`. Preserve inversion styles, focus and list layout notifications. Keep disclosure animation, retained children, turn keys, manual choices and drag/new-tap cancellation. The physical scroll range still limits anchoring when the remaining content is shorter than the viewport. ### Validation - `nice bun install`, `nice bun run gen:check`, full `nice bun run typecheck`, `nice bun run lint`, `nice bun run format` and `nice bun run format:check`: passed. All temporary files use a private `/var/tmp` directory. - Focused tests: `nice bun test tests/integration/mobile-disclosure-anchor.test.ts tests/integration/thread-scroll.test.ts`: **7 passed, 40 assertions**. Three new pure geometry tests cover stale/repeated scroll checkpoints, expansion/collapse, nested/preceding-cell changes, reversal and iOS/Android lower bounds. No UI suites. - Final iOS and Android Hermes exports passed, run sequentially with `nice`. - Production-profile EAS fingerprints were generated against clean base `dev` and the implementation: **unchanged**. iOS `83794f069934a7374461427d89b8d008cec19d97`; Android `141ef4e8c825ee4fc5d22c499402b284741b0970`. iOS also matches the last delivered nightly store build. No dependencies, native configuration or native sources changed. - Native device checks are blocked by the supplied device-host failure. Export/test success does not prove native frame pacing, rendered-cell counts or phone anchoring. No E2E/UI suites, full integration suite or web build were run for this mobile-only change. ### Re-test on iPhone and Android Published directly to **nightly** by the implementing agent without authorization, from `0601f2ea4bf96feb70c1f920420ae6d3730cc31b`, for both existing runtimes. The OTA keeps the last delivered JS release version `0.3.0-nightly.12`; its message is `Canopy v0.3.0-nightly.12 + disclosure anchor fix (0601f2e)`. Publishing reported success and returned the same runtime fingerprints checked above: - iOS update `01a1daa3-fa24-7e7d-8bed-1b03e10041a7`, group `62c3742a-aabb-4860-9a44-6bcc754df97b`. - Android update `01a1daa3-fa24-7f83-a58e-e0cd0ce3ed78`, group `e0c51f88-99a6-4b60-937e-02c19a9257dc`. No native build, new release tag or release-version commit was created. Release preparation files were restored afterward. Merge this PR so subsequent scheduled nightly releases retain the fix. On the phone, use Settings → Updates to fetch/apply the new nightly OTA before these checks: 1. In a long thread, scroll to the middle and put a completed work header near the top, middle and bottom of the viewport. Expand/collapse it ten times, then repeat for its tool group and a tall individual command/tool result. The tapped header and messages above it must stay at the same screen Y; only content below changes. No unrelated history may flash into view. 2. Repeat at the latest turn while following, with short and very tall results. Rapidly reverse a disclosure before its 250 ms animation ends and tap another header mid-transition. The new tap must own the anchor. A physically too-short collapsed thread may reach its scroll boundary. 3. Repeat with keyboard open/closed and system Reduce Motion on/off. Drag during expansion: the drag must take over immediately, and programmatic corrections must not fold the composer. Check light/dark and narrow/wide layouts with long labels. 4. Load older history, toggle again, switch away/back, then use “Jump to latest” and receive a new message. Retained choices/history must survive, the reading position must hold, and explicit following must still work. Also check bot chat scrolling/keyboard because it shares the base list wrapper. Copy audit (docs/copy.md §8): no UI text changed. Relevant Polish docs updated. Temporary frames, exports and logs are removed after delivery.
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Scrolling up a long thread sometimes moved the view by itself: it snapped back to the end, or jumped by hundreds of pixels to rows far above. It happened over the margin too, with no visuals (found while testing #707, reproducible on
dev).Root cause
Older rows are re-estimated as rows are measured (group averages). Two paths then lost the reading position:
scrollTopto the new end. While a wheel/key gesture lease is active,ScrollIntentlabelled that clampreaderwith distance 0, sofollowingAfterScrollturned following back on and the view snapped to the end.scrollevents. Whensettle(afterpadTopchanged) took such a pending scroll in,onscrollrecaptured the anchor from rows that the re-estimate had just moved, often by thousands of px. Often no row was on screen: the anchor was dropped, and the window then followed the estimate, about 165 rows away.Fix
scrollOrigin(scroll.ts): a position clamped to the end of a range that shrank below the last position isunattributed(layout).settlerestores the anchor, in the same frame.followScroll(feed-anchor.ts): a scroll taken in bysettle(no event) moves the existing anchor by the reader's distance, instead of reading the rows on screen.settleAnchorthen corrects the layout part in the same frame. Native scroll events still recapture as before.client-performance.mdhas the measurement lessons (frames with no shared row are jumps;layout-shiftalso counts same-frame compensated corrections; check smooth wheel and Page Up).Measurements
Private bench stack (
scripts/bench/client-stack.ts), Chromium with smooth scrolling and--site-per-process. 120 steps per run, starting at the end. A probe samples every frame after paint (rAF, then a task) and compares the rows on screen with the previous frame. A jump is a frame where shared rows move against the scroll or further than one input step. A teleport is a frame with no shared row: a snap to the end or a leap to another part of the thread./dev/long-thread?turns=1000(all 5000 rows loaded, mostly estimated):dev: teleports (size)Seeded 1000-turn thread page (history paged in through the gateway): wheel and trackpad-like runs had no jumps on
deveither. Paging keeps the estimated region small. Page Up had 5–6 teleports and 3–6 jumps (max 528–597 px) ondev, 0 and 0 on this branch, at both widths.With smooth scrolling off,
devPage Up had no jumps: the second path needs a smooth scroll. Real mouse wheels are smooth-animated on Linux and Windows, so the reported 360–400 px wheel jumps are likely this path. Synthetic CDP wheel events in headless Chromium are not animated, so they only reproduced the first path.layout-shiftentries are not a jump metric here: a 3 px row growth withscrollTop += 3in the same frame also produces them on a plain test page, more during smooth scrolling.Browser check
On a second machine with a fresh clone of this branch (own ports, own container, cleaned up afterwards), I ran the same 15-run matrix on both pages. It covered wheel −40 px and −100 px, trackpad-like and Page Up, at 1280 × 900 and 390 × 844. All runs had 0 teleports and 0 jumps, and visual travel matched input (e.g. 12000 of 12000 px). Page Up now travels about 75000 px over 120 presses, against 62000 on
dev(the view no longer falls back). Cached threads (#687): scrolled up, switched to another thread and back. The same row returned at the same offset. No visual change, so no light/dark difference.After rebasing onto
devwith #707, the same 16 runs (both pages, both widths, wheel −40 and −100 px, trackpad-like, Page Up) again had 0 teleports and 0 jumps. A clamp still wins over #707's hovered-frame attribution: a clamp is layout even while the pointer is over a visual.Checks
bun install,gen:check,typecheck,lint,format:check, focused test (tests/integration/thread-scroll.test.ts, the clamp origin), web build.Copy audit (docs/copy.md §8)
No UI text changed.
Related: #687, #707