Skip to content

fix(ChatVirtualizer): attach mode works on the page's own scroller - #10879

Merged
cixzhang merged 10 commits into
mainfrom
fix/chatvirtualizer-page-scroller
Nov 11, 2026
Merged

cixzhang merged 10 commits into
mainfrom
fix/chatvirtualizer-page-scroller

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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 ChatVirtualizer to 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 any scrollElement, 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 from el.getBoundingClientRect().top. For the page's scroller that box moves up by the scroll offset, so every correction pass added scrollTop again: 92 → 184 → 368 … until the page sat past every row.

  • Origin: the scroller's visible top is the viewport's top (0) for the page's scroller. The measured-anchor read uses the same value.
  • Scroll events: the page's scroll events fire at the document, not at <html>, so the list listens there.
  • Finger scrolls: the list watches the page's finger scrolls through a ref that names the document (Core's internal reader accepts one as of refactor(core): the internal finger-scroll reader accepts a ref that names the document #10883, which this stacks on), so the touch write-gate holds on a phone.
  • Viewport size: the page scroller's box doesn't resize with the viewport, so a window resize marks 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):

    scrollY after load (10 samples) Rows in view
    main 479,412 every sample 0
    this branch 92 every sample (the header's height: the first message's top at the viewport top) 16, starting at message 1

    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.

    main, after load this branch, after load
    main: blank page this branch: header and first messages
  • Red-first browser proof: ChatVirtualizerPageScroller.interaction.browser.spec.ts checks, 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:changesets pass. 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

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.
@vercel

vercel Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 11, 2026 7:21am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 9, 2026
@cixzhang cixzhang added the ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) label Nov 9, 2026
@cixzhang

cixzhang commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec e7db578

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · bb93e52

Storybook · Sandbox · built from this PR's head

Modified components

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

@astracat-bot

astracat-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 11, 2026, 7:36 AM UTC

…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.
@cixzhang
cixzhang changed the base branch from main to fix/core-finger-scroll-document-ref November 9, 2026 20:38

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 resize runs the full correction pass inside the resize handler (packages/lab/src/Chat/ChatVirtualizer.tsx:1350-1353), so every resize event reads layout between writes, which architecture:react-component-runtime INV18 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, scrollportTop and scrollEventTarget (ChatVirtualizer.tsx:82-100) copy the page-scroller rules that Core's useChatStreamScroll already implements (scrollsPage), and the copies already disagree on whether document.documentElement is 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]

@cixzhang

cixzhang commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 65ff95a

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 window resize event (5 layout reads per event, none on the base), which architecture:react-component-runtime INV18 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, scrollportTop and scrollEventTarget (lines 82-100) copy the page-scroller rules that Core's useChatStreamScroll already implements, and the copies already disagree on document.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]

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 10, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/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.
@cixzhang
cixzhang marked this pull request as ready for review November 10, 2026 16:40
cixzhang added a commit that referenced this pull request Nov 10, 2026
The preview page on top of the resize fix. Preview only; not for merge.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-runtime INV18 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, scrollportTop and scrollEventTarget (lines 82-100) still copy the page-scroller rules that Core's useChatStreamScroll already implements, and the copies already disagree on document.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.
@cixzhang
cixzhang marked this pull request as draft November 11, 2026 02:26
@cixzhang
cixzhang marked this pull request as ready for review November 11, 2026 02:26
cixzhang added a commit that referenced this pull request Nov 11, 2026
The preview page on top of the width-drag fix. Preview only; not for merge.
…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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.innerWidth in every resize event (line 1365; 9 reads over 9 events in Chromium), which architecture:react-component-runtime INV18 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 through observeResize), or at least read the width once in the frame callback.
  • A height-only resize that 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 reset containerEntrySeen when such a resize arrives.
  • isPageScroller, scrollportTop and scrollEventTarget (lines 82-100) still copy the page-scroller rules that Core's useChatStreamScroll implements, and the copies already disagree on document.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.

Automated review (maintainer link)

@cixzhang
cixzhang marked this pull request as draft November 11, 2026 02:53
@cixzhang
cixzhang marked this pull request as ready for review November 11, 2026 02:53
cixzhang added a commit that referenced this pull request Nov 11, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec cceecf4

@cixzhang
cixzhang changed the base branch from fix/core-finger-scroll-document-ref to main November 11, 2026 03:06
@cixzhang
cixzhang marked this pull request as draft November 11, 2026 03:12
@cixzhang
cixzhang marked this pull request as ready for review November 11, 2026 03:12

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.innerWidth in every resize event (line 1365), which architecture:react-component-runtime INV18 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 through observeResize), or compare the width once in the frame callback.
  • A height-only resize that 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 resetting containerEntrySeen when 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, scrollportTop and scrollEventTarget (lines 82-100) copy the page-scroller rules that Core's useChatStreamScroll already implements, and the copies already disagree on document.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.

Automated review (maintainer link)

…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.
@cixzhang
cixzhang marked this pull request as draft November 11, 2026 07:10
@cixzhang
cixzhang marked this pull request as ready for review November 11, 2026 07:11
cixzhang added a commit that referenced this pull request Nov 11, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec bb93e52

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 removed resize listener.

Automated review (maintainer link)

Comment on lines +1353 to +1357
// 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cixzhang
cixzhang merged commit a3a6f1c into main Nov 11, 2026
125 checks passed
cixzhang added a commit that referenced this pull request Nov 11, 2026
…r resize, anchoring, page-scroller and append scenarios, plus a page-scroller viewport resize
@github-actions
github-actions Bot deleted the fix/chatvirtualizer-page-scroller branch November 12, 2026 06:06

This branch was successfully deployed

1 active deployment
Preview — bb93e525 Deployed Nov 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant