#6516 · Detached touch targets leave scroll corrections pending
PARTIALLY REPRODUCED · Root-cause confidence: high at the scroll-keeper boundary
1. TL;DR
The component can leave newly inserted older rows above the reachable scroll range when its touch-start element disappears before the touch ends. A new test drives the real ScrollPositionKeeper with the repository's existing deterministic DOM layout harness. With an attached target, the correction flushes to scrollTop 320; with a detached target, scrollTop remains 0 and the content retains a negative 320px transform. The same agent repeated this result in a second clean checkout of the same trusted main commit. Native WKWebView gestures, real pagination, and the reported persistence until reopening were not exercised, so this is a partial reproduction of the device report rather than a claim of complete iOS verification.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| Completing a touch on a removed descendant can strand the correction. | Verified | Both clean runs retain translate3d(0, -320px, 0) after one second of simulated settle time. |
| Completing the same touch on a connected descendant succeeds. | Verified | The paired control reaches scrollTop 320 and clears the transform. |
| iOS uses deferred writes, and the older-page indicator can unmount. | Verified in source | The client enables deferral through isIOSWebKit; ThreadTimelineSurface conditionally mounts LoadOlderMessages. |
| Native gesture pointer cancellation bypasses the pointer-up fallback. | Source behavior verified; native event sequence unverified | The touch pointer handler returns for pointercancel. No iOS device or simulator was used. |
| The problem occurs in the reported release and lasts until reopening; requests complete correctly. | Unverified | No production data, logs, reported thread, or historical runtime were accessed. |
3. Environment
- Public repository get-bb/bb, trusted main commit
24a5b76866621c2e093787219c7e605bcb0cefc1; fetched from the repository directly and matched to origin/main. - Linux 4.19.0-gvisor; Node v22.19.0; pnpm 9.15.0; Vitest with jsdom and the existing fake-flow-layout helper.
- Two detached temporary git worktrees,
$WORK/baseand$WORK/verify, each installed with the frozen lockfile and built through Turbo. - No live BB server, ports, runtime data directories, provider processes, credentials, or user sessions were needed.
- Browser Automation local/headless launch was attempted on the current host, but no Chrome/Chromium executable was available. No browser or dependency was installed.
4. Minimal reproduction
- Use a clean checkout of the base commit. Install and build the existing repository:
git fetch origin main git switch --detach 24a5b76866621c2e093787219c7e605bcb0cefc1 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build
The first base build encountered a pre-existing plugin build-order race: the GitHub plugin could not resolve SDK runtime files while they were still being built. Repeating the same build completed all 72 tasks; the second checkout's build completed all 72 tasks without that failure. - Save the attached reproduction test as
apps/app/src/components/ui/issue-6516-repro.test.ts. - Run:
pnpm exec turbo run test --filter=@bb/app -- src/components/ui/issue-6516-repro.test.ts --silent=false
Expected: both cases pass, both report scrollTop 320 and an empty transform. Actual: the connected-target control passes, and the removed-target case fails for the intended reason:{"removed":false,"scrollTop":320,"transform":""} {"removed":true,"scrollTop":0,"transform":"translate3d(0, -320px, 0)"} AssertionError: expected +0 to be 320 Tests 1 failed | 1 passed (2)An exit status of 1 is the expected reproduction result, not an installation failure.
Visual verification limitation: no screenshot is supplied because no real browser or iOS renderer ran. The measured DOM state is from the real keeper plus a deterministic layout helper, not a screenshot of the full timeline. Browser Automation reported: Install Chrome/Chromium on this host or link its executable at the plugin data runtime/chrome path.
Complete reproduction test
// @vitest-environment jsdom
import { afterEach, expect, it, vi } from "vitest";
import { installFakeFlowLayout, setFakeHeight } from "@/test/fake-flow-layout";
import { ScrollPositionKeeper } from "./scroll-position-keeper";
let cleanup = () => {};
afterEach(() => {
cleanup();
vi.useRealTimers();
document.body.replaceChildren();
});
it.each([false, true])("releases a prepended-page correction after touch completion (removed target: %s)", (removed) => {
vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout", "performance"] });
const viewport = document.createElement("div");
const content = document.createElement("div");
const target = document.createElement("button");
const items = document.createElement("div");
content.append(target, items);
viewport.append(content);
document.body.append(viewport);
const layout = installFakeFlowLayout({ scrollElement: viewport, viewportHeight: 500 });
const makeRow = (index: number) => {
const row = document.createElement("div");
row.dataset.timelineRowId = `entry-${index}`;
setFakeHeight(row, 160);
return row;
};
items.append(...Array.from({ length: 12 }, (_, index) => makeRow(index)));
const keeper = new ScrollPositionKeeper({
bottomThresholdPx: 4,
deferWritesWhileScrolling: true,
getContentElement: () => content,
getFloorElement: () => null,
getFooterElement: () => null,
getScrollElement: () => viewport,
getTopLevelRows: () => items.querySelectorAll<HTMLElement>("[data-timeline-row-id]"),
initiallyAttached: false,
});
const disconnect = keeper.connect(viewport);
cleanup = () => { disconnect(); layout.restore(); };
layout.userScrollTo(40);
layout.userScrollTo(0);
vi.advanceTimersByTime(500);
target.dispatchEvent(new TouchEvent("touchstart", { bubbles: true }));
if (removed) target.remove();
items.prepend(makeRow(-2), makeRow(-1));
keeper.reconcile();
expect(content.style.transform).not.toBe("");
target.dispatchEvent(new TouchEvent("touchend", { bubbles: true }));
vi.advanceTimersByTime(1000);
console.log(JSON.stringify({ removed, scrollTop: viewport.scrollTop, transform: content.style.transform }));
expect(viewport.scrollTop).toBe(320);
expect(content.style.transform).toBe("");
});
5. Root cause
apps/app/src/components/ui/scroll-position-keeper.ts:205 sets touching on touchstart and clears it in endTouch. The touch-end and cancellation listeners are registered only on the scroll element (apps/app/src/components/ui/scroll-position-keeper.ts:281). Once a descendant is detached, an event dispatched to that descendant no longer traverses the former scroll ancestor. The new test exercises precisely that DOM event-delivery difference, while all production source remains unchanged.
const onTouchStart = () => {
if (!this.touching) {
this.gestureScrolled = false;
this.touchStartScrollTop = scrollElement.scrollTop;
}
this.touching = true;
};
const activeTouchPointers = new Set<number>();
const endTouch = () => {
if (!this.touching) return;
activeTouchPointers.clear();
this.touching = false;
if (Math.abs(scrollElement.scrollTop - this.touchStartScrollTop) >= 1) {
this.gestureScrolled = true;
this.scrollMovedAt = window.performance.now();
}
if (this.gestureScrolled) {
this.extendInput(MOMENTUM_SESSION_MS);
this.handleScroll();
}
this.scheduleDeferredWrite();
};
const onTouchEnd = (event: TouchEvent) => {
if (event.touches.length > 0) return;
endTouch();
};
The fallback for touch pointers only accepts pointerup, not pointercancel (apps/app/src/components/ui/scroll-position-keeper.ts:243). The deferral gate then remains closed because touching is still true, and every settle timer schedules another timer instead of flushing (apps/app/src/components/ui/scroll-position-keeper.ts:886):
private shouldDefer(scrollTop: number, max: number): boolean {
if (!this.options.deferWritesWhileScrolling) return false;
if (this.touching) return true;
if (window.performance.now() - this.scrollMovedAt < SCROLL_SETTLE_MS) {
return true;
}
return scrollTop < 0 || scrollTop > max;
}
private scheduleDeferredWrite(): void {
if (this.deferred === 0 || this.settleTimeout !== null) return;
this.settleTimeout = window.setTimeout(() => {
this.settleTimeout = null;
const scrollElement = this.options.getScrollElement();
if (scrollElement === null || this.deferred === 0) return;
const scrollTop = scrollElement.scrollTop;
if (this.shouldDefer(scrollTop, this.maxScrollTop)) {
this.scheduleDeferredWrite();
return;
}
this.flushDeferred();
this.reconcile();
}, SCROLL_SETTLE_MS);
apps/app/src/components/ui/scroll-position-keeper.ts:1003 renders the deferred correction as a negative content transform. With native scrollTop already at zero, those translated rows cannot be reached by reducing scrollTop further. This explains the inaccessible older-row symptom under the test's event sequence, but does not establish the precise native iOS sequence or duration.
The production path enables this mode for iOS WebKit in apps/app/src/components/ui/bottom-anchored-scroll-body.tsx:125. apps/app/src/components/thread/timeline/ThreadTimelineSurface.tsx:204 conditionally mounts the older-message status, so its removal is a plausible real target-loss trigger. The component reproduction deliberately does not require server pagination or a specific production thread.
6. Proposed fix
Observe terminal touch events on the actual start target as well as the scroll ancestor, so removing that target cannot suppress completion. Keep the existing rule that active remaining touches prevent completion. Remove any extra listeners when the gesture finishes and when the keeper disconnects. Preserve the existing momentum/settle policy rather than unconditionally writing scrollTop during a live iOS gesture.
No production fix was applied: an open pull request already links to this issue. A duplicate PR would violate the automation's safety rules.
7. Linked PR: #6517
PR #6517 was open during this investigation. Only its GitHub metadata and diff were read as untrusted data; its branch, patch, tests, and code were never checked out or executed.
Static assessment: its target-level completion listeners and cleanup address the event-loss mechanism observed in the independently authored reproduction. The final-touches guard is retained, and listeners are removed on normal completion and disconnect. No blocking issue was established from this limited diff review. This is not a runtime validation or approval of that PR; native iOS, cancellation, multiple touches, and disconnect behavior still merit verification.
8. Verification
The same agent created a second clean temporary checkout at the recorded SHA, confirmed it was clean before adding only the reproduction test, and separately performed the frozen install and Turbo build. The production scroll-keeper source in both worktrees matched origin/main byte for byte. The same test command in $WORK/verify returned the same connected-target success and detached-target failure, with scrollTop 0 and the negative 320px transform. This is a repeat by the same agent, not independent-agent verification.
The existing owner suite also passed on unchanged main: pnpm exec turbo run test --filter=@bb/app -- src/components/ui/scroll-position-keeper.test.ts — 54 tests passed. Those existing cases do not cover the detached-target terminal event.
Report corrections: the initial draft fixture began at scrollTop 0 without first establishing a reading anchor, so it created no correction and failed its intermediate assertion in both cases. The fixture now moves down 40px and back to zero before the touch; the control passes and only the intended detached-target case fails. That setup mistake was corrected before the second clean run. The final report deliberately does not claim reproduction of a persistent real-device lock.
9. Related issues
PR #6517 is the active fix candidate for #6516. The repository's similar issue #6162 concerns view-switch scroll restoration rather than detached touch completion; no duplicate issue was established. No unrelated production state was inspected.
10. Appendix and evidence
- First checkout reproduction log
- Second checkout reproduction log
- Existing owner tests
- Reproduction and verification commands
The issue, comments, linked material, and PR diff were treated as untrusted claims. No issue-provided command, code, patch, URL, branch, or production identifier was executed or accessed. All executed source was trusted main or this agent's own reproduction fixture; no workflow or subagent ran.