Repository navigation
fix(ChatVirtualizer): a rotation keeps the row at the top of the view in place - #11219
Conversation
… in place A phone that rotates moves the page's scrollTop itself to keep the reader's place, against row heights the list has not measured yet. The list read that scroll as the reader's own and re-anchored on the row under the scaled position, so the view advanced several rows. A window resize on the page scroller now marks the viewport as changing, reading nothing, until the next correction pass. A scroll event during that time is not the reader's unless a finger scrolls, and the pass restores the held row from the measured heights. Follow-at-end also survives a rotation. New tests play the browser in a jsdom layout model: rotations to portrait, with and without the scaled scroll position, back to landscape, at the end, and under a scrolling finger. Three fail on the previous head. The record adds the rotation sentence to FR4 and a verification row.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| lab/ChatVirtualizer | 56.0 kB (+259 B) · 223 B CSS (0) | — | — · ✓ · ✗ |
| lab/ChatEmojiPicker | 110.3 kB (0) · 773 B CSS (0) | — | — · ✓ · ✓ |
| lab/ChatReactionBar | 111.4 kB (0) · 1.1 kB CSS (0) | — | — · ✓ · ✓ |
3 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| lab/ChatTypingIndicator | 25.9 kB (0) · 612 B CSS (0) | — | — · ✓ · ✓ |
| lab/ChatUnreadDivider | 3.7 kB (0) · 348 B CSS (0) | — | — · ✓ · ✓ |
| lab/Chat | — | — | — · ✓ · — |
Package size: no published package changed; no new dependencies.
Touched components checked; add ci:run-visual or ci:run-rtl to run the full suites.
Generated by PR Enrichment workflow | View full report
|
/approve-spec 3421daf |
There was a problem hiding this comment.
No blocking problems turned up in the code. Approval waits on an engineering owner deciding the record change below.
Owner decision needed: this pull request adds a new requirement to FR4 of the draft component:ChatVirtualizer record ("Rotating the device keeps the row that was at the top of the view in place, in both directions: a scroll position the browser sets itself while the viewport changes size is not the reader's scroll, and the next pass restores that row.") and a matching verification row for ChatVirtualizerRotation.test.tsx. An engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request, or says what the requirement should state instead. The author may do this as an engineering owner.
Non-blocking suggestion:
- The correction pass clears the new
viewportResizingmark (ChatVirtualizer.tsx:948), but its live-anchor refresh (:788) never reads it. The fix therefore relies on the browser's rotation scroll event arriving before the ResizeObserver pass. With the opposite order, the same test harness still moves the top row 25 rows. Adding!viewportResizing.current &&to that condition keeps the row in both orders and the Chat tests still pass. A pass-first case besiderotate()would pin it, and the real-phone run will show which order phones use.
There was a problem hiding this comment.
Approved. The new FR4 rotation requirement and its verification row carry an engineering owner's approval at this head, the new rotation tests fail before the change and pass with it, and CI is green on this head.
Non-blocking suggestions:
- A reader's own wheel, keyboard or scrollbar scroll that lands in the same frame as a window resize is now undone (
ChatVirtualizer.tsx:1236); clearingviewportResizinginonWheelwould keep at least the wheel case. - The correction pass's live-anchor refresh (
ChatVirtualizer.tsx:788) does not readviewportResizing, so a reader whose last scroll was not a finger's still loses their row if the resize observer batch arrives before the rotation's scroll event; adding!viewportResizing.current &&to that condition, with a pass-first test besiderotate(), would close it.
…ze event or after the pass are not the reader's On an iPhone the view still moved about one message per rotation. Safari can write its scroll position before the window's resize event, or after the correction pass that follows it, and the list read either write as the reader's own. A scroll that no finger makes now counts as the browser's when it lands within 500 ms of a window resize, or when the scroller's height differs from the one the last pass read. The list then restores the held row on the next frame. A wheel ends that time at once, so the reader's own wheel scroll right after a rotation is followed. The resize handler still reads nothing, and the scroll handler adds no read. Tests model both Safari orderings and hold the row's top edge at the top of the view; both fail on the previous head. A wheel test pins that the reader's own scroll is not reverted. The verification row names the new states.
|
/approve-spec 9679a83 |
There was a problem hiding this comment.
Approval waits on an engineering owner deciding the record change below, and three code fixes are needed whatever that decision is.
Owner decision needed: this pull request adds a requirement to FR4 of the draft component:ChatVirtualizer record ("Rotating the device keeps the row that was at the top of the view in place, in both directions: …") and rewrites its verification row for ChatVirtualizerRotation.test.tsx; the earlier /approve-spec named the previous commit, so it no longer counts. An engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so as an engineering owner.
Blocking:
- A reader's own scroll with no finger and no wheel (keyboard, scrollbar, a smooth or scripted scroll) within 500 ms of any window resize on the page scroller is undone (
ChatVirtualizer.tsx:1245-1247): in Chromium, PageUp 100 ms after a width-only resize stays on message 621 instead of reaching 608, so end that window on reader input such askeydownandpointerdown, asonWheeldoes, and add a keyboard case beside the wheel test. - Each finger-free scroll in that window runs a full correction pass on the next frame (
ChatVirtualizer.tsx:1256-1260), so a continuing scroll is laid out and written back every frame, against the runtime rule that a scroll path reads no layout; arm one restore per viewport change instead and name that trigger in FR4's pass list. - Desktop behavior change needs an owner decision: the height check (
ChatVirtualizer.tsx:1248-1249) runs on every scroller under every pointer, so a mouse-wheel or trackpad scroll on a list's own scroller that lands in the frame its height changes is undone; limit it to the page scroller, gate it to touch input, or cite the decision.
Also worth a look: the earlier note on the pass-first order (ChatVirtualizer.tsx:788-803) still applies, two new comments could be shorter (inline), and the description still describes the previous commit's mechanism and test counts.
There was a problem hiding this comment.
Changes requested: the record change is approved, and three code fixes remain.
The FR4 rotation sentence and its verification row in the draft component:ChatVirtualizer record carry an engineering owner's approval at this head, so the record change is settled.
Blocking:
- A reader's own scroll with no finger and no wheel (PageUp, Space, arrow keys, a scrollbar drag, a scripted scroll) within 500 ms of any window resize on the page scroller is put back (
ChatVirtualizer.tsx:1245-1247), so end that window on reader input such askeydownandpointerdown, asonWheeldoes, and add a keyboard case beside the wheel test. - Each finger-free scroll in that window arms a full measuring pass for the next frame (
ChatVirtualizer.tsx:1256-1260), so a continuing scroll is laid out and written back every frame against the runtime rule that a scroll path reads layout once per change, not per frame; restore with one scroll write from the stored geometry instead, and name that restore in FR4's pass list. - Desktop behavior change needs an owner decision: the rule runs under every pointer and its height check on every scroller (
ChatVirtualizer.tsx:1248-1249), so on desktop a mouse-wheel or trackpad step in the frame a scroller's height changes, and a scrollbar drag right after a window resize, are put back; gate the rule to touch input, or cite the owner decision that covers it.
Also worth a look: the live-anchor refresh (ChatVirtualizer.tsx:788-803) can still re-anchor on the browser's scaled position when its scroll event arrives after the observer's pass, and two new comments could be shorter.
Claims and files checked
- Claim: a rotation on the page scroller keeps the top row in place in both directions — verified for the browser's own rotation scroll (rotation tests green in CI; Chromium phone emulation holds the same message); no real-phone result for this head.
- Claim: a finger-free scroll counts as the browser's within 500 ms of a window resize on the page scroller or at a changed scroller height — verified (
ChatVirtualizer.tsx:1245-1249); the height half also runs on a list's own scroller. - Claim: a wheel ends that time at once — verified (
ChatVirtualizer.tsx:1379); the height check still applies to a wheel. - Claim: the resize handler reads nothing and the scroll handler adds no read — verified for the handlers (
ChatVirtualizer.tsx:1399-1401,:1245-1249); the pass they arm reads layout (second blocking finding). - Claim: the scroll-anchoring writer, finger-scroll watch, viewport probe and engine choice are unchanged — verified.
- Claim: the record adds one FR4 sentence and a verification row — verified (
ChatVirtualizer.spec.md:93,:128,:16). - Claim: before the change the top row jumps 25 and 21 rows and follow-at-end is lost in the test model — consistent with the base scroll handler; not rerun.
- Claim: all 8 rotation tests and the Lab Chat tests pass — verified through the green UI test shards for this head.
- Claim: a rotation where the browser keeps the scroll position, and one during a finger scroll, behave the same before and after — consistent with the code.
- Claim: the Safari-order tests fail on the previous head — not checked.
- Claim: 3 files, +484/−16, no published package size change — verified (Lab is private).
- Claim: no new interaction model under the bug-fix label — false for the reader's own scrolls within 500 ms of a resize (blocking findings).
- Claim: no internal context in public text — verified.
- File
docs/specs/components/Chat/ChatVirtualizer.spec.md— clear; FR4's pass list should name the new restore (second blocking finding). - File
packages/lab/src/Chat/ChatVirtualizer.tsx— three blocking findings, plus two comment-style notes and the pass-first note. - File
packages/lab/src/Chat/ChatVirtualizerRotation.test.tsx— no keyboard or scripted-scroll case in the resize window; otherwise clear.
… and the reader's scroll is followed The previous head treated every scroll with no finger for 500 ms after a window resize as the browser's, and scheduled a correction pass for each. A reader's PageDown or scrollbar drag in that time was undone, a scripted smooth scroll was written back every frame, and the height check also ran on a list's own scroller. Now a viewport change on the page scroller arms one restore: at the resize event, and again when the viewport's pass reads a new height. A scroll at a height that pass has not read, or the first one while a restore is armed, is the browser's and uses it; every other scroll is the reader's. A key, a pointer press or a wheel disarms it at once. A list's own scroller is untouched, since its observer entry carries its size. FR4 names the new pass trigger. Tests: a key scroll right after a rotation is followed, a run of eight scripted scroll events gets at most one list write, and a scroll on the list's own scroller as its height changes is followed. All three fail on the previous head.
|
/approve-spec f94f508 |
There was a problem hiding this comment.
Changes requested: the rotation restore holds the reader's row for the browser's own scroll before the pass and follows the reader's key, pointer and wheel input, and two fixes remain.
Blocking:
- The list's own scroll echo spends the restore meant for a browser write after the pass (
ChatVirtualizer.tsx:1255-1274), so in Chromium a finger-free 125 px scroll about 360 ms after a rotation moves the held message off the top, and the rotation test misses it because itsscrollTopsetter fires no scroll event for the list's writes (ChatVirtualizerRotation.test.tsx:104-109); excluding that echo fromisViewportMoveand firing the event in the test fixes both. - The description says
ChatVirtualizer.tsxchanges by +47/−1 and by +77/−1 and that the resize listener only records the time, but the file changes by +76/−1 and the listener also arms the restore.
Non-blocking: the keydown and pointerdown listeners could listen in the capture phase, so a key whose handler stops propagation still ends the restore, and the comment at ChatVirtualizer.tsx:1252-1254 reads better as two short sentences. CI's test check is red only because a node-test shard that does not run Lab code hit its 15-minute limit; a re-run should clear it.
Claims and files checked
- Rotation on a phone used to jump several messages on real phones: author-reported device result; consistent with the code, since Chromium itself moves the page's scroll position by about 1,100 px on a rotation and the base treats that as the reader's scroll.
- After the change the top row stays in place in both directions: verified in Chromium for the browser's scroll before the pass, both directions; false for a browser scroll after the pass (first blocking finding).
- Follow-at-end survives a rotation: verified by the rotation test, which passes in CI.
- A viewport change arms one restore at the resize event and again when the pass reads a new height: verified (
ChatVirtualizer.tsx:781-789,:1423-1426). - A finger-free scroll counts as the browser's at an unread height, or as the first scroll while armed within 500 ms: verified (
:1255-1261); the first such scroll after the pass is usually the list's own echo (first blocking finding). - A key, pointer press or wheel ends the restore at once: verified (
:1390-1408); a PageDown right after a rotation is followed in Chromium. - A list's own scroller is unaffected: verified (the rule is gated to the page scroller,
:1420); the own-scroller test passes in CI. - The file changes by +47/−1 and the resize listener only records the time: false (+76/−1; the listener also arms the restore).
- The resize handler reads nothing and the scroll handler adds no read: verified.
- No change to the scroll-anchoring writer, the finger-scroll watch, the viewport probe or the engine choice: verified from the diff.
- The new rotation tests fail before the change (top row moves 25 and 21 rows, follow-at-end lost): not run here; consistent with the base scroll handler by reading.
- All 11 rotation tests pass, the held row's top edge stays within 2 px: verified (CI unit tests; the test's 2 px check).
- The Safari-order tests fail on the first head and pass here: pass verified in CI; the first-head run was not repeated.
- The key, scroll-run and own-scroller tests fail on the previous head and pass here: pass verified in CI; the previous head lacks the key disarm, runs a pass per scroll and checks the height on every scroller, so they fail there by reading.
- Device results on the first head, and the Safari reload rate on rotation: author-reported device results.
- Heap, DOM node count and mounted rows match main in headless Chrome: not checked here.
- Unchanged paths (a rotation where the browser keeps the position; a rotation while a finger scrolls) pass before and after: pass at this head verified in CI; the base run was not repeated.
- The Lab Chat tests pass (95): not counted here; the three ChatVirtualizer test files (49 tests) pass in CI.
- Three files, +591/−16, the test file +498: verified; the component's +77/−1 is false (+76/−1).
- No published package changes size and no public API, default or interaction model is added: verified (Lab is private; props and handle unchanged).
- The record sentence states present behavior, is pinned by its verification row and carries no history: verified (record FR4 and its verification row).
docs/specs/components/Chat/ChatVirtualizer.spec.md: clear; the FR4 trigger, sentence and verification row carry an engineering owner's approval at this head.packages/lab/src/Chat/ChatVirtualizer.tsx: first blocking finding; non-blocking listener phase and comment notes.packages/lab/src/Chat/ChatVirtualizerRotation.test.tsx: first blocking finding (its scroll model fires no event for the list's writes); otherwise consistent with the record's verification row.
…rowser's restore The scroll event a browser fires for the list's own restore write was the first finger-free scroll while a restore was armed, so it spent the restore. A browser scroll write that landed after the pass then counted as the reader's and moved the held row off the top. The list's own echo now never counts as a viewport move. The key and pointer listeners that disarm the restore listen in the capture phase, so a key whose handler stops its propagation still disarms it. They are added only on the page scroller, where a restore can be armed. Tests: the rotation model's scrollTop setter fires the next-frame scroll event a browser fires for the list's own write. With it, the late Safari write test fails on the previous head and passes here. The key test presses PageDown on a control that stops the key's propagation.
|
/approve-spec db6dcab |
There was a problem hiding this comment.
Approved pending CI: a few CI jobs have not finished on this head yet.
The rotation restore now keeps the late browser scroll it exists for: the list's own scroll echo no longer spends it, and the key and pointer listeners that end it run in the capture phase on the page scroller only. The FR4 changes carry an engineering owner's approval at this head, the rotation tests pass in CI, and on this head's Storybook in Chromium a finger-free scroll 250 ms after a rotation is put back while a key press or wheel right after a rotation is followed. Two non-blocking notes are inline: the pass-first anchor refresh, and one comment sentence over the 25-word limit.
Claims and files checked
- Phones lost their place on rotation in a page-scrolling chat, and keep it after the change: the before is the author's device report; the after holds in this head's rotation tests and in Chromium (within 1 px over a round trip).
- The browser moves the page's scroll position on rotation and the list took that as the reader's scroll: verified by reading the base scroll handler, which re-anchors on any scroll that is not its own write.
- A window resize and a pass that reads a new height each arm one restore: verified,
ChatVirtualizer.tsx:781-789and:1431-1435. - A finger-free scroll at an unread height, or the first one while armed within 500 ms, is the browser's and is restored on the next frame: verified,
:1255-1276. - The scroll event of the list's own write never spends the restore: verified,
:1255-1260, and in Chromium. - A key or pointer press (capture phase) or a wheel ends the restore: verified,
:1391-1399,:1416-1427, and in Chromium with a control that stops the key's propagation. - A list on its own scroller is unaffected: verified, the page-scroller gate at
:1258and the listeners added only with the viewport probe. - The record adds the FR4 rotation sentence, its pass trigger and a verification row: verified,
ChatVirtualizer.spec.md:93,:128(the description quotes the sentence's first clause). ChatVirtualizer.tsx+84/−1, and 3 files +616/−16 in total: verified against the diff.- The resize handler reads nothing and the scroll handler adds no layout read: verified.
- No change to the scroll-anchoring writer, the finger-scroll watch or the viewport probe: verified.
- All 11 rotation tests pass, with the held row within 2 px: verified in CI and in the test's own check.
- The new tests fail on the base and on the earlier heads: not rerun here (the local install failed); the late-write and stopped-key cases fail on the previous head by reading.
- Device farm results, the Safari reload rates and the headless Chrome memory check: the author's report, stated in text.
- 95 Lab Chat tests pass: not rerun here; CI runs the three ChatVirtualizer test files green (31, 7, 11).
- No published package changes size, and no public API changes: verified, Lab is private and CI's analysis lists no row.
- The record carries no history or pull request references: verified.
- The rotation step matches an earlier pull request's device checklist: context outside this repository, not checked.
docs/specs/components/Chat/ChatVirtualizer.spec.md: clear.packages/lab/src/Chat/ChatVirtualizer.tsx: clear; two non-blocking notes.packages/lab/src/Chat/ChatVirtualizerRotation.test.tsx: clear.
| vp.clientHeight !== passViewportHeight.current | ||
| ) { | ||
| // A browser scroll write can still follow this viewport pass. | ||
| isRestoreArmed.current = true; |
There was a problem hiding this comment.
Non-blocking: this pass arms the restore, but the live-anchor refresh below (:795-810) still re-derives the anchor from the live scrollTop while userScrolledRef is true. If the browser moves the page during the resize frame's layout and its scroll event dispatches after this pass, the pass anchors on the scaled position before onScroll sees it. Chromium dispatched its move at the resize, so this was not observed. Clearing userScrolledRef in onViewportResize (it still reads nothing) keeps the stored row in that order.
| // The browser writes its scroll for a viewport change before that | ||
| // change's pass, at a height the pass has not read, or once soon after it. |
There was a problem hiding this comment.
Non-blocking (comment style): this sentence has 26 words, over the 25-word limit for a description. Suggested:
// The browser's scroll for a viewport change lands before that change's
// pass, at a height the pass has not read, or once soon after.
User impact
A reader on a phone, reading back through a long chat on a page that scrolls (ChatVirtualizer attached to
document.scrollingElement), rotates from landscape to portrait. The view jumps about 4–5 messages ahead, so they lose their place. A device farm run on real iPhone and Pixel phones saw this at both #10879's merged head and the head Cindy passed (9:20 → 9:24/9:25 on a Pixel, 9:16/9:17 → 9:20 on an iPhone). After this change the row at the top of the view stays in place in both directions, and a list following the newest message keeps following it.Problem and solution fit
scrollTopitself to keep the reader's place, scaled to the new content height. The list's row heights are not measured yet at that moment.Expected behavior and authority
component:ChatVirtualizerownership boundary: the list owns the restored row identity.Smallest restoration
ChatVirtualizer.tsx+84/−1 vs main, page scroller only:resizelistener that records the time and arms one restore;The resize handler reads nothing, and the scroll handler adds no read.
No change to the scroll-anchoring writer, the finger-scroll watch, the viewport probe, or the held engine choice.
Evidence
ChatVirtualizerRotation.test.tsx(a jsdom layout model where the content starts at the page top, spacers are as tall as the list sets them, rows have one height that changes on rotation, and newly observed rows report their size after the next frame), the top row moves 25 rows on a rotation to portrait with a browser-scaledscrollTop, and 21 rows on the way back to landscape, and follow-at-end is lost through a rotation to landscape.scrollToppasses before and after. A rotation while a finger scrolls writes nothing until the finger lifts (FR2), before and after. Lab Chat tests pass: 95.Size
ChatVirtualizer.tsx+84/−1,ChatVirtualizerRotation.test.tsx+515,ChatVirtualizer.spec.md+17/−15: the FR4 sentence, its pass-trigger list and the verification map, mostly table re-padding).pr-analysis, 0 bytes on every package).Scope
Components: ChatVirtualizer
Testing
pnpm vitest run --project ui packages/lab/src/Chat(95 pass), including the 11 rotation tests, red-first against main and against the earlier heads. Real-phone rotation is checked on the farm, on takes without a reload.Safari reload on rotation: device-state, reproduces on main.
Writing rubric results
audit:ChatVirtualizer/behavior).