Repository navigation
fix(ChatVirtualizer): attach mode works on the page's own scroller - #10879
Conversation
On document.scrollingElement, a list anchored to its first row jumped hundreds of thousands of pixels down and showed no rows. The list measured where its content starts against the scroller's box, and the page's box moves up with every scroll, so each pass added the scroll offset again. It now measures against the viewport's top for the page's scroller, listens for the page's scroll on the document, watches the page's finger scrolls through the document, and treats a window resize as a viewport change. A Storybook story attaches 10,000 messages of varied height under a header to the page scroller, and an interaction proof checks the page stays at the first message frame after frame and keeps rows on screen through scrolls. In real Chrome, main jumps to scrollY 479,412 with no rows in view; this branch stays at 92 (the header's height) with the first message at the top. Core's internal finger-scroll reader accepts a ref that names the document.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
/approve-spec e7db578 |
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| lab/ChatVirtualizer | 55.8 kB (+197 B) · 223 B CSS (+79 B) | — | — · ✓ · ✗ |
| 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
|
AI review status for this pull request.
|
…names the document useFingerScroll took a ref to an element, or the document for the page's own scroll. A component whose scroller may be either (Lab's ChatVirtualizer attached to document.scrollingElement, whose scroll events fire at the document) holds both in one ref. The hook now accepts a ref whose current names the document; the watch already treated the document as the page's scroller, so behavior is unchanged. A test reads a finger's page scroll through such a ref.
…virtualizer-page-scroller
There was a problem hiding this comment.
The page-scroller fix works: the new PageScroller story now opens at message 1 with rows in view, where main parks the page at scrollY 479,412 with nothing on screen. Two blocking fixes are needed, and approval also waits on an owner decision.
Blocking
- A window
resizeruns the full correction pass inside the resize handler (packages/lab/src/Chat/ChatVirtualizer.tsx:1350-1353), so every resize event reads layout between writes, whicharchitecture:react-component-runtimeINV18 rules out on a resize path; let the new viewport size reach the existing pass as a ResizeObserver entry instead of reading it in the handler. isPageScroller,scrollportTopandscrollEventTarget(ChatVirtualizer.tsx:82-100) copy the page-scroller rules that Core'suseChatStreamScrollalready implements (scrollsPage), and the copies already disagree on whetherdocument.documentElementis the page; move those rules into one Core helper that both call and drop the Lab copy.
Owner decision
Attach mode on the page's scroller has no current record: component:ChatVirtualizer is still a draft, and the existing /approve-spec approves no record because this pull request changes none. An engineering owner, the author included, settles it by approving that record or by adding a clause here that names the page's scroller and approving it with /approve-spec <full head SHA>.
[Automated review]
|
/approve-spec 65ff95a |
There was a problem hiding this comment.
Changes requested. The page-scroller fix works: the new PageScroller story holds message 1 with rows in view where the base parks the page at scrollY 479,412 with nothing on screen, its browser proof fails on the base and passes here, and the engineering owner's approval of the new FR4 verification row settles the direction. Two fixes remain in packages/lab/src/Chat/ChatVirtualizer.tsx:
onViewportResize(lines 1349-1354) runs the whole correction pass inside every windowresizeevent (5 layout reads per event, none on the base), whicharchitecture:react-component-runtimeINV18 rules out on a resize path; mark the geometry changed there and let the viewport's height reach the existing coalesced ResizeObserver pass instead.isPageScroller,scrollportTopandscrollEventTarget(lines 82-100) copy the page-scroller rules that Core'suseChatStreamScrollalready implements, and the copies already disagree ondocument.documentElement; move those rules into one Core helper on an internal entry that both call, and delete the Lab copy.
Non-blocking: the comment at lines 1347-1348 could say that the root box does not follow the viewport's height (it does follow its width).
[Automated review]
|
/approve-spec 65ff95a |
…orrection pass per frame On the page scroller the window resize listener ran the full correction pass inside every resize event. An iOS toolbar height change fires many of them in one frame and gives the page scroller no ResizeObserver entry. The handler now reads no layout: it marks the geometry dirty and schedules one pending animation frame, which runs the correction pass once. Unmount or a replaced scroller cancels the pending frame. Only the resize path changes. A test makes the traced scroller the page scroller: one resize reads nothing in its handler and is followed by one pass; three resizes in one frame read nothing in any handler and give the same single pass, with at most the pass's two layouts. It fails on the previous head.
There was a problem hiding this comment.
Approval waits on an engineering owner's decision for this head, and two fixes in packages/lab/src/Chat/ChatVirtualizer.tsx are required either way.
The page-scroller fix itself works: the PageScroller story holds message 1 with rows in view where the base parks the page at scrollY 479,412 with nothing on screen, its browser proof fails on the base and passes here, and the reworked resize handler no longer reads layout inside the event. component:ChatVirtualizer is still a draft record and the FR4 verification row added here defines the page-scroller behavior, while the earlier /approve-spec comments name older heads, so an engineering owner records the decision by commenting /approve-spec 4549fcb0e8124309190217b551af15f716d498e4 on this pull request (the author may do so as an engineering owner).
- A window drag that changes width now runs two correction passes per frame, the new frame pass at lines 1354-1362 and then the root's ResizeObserver pass (10 frame passes plus 10 observer passes over ten one-frame steps in Chromium, against 10 on the base), which
architecture:react-component-runtimeINV18 rules out with "one batched measurement pass per change"; let the viewport's size reach the existing coalesced observer pass instead, so a width change makes one pass. isPageScroller,scrollportTopandscrollEventTarget(lines 82-100) still copy the page-scroller rules that Core'suseChatStreamScrollalready implements, and the copies already disagree ondocument.documentElement; move those rules into one Core helper on an internal entry that both call, and delete the Lab copy.
Non-blocking: the comment at lines 1347-1351 says the root box does not change size with the viewport, though it follows the viewport's width, and one shorter comment can keep both reasons.
[Automated review]
…ection pass A window width change also resizes the page scroller's box, so its ResizeObserver entry already runs a correction pass in that frame. The resize handler's own frame pass ran a second one. A width change now leaves the pass to that entry; one frame later, a pass runs only if no entry came. A height-only change, such as an iOS toolbar collapse, gives the scroller no entry and keeps its single frame pass. New tests deliver the scroller's entry by hand and count passes: a width drag with its entry runs one pass, a height-only change runs one, and a width change with no entry runs one a frame late. The first and third fail on the previous head.
…ly sequence runs one pass The test guards the frame handle: a height-only resize must clear it, or a later resize never schedules a pass. With that line removed, the third resize runs no pass and the test fails.
There was a problem hiding this comment.
Approval waits on an engineering owner's decision for this head, and three fixes in packages/lab/src/Chat/ChatVirtualizer.tsx are required either way.
The page-scroller fix works: the PageScroller story opens at message 1 with rows in view where the base sits blank at scrollY 479,412, and a width drag now runs one correction pass instead of two. component:ChatVirtualizer is still a draft record and the FR4 verification row added here defines the page-scroller behavior, so an engineering owner records the decision by commenting /approve-spec ae1819edde361f8f243d1c16ca20afcdb5197872 on this pull request (the author may do so as an engineering owner).
- The resize handler reads
window.innerWidthin everyresizeevent (line 1365; 9 reads over 9 events in Chromium), whicharchitecture:react-component-runtimeINV18 rules out on a resize path; let the viewport's size reach the existing coalesced ResizeObserver pass (for example from a fixed, viewport-sized element observed throughobserveResize), or at least read the width once in the frame callback. - A height-only
resizethat lands one frame after a width change gets no correction pass, because it returns early while the second frame is pending and that frame then skips its pass since the width change's container entry already arrived (lines 1370-1388); the observer route fixes this too, or resetcontainerEntrySeenwhen such a resize arrives. isPageScroller,scrollportTopandscrollEventTarget(lines 82-100) still copy the page-scroller rules that Core'suseChatStreamScrollimplements, and the copies already disagree ondocument.documentElement; move them into one Core helper on an internal entry that both call, and delete the Lab copy.
Non-blocking: the comment at lines 1351-1355 says the page scroller's box does not resize with the viewport and that the handler reads no layout, and the new FR4 row leaves its Audit section cell empty.
|
/approve-spec cceecf4 |
There was a problem hiding this comment.
Changes requested on #10879; #10883 is approved.
#10883: approved. Its internal useFingerScroll type change is already merged into main.
#10879: changes requested. The page-scroller fix works (the PageScroller story opens at message 1 instead of a blank page at scrollY 479,412), but four fixes in packages/lab/src/Chat/ChatVirtualizer.tsx remain:
- The resize handler reads
window.innerWidthin everyresizeevent (line 1365), whicharchitecture:react-component-runtimeINV18 rules out on a resize path, and the test that says the handler reads no layout does not trace that read; let the viewport's size reach the existing coalesced ResizeObserver pass (for example from a fixed, viewport-sized element observed throughobserveResize), or compare the width once in the frame callback. - A height-only
resizethat lands one frame after a width change gets no correction pass, because it returns early while the second frame is pending and that frame then skips its pass once the width change's container entry has arrived (lines 1370-1388); the observer route, or resettingcontainerEntrySeenwhen such a resize arrives, fixes it, and a test should resize one frame after the width change. - Miss: on a page that sets
html { height: 100% }, a height-only resize also resizes the observed<html>box, so the frame pass (lines 1375-1378) and the container's ResizeObserver pass both run for one change, which INV18 rules out; the observer route fixes this too, or the height branch can wait for the container entry as the width branch does. isPageScroller,scrollportTopandscrollEventTarget(lines 82-100) copy the page-scroller rules that Core'suseChatStreamScrollalready implements, and the copies already disagree ondocument.documentElement; move them into one Core helper on an internal entry that both call, and delete the Lab copy.
Whole stack: a pull request lands only when it and every pull request below it are approved, so the stack waits on #10879.
Non-blocking: the comment at lines 1351-1355 says the handler reads no layout, and the new FR4 verification row is missing its Audit section cell.
…h its ResizeObserver batch The page scroller's own box does not change size with the viewport, and an iOS toolbar change resizes only the viewport. A hidden fixed box the viewport's size now reports both, in the same coalesced ResizeObserver batch as the scroller and its rows. The window resize listener and its frame callbacks are gone: a resize reads no window size, a width drag runs one pass for the scroller's and the box's entries together, and a height-only change right after a width change still runs its pass. The page-scroller rules come from Core's owner module through @astryxdesign/core/internal/page-scroller; the Lab copies are gone. The shared rule also counts the document element as the page's scroller when the body is the scrolling element. Tests deliver the entries a browser sends with each resize. On the previous head, the box is missing, the resize handler reads the window's width, and a height-only change in the frame after a width change runs no pass. The record lists the new test and fills the page-scroller row's audit section.
|
/approve-spec bb93e52 |
There was a problem hiding this comment.
Approved: attached to document.scrollingElement, the PageScroller story now opens at message 1 with rows in view, and viewport changes keep that position.
#10883: approved and already merged; no blocking findings.
#10879: approved; no blocking findings. The earlier resize-path and shared-rule findings are fixed, and the record's new FR4 rows carry an engineering owner's approval for this head.
Whole stack: passes, with no public API change. A pull request in this stack lands only when it and every pull request below it are approved.
- Optional: the comment above the viewport probe (
ChatVirtualizer.tsx:1353-1357) says the page's box ignores the viewport, which holds only for its height, and the description's "Viewport size" bullet still describes the removedresizelistener.
| // The page's own scroller's box does not change size with the viewport, | ||
| // and an iOS toolbar change resizes only the viewport. The viewport probe | ||
| // reports both in the same ResizeObserver batch as the scroller and its | ||
| // rows, so one viewport change runs one correction pass and reads no | ||
| // layout outside it. |
There was a problem hiding this comment.
Non-blocking (comment style): the page's root box does follow the viewport's width; only its height ignores the viewport. "reports both" leaves "both" unclear, and the last sentence runs 30 words with two topics. Suggested:
// The page scroller's box does not follow the viewport's height. An iOS
// toolbar change resizes only the viewport. The probe's entry arrives in
// the same ResizeObserver batch as the scroller's and the rows', so one
// viewport change runs one pass.…r resize, anchoring, page-scroller and append scenarios, plus a page-scroller viewport resize
Stack: #10883 → #10879
Stacked on #10883 (Core: the internal finger-scroll reader accepts a ref that names the document). Merge that first.
User impact
A product that attaches Lab's
ChatVirtualizerto the page's own scroller (document.scrollingElement), with any content above the list, got a blank page. Anchored to the first message, the page jumped hundreds of thousands of pixels down and showed no rows. Now the page stays at the first message and rows render. Attach mode covers anyscrollElement, including the page's.Cause and fix
The list measures where its content starts inside the scroller: the top spacer's position minus the scroller's visible top, plus
scrollTop. It read the scroller's visible top fromel.getBoundingClientRect().top. For the page's scroller that box moves up by the scroll offset, so every correction pass addedscrollTopagain: 92 → 184 → 368 … until the page sat past every row.<html>, so the list listens there.resizemarks the geometry changed.Own-container mode and attach mode on an element scroller don't change.
Evidence
Real Chrome 157, 1280×800, the new story (attach to
document.scrollingElement, 10,000 messages of one to six lines, a header above, anchored to the first message):Scrolling the page to 3,000, then 12,000, then 0 keeps 14–17 rows in view on this branch; main shows none until it's back at the top.
Red-first browser proof:
ChatVirtualizerPageScroller.interaction.browser.spec.tschecks, over ten checks of six frames each, that the page stays under 400px from the top with message 1 in view, and that scrolls keep rows on screen. On main the first check fails (scrollY 479,412).Tests and checks: ChatVirtualizer unit tests pass. ESLint, Prettier and
check:changesetspass. Lab ships no Changeset; the Core change and its Changeset are in refactor(core): the internal finger-scroll reader accepts a ref that names the document #10883.Phone check
On a phone, open the Page Scroller story on this branch's preview, then scroll the page with a finger, fling it and let the momentum run out. The list must keep rows on screen and never jump or fight the finger.
Scope
Components: ChatVirtualizer