Skip to content

chore(core): one owner module turns scroll anchoring off - #10173

Merged
cixzhang merged 7 commits into
mainfrom
chore/scroll-anchoring-owner
Nov 7, 2026
Merged

cixzhang merged 7 commits into
mainfrom
chore/scroll-anchoring-owner

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

User impact

No change anyone sees: a chat transcript that follows the end still keeps its position the same way. This gives the "turn the browser's scroll anchoring off" rule one owner, so Lab's ChatVirtualizer can reuse it instead of copying it.

What changes

  • Owner module: privateAttributes/scrollAnchoring.stylex.ts owns the private data-astryx-scroll-anchoring attribute and its one injected rule (overflow-anchor: none !important on ="off"). It exports only the writer, setScrollAnchoringOff(element, on).
  • Rule details: the rule is an attribute rule, not inline style, so a caller's own overflow-anchor is never touched and applies again when the attribute is gone. It's added once per document.
  • useChatStreamScroll: uses the writer while it follows the end, in place of its hand-written data-astryx-chat-following attribute and style. Same behaviour: anchoring is off while locked, back on when unlocked or unmounted.
  • Internal export: the new entry @astryxdesign/core/internal/scroll-anchoring re-exports the writer (never the name) for Lab. It's registered in package.json and scripts/sync-exports.js.
  • INV23 amendment: an owner module whose attribute marks an element its package doesn't render (here, a caller's scroller) may write its selector once in an injected rule instead of stylex.create. Core may re-export only that module's writer to Lab through an internal entry, and the name and selector stay private to the owner.
  • Lint baseline: the no-raw-private-attribute baseline drops the two hand-written useChatStreamScroll sites.

Authority

  • architecture:public-component-api INV23: one owner module per private attribute, exporting writers, never the raw name. The old attribute was hand-written outside an owner module.
  • Specs & Decisions chose this shape and ruled the INV23 amendment a consistency amendment (one owner per attribute and a private name both still hold).
  • The ChatLayout record gains the ownership line.

Verification

  • scrollAnchoring.test.ts covers the attribute and the single rule, that the element's inline overflow-anchor is left alone, the hand-back, and that the internal entry exports exactly the writer.
  • The useChatStreamScroll unit test now reads the new attribute. The Chromium spec reads the computed overflow-anchor instead of the attribute.
  • Chat and privateAttributes suites pass (446). The core type check, the sync-exports --check, check-knowledge and check:changesets pass.

Scope

  • One change: the anchoring rule's owner module and its two callers' path to it.
  • Changeset: [chore] internal.
  • Public text contains no internal Meta context.

Writing rubric results

Covers the architecture:public-component-api INV23 amendment and the component:ChatLayout ownership line.

R1 narration: none; both state what the system does in the present tense.
R2 research: none in either record.
R3 evidence: no evidence cell names a pull request, issue or commit.
R4 rejected alternatives: none recorded.
R5 change references: none; the ChatLayout line links the owner module's path and architecture:public-component-api INV23, not a pull request.
R6 open questions: none added or answered.

`privateAttributes/scrollAnchoring.stylex.ts` owns the private attribute
and its one injected rule, and exports only `setScrollAnchoringOff`.
useChatStreamScroll uses it in place of its hand-written attribute and
style (same behaviour), and `@astryxdesign/core/internal/scroll-anchoring`
gives the writer to Lab's ChatVirtualizer, so the rule has one owner
(public-component-api INV23).
@vercel

vercel Bot commented Nov 5, 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 7, 2026 11:34am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 5, 2026
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 5, 2026
@astracat-bot

astracat-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

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

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 5, 2026
@cixzhang

cixzhang commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 59e9541

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · a552a57

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
ChatLayout 61.3 kB (+30 B) · 10.4 kB CSS (0) — ✗ · ✓ · —
ChatComposer 74.5 kB (0) · 11.7 kB CSS (0) — ✗ · ✓ · —
ChatComposerDrawer 17.7 kB (0) · 4.7 kB CSS (0) — ✗ · ✓ · —
15 more components
Component Size LoC Visual · A11y · RTL
ChatComposerInput 72.5 kB (0) · 11.2 kB CSS (0) — ✗ · ✓ · —
ChatComposerTokenElement 72.5 kB (0) · 11.2 kB CSS (0) — ✗ · ✓ · —
ChatDictationButton 58.6 kB (0) · 10.0 kB CSS (0) — ✗ · ✓ · —
ChatLayoutScrollButton 58.5 kB (0) · 10.1 kB CSS (0) — ✗ · ✓ · —
ChatMessage 16.8 kB (0) · 3.7 kB CSS (0) — ✗ · ✓ · ✓
ChatMessageBubble 7.2 kB (0) · 3.7 kB CSS (0) — ✗ · ✓ · ✓
ChatMessageList 26.5 kB (0) · 7.0 kB CSS (0) — ✗ · ✓ · —
ChatMessageMetadata 19.9 kB (0) · 4.1 kB CSS (0) — ✗ · ✓ · —
ChatSendButton 58.4 kB (0) · 9.9 kB CSS (0) — ✗ · ✓ · —
ChatSystemMessage 7.0 kB (0) · 3.8 kB CSS (0) — ✗ · ✓ · —
ChatTokenizedText 7.2 kB (0) · 4.0 kB CSS (0) — ✗ · ✓ · —
ChatToolCalls 30.4 kB (0) · 8.3 kB CSS (0) — ✗ · ✓ · —
Chat — — ✗ · ✓ · —
lab/Comments 321.2 kB (+14 B) · 2.5 kB CSS (0) — — · — · —
chat — — — · ✓ · —
Visual changes: 4 snapshots in 1 component

A change is a question for the reviewer, not a failure.

Component · story Before After Diff
Chat · Default (neutral, dark) before frame after frame diff frame
Chat · Default (neutral, light) before frame after frame diff frame
Chat · Clipping (neutral, dark) before frame after frame diff frame
Chat · Clipping (neutral, light) before frame after frame diff frame

Package size: @astryxdesign/core 6.88 MB packed (+1.7 kB); no new dependencies.

API changes: none in this pull request

Committed API report behind this build: cli 19 rows, core 25 rows; run pnpm api:report.

Touched components checked; add ci:run-visual or ci:run-rtl to run the full suites.

Accessibility: 2 violation(s)

Accessibility Audit

Status: 2 accessibility violation(s) found — 2 serious.

ChatComposer - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/19 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
ChatComposerInput - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/18 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Generated by PR Enrichment workflow | View full report

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

This pull request needs an engineering owner's decision before it can be approved, plus two fixes whichever way that goes.

Decision needed: public-component-api INV23 puts an owner module's selector in a stylex.create call and forbids importing another package's owner module through an internal path, yet the new owner module injects a global <style> rule and @astryxdesign/core/internal/scroll-anchoring re-exports its writer for Lab. An engineering owner decides whether INV23 allows this shape (amending it to say so) or Lab keeps its own owner module, and records that here with /approve-spec <full head SHA>; the author may do so as an engineering owner.

Blocking fixes:

  • internal/eslint-plugin-astryx/no-raw-private-attribute.baseline.json (lines 10–13) still allows the two hand-written useChatStreamScroll.ts sites this PR removes, so no-raw-private-attribute.baseline.mjs --check fails and the lint would miss them coming back; regenerate the baseline.
  • .changeset/scroll-anchoring-owner.md (line 5) and the two new file headers say Lab's ChatVirtualizer uses the new entry, but ChatVirtualizer is not in the repository, so Core's release notes would name a component this release does not contain.

Same-document behaviour checks out: the hook's tests pass, and in Chromium the computed overflow-anchor matches main.

[Automated review]

Comment thread .changeset/scroll-anchoring-owner.md Resolved
* back (`!on`). A component calls this while it alone moves the container's
* position, so native anchoring does not move it a second time.
*/
export function setScrollAnchoringOff(element: Element, on: boolean): void {

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: setScrollAnchoringOff(el, true) turns anchoring off, and the JSDoc needs "(on)" and "(!on)" to say so. Naming the parameter off makes that obvious; the JSDoc can then keep only the reason: "A component calls this while it alone moves the container's position, so native anchoring does not move it a second time."

…notes follow

INV23 now allows an owner module whose attribute marks an element its
package does not render to write its selector once in an injected rule,
and Core to re-export only that writer to Lab through an internal entry;
the name and selector stay private to the owner. The lint baseline drops
the two hand-written useChatStreamScroll sites, and the Changeset and file
headers say Lab instead of naming a component this release does not ship.
@cixzhang

cixzhang commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 2229eec

cixzhang added a commit to yyq1025/astryx that referenced this pull request Nov 6, 2026
…t off the log, Core's shared touch and anchoring

- Keyboard users reach and scroll the list's own scroller, a `group` named
  by its new `label` prop (default "Messages"), through Core's
  useScrollableArea; a row holding focus stays mounted while the window
  moves away from it.
- Rows the window mounts over history, or history loaded above, mark the
  content block `aria-busy` for that commit and the next frame, so the
  transcript's log does not read them out as new; tail appends stay news.
- The touch write-gate follows Core's useFingerScroll (and its onEnd) in
  place of the list's own touch listeners and settle clock.
- Scroll anchoring goes off through Core's scroll-anchoring writer instead
  of a copied rule and a hand-written private attribute.
- `apiRef` is `handleRef`, as in Core components; static styles move to
  StyleX; the docs limit the spacer-height wording to touch gestures.
- A draft component record holds the ownership lines and the verification
  map, with the screen-reader evidence gap for aria-busy.

Depends on the Core changes in meta#10172 and meta#10173.

@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 pending CI: CI has not run on this head yet, because the pull request is still a draft; it runs once the pull request is marked ready for review.

The new owner module keeps same-document behaviour unchanged, the lint baseline and changeset fixes from the last round are in, and the INV23 amendment carries an engineering owner's approval for this head.

Non-blocking:

  • The INV23 amendment allows the injected rule for an attribute that "marks an element its package does not render", but in ChatLayout's self-scroll mode it marks ChatLayout's own root; "may mark" would cover both cases.
  • A following transcript in another document (an iframe or a portaled window) now gets anchoring turned off too, which the changeset's "same behaviour as before" does not mention.

[Automated review]

never writes the attribute or its selector, and no package imports another
package's owner module through an internal path. StyleX merges styles one
package's owner module through an internal path. An owner module whose
attribute marks an element its package does not render may write its

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: this allows the injected rule for an attribute that "marks an element its package does not render", but in ChatLayout's self-scroll mode the marked scroller is ChatLayout's own root (ChatLayout.tsx:308, externalScrollRef ?? rootRef), which Core renders. "whose attribute may mark an element its package does not render" would cover both cases.

@cixzhang
cixzhang marked this pull request as ready for review November 6, 2026 02:38
Keeps both internal entries: main's ./internal/dialog-context and this
branch's ./internal/scroll-anchoring, in package.json exports and in
sync-exports' internal list.
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 6, 2026
@cixzhang

cixzhang commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 5ceab51

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 6, 2026

@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: one item in the description, and no code change is needed.

  • Miss: the description has no ## Writing rubric results section, which architecture:knowledge-contracts requires of a pull request that changes a knowledge record, so add one R1–R6 line per check from docs/contributing/spec-writing.md covering the INV23 amendment and the ChatLayout ownership line.

The owner module, the internal entry and the INV23 amendment are otherwise in order, and the amendment carries an engineering owner's approval for this head. Two earlier non-blocking notes still apply: the amendment's "marks an element its package does not render" leaves out ChatLayout's own self-scroll root, and the changeset's "same behaviour as before" does not mention that a following transcript in an iframe or portaled window now has anchoring turned off.

[Automated review]

@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 pending CI: the heavy suites (build, test, docsite-test) are deferred on this head and run before merge.

The description now carries writing-rubric results that match both changed records, which was the one item outstanding; the owner module, the internal entry and the INV23 amendment are in order, and the amendment carries an engineering owner's approval for this head.

Two optional notes:

  • INV23's new sentence ("marks an element its package does not render") leaves out ChatLayout's own self-scroll root, which is marked too; "may mark" would cover both.
  • The changeset's "same behaviour as before" does not mention that a following transcript in an iframe or another window now has anchoring turned off.

[Automated review]

github-actions Bot added a commit that referenced this pull request Nov 6, 2026

@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 pending CI: the heavy suites (build, test, docsite-test) are deferred on this head and run before merge.

The update only merges main, so the change itself is the one approved before, and the scroll-anchoring owner module, its internal entry and the INV23 amendment still hold up. These non-blocking points are still open:

  • INV23's new sentence covers an attribute that "marks an element its package does not render", but in self-scroll mode ChatLayout marks its own root (ChatLayout.tsx:308); "may mark" would cover both.
  • The changeset says the behaviour is the same as before, but a following container in an iframe or another window now also has scroll anchoring turned off.
  • Naming setScrollAnchoringOff's second parameter off would let its JSDoc drop "(on)" and "(!on)", and the first sentence of the ensureRule JSDoc reads better split into short sentences.

[Automated review]

github-actions Bot added a commit that referenced this pull request Nov 6, 2026
@cixzhang

cixzhang commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 8457d93

@cixzhang cixzhang added the ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) label Nov 7, 2026

@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 pending CI: the heavy suites (build, test, docsite-test) are deferred on this head and run before merge.

The scroll-anchoring rule now has one owner module, useChatStreamScroll writes only through it, and the INV23 amendment and the ChatLayout line carry an engineering owner's approval for this head. The unit tests, the private-attribute baseline check, sync-exports --check and the core typecheck pass, and the Chat stories render the same as on main.

Non-blocking, still open from earlier rounds:

  • INV23's new sentence covers an element "its package does not render", but in self-scroll mode the marked element is ChatLayout's own root (ChatLayout.tsx:308); "whose attribute may mark an element its package does not render" covers both.
  • The changeset says "with the same behaviour as before", but a following container in an iframe or another window now also loses anchoring; naming that keeps the release note accurate.
  • In setScrollAnchoringOff(element, on), true turns anchoring off; naming the parameter off lets the JSDoc drop "(on)" and "(!on)".

[Automated review]

@cixzhang

cixzhang commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec e0795bf

@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 pending CI: the heavy suites (build, test, docsite-test) are deferred on this head and run before merge.

The update only merges main: the scroll-anchoring owner module, its internal entry for Lab, and the INV23 and ChatLayout record lines are unchanged, and the spec-owner approval covers this head.

Still open from earlier rounds, all non-blocking: the INV23 amendment's wording does not cover ChatLayout's own scroller, the changeset's "same behaviour as before" leaves out that a following container in a same-origin iframe now loses scroll anchoring, and two comment-style suggestions in scrollAnchoring.stylex.ts.

[Automated review]

github-actions Bot added a commit that referenced this pull request Nov 7, 2026
…attribute

The Studio AI conversation test, merged from main, still asserted the old
data-astryx-chat-following attribute. It now checks the owner module's
data-astryx-scroll-anchoring="off" while the chat follows, and its absence
after the reader scrolls up.
@cixzhang

cixzhang commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec a552a57

@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 pending CI: the heavy suites (build, test, docsite-test) are deferred on this head and run before merge.

The latest commit makes the docsite theme-showcase test read data-astryx-scroll-anchoring="off"; it passes, and no reference to the old marker remains. Four earlier non-blocking suggestions are still open if you want them: the scope of the new INV23 sentence, the changeset's "same behaviour" wording (a following container in a same-origin iframe now also loses anchoring), and two comment edits in scrollAnchoring.stylex.ts.

[Automated review]

github-actions Bot added a commit that referenced this pull request Nov 7, 2026
@cixzhang
cixzhang merged commit 6e0b604 into main Nov 7, 2026
112 of 115 checks passed
@github-actions
github-actions Bot deleted the chore/scroll-anchoring-owner branch November 8, 2026 06:03
cixzhang added a commit that referenced this pull request Nov 9, 2026
* feat(lab): experimental ChatVirtualizer with a virtualized transcript story

Adds a windowing participant for ChatMessageList children: ChatLayout
keeps the scroller, ChatMessageList keeps its shell semantics, and the
lab ChatVirtualizer renders only the rows near the viewport between two
document-flow spacers. It owns follow-at-end (displacement-based
disengage, position-based re-engage, declarative jumps) and
read-position stability (identity anchoring while scrolled up), with
per-type running size estimates behind hysteresis.

The story pairs a virtualized and an unvirtualized arm over the same
corpus and controls: streaming a reply with 3000 messages mounted
measures ~8fps unvirtualized vs the machine's full frame rate
virtualized with ~17 rows in the DOM (the status pill shows both live).

Related: #4102, #2282, #3942.

Co-Authored-By: Claude Fable 5 <[email protected]>

* feat(lab): expose endThreshold as a story control

The re-engage threshold maps directly to the follow-semantics
discussion in the PR: at 1px (TanStack Virtual's default) stopping
visually at the bottom often leaves follow silently disengaged while a
stream grows below; the control makes that reproducible in 30 seconds.

Co-Authored-By: Claude Fable 5 <[email protected]>

* feat(lab): streamSpeed story control (relaxed/default/fast)

Fast chunk cadence is the stress case for follow ownership —
disengage mid-stream, scroll back, re-engage — so make it a control
instead of a fixed 25ms.

Co-Authored-By: Claude Fable 5 <[email protected]>

* fix(lab): static source for the ChatVirtualization docs panel

'Show code' defaults to the dynamic snippet, which serializes the
rendered element tree — at messageCount=3000 that walk freezes the
docs panel. docs.source.type='code' renders the story source instead
(4KB, instant).

Co-Authored-By: Claude Fable 5 <[email protected]>

* storybook: split the two arms into two stories, add startAtTop

The virtualized/unvirtualized comparison becomes a story switch instead of
a control that turns the subject off: "Thousands of Messages" keeps the
virtualizer controls, "Unvirtualized Baseline" carries only the shared
corpus/stream controls. startAtTop demos the anchorToKey half of the
imperative API (log-reading mode: open at the first row, stream grows
below without moving the viewport).

* ci: retrigger preview deploy after the gh-pages reset

* feat(lab): hold scrollTop during touch gestures, absorb corrections in the spacer

The follow and anchoring machinery was measured against wheel gestures and
programmatic scrolls. Touch produces scroll events with no wheel event
anywhere, and that input class had three defects living in it, found by
hand-testing the preview on a phone.

Slow drags off the bottom deadlocked: re-engage is a position test, disengage
a displacement test, and per-event restores erased the displacement faster
than a slow drag could accumulate it — 599 of 600 frames reverted, 8px of
4800 travelled, identical in Blink and WebKit. Where momentum belongs to the
scroll view (iOS WebKit, Android) a programmatic write also cancels the
fling, so a flick stopped after about two messages. And with writes withheld,
rows mounting above the viewport landed their (real − estimate) delta in the
geometry and the content crawled under the finger.

So while a touch gesture owns the viewport — finger down, plus the settle
window after lift-off — the machinery writes no scrollTop at all. The
correction it would have written goes into the top spacer instead, and
paintOrigin() converts between painted space and model space so the two can
never be mixed. Rows in normal document flow are what make that possible: the
spacer is a second knob, where a transform-positioned virtualizer has only
scrollTop, which is exactly the thing a gesture forbids. Nothing is deferred
into a ledger, so nothing stale can replay — the flush is one ordinary sync
from the re-stated mode.

That restatement is unconditional, because it also hands the adjustment back:
anchorAt reads through paintOrigin, so the carried adjustment folds into the
stored viewportOffset and zeroing it leaves a single balancing write in the
same task. Whether the gesture moved decides only the semantics — a real
scroll re-judges follow against the bottom edge, a plain tap keeps the mode it
had, and "moved" counts only non-echo scrolls so a browser clamp cannot
masquerade as intent.

No platform sniffing: where momentum survives a write there are touch events
to gate on, and where it does not (a macOS trackpad, whose momentum arrives as
wheel events) this path never runs. Settling is scroll silence plus an
elastic-overscroll guard, polled; only the last finger off the glass starts
it.

Measured on this story, 40000px of touch travel: 0 pushbacks, 0 drift events,
1px flush shift, 0px on a tap. Four tests pin the state machine (both the gate
and the multi-touch guard fail the suite when reverted). The story's wrapper
moves to dvh, which mobile Safari needs to stop the page rubber-banding under
the list.

* fix(lab): read the gesture reference frame from paint, and converge on a head change

Two defects found by hand-testing the preview on a phone.

Releasing the finger moved the page. paintOrigin() — and so anchorAt, targetFor
and computeWindow — assume painted == model + gestureAdj. At the very top there
is nothing above to absorb a negative adjustment into, so the spacer stops at 0
while gestureAdj keeps its full value, and the flush then restates the frame
from a map the screen no longer shares. anchorFromPaint reads viewportOffset off
a rendered row's rect instead; anchorAt already computes that same quantity
(offsets[idx] - y IS the painted top), so this only stops assuming the map holds.
A drag ending at the top moved 182px on release before and 0px after, while
mid-history the scroll still travels (435px, 1218px) with the picture at 0-1px.

Loading older history hijacked the anchor. The live-anchor refresh fired in the
middle of an unfinished correction and froze the intermediate position, after
which the list held the wrong row faithfully — 7 runs in 12, permanently. A page
of history is a correction the size of the page, paid over several passes as
those rows measure in; converging is already the state for "a correction is in
flight, do not re-derive", it was simply never set for a data change. 7/12 -> 0/12,
and every gesture path already clears converging so it cannot wedge.

Adds the contract halves jsdom can hold: a prepend re-indexes rows without
renumbering their keys, and a gesture that ends with nothing rendered falls back
rather than throwing.

* feat(lab): load-older-history control in the story, and an estimate contract

The story could demo streaming and follow but had no way to prepend, so the one
question a reviewer is most likely to ask — what happens to my reading position
when older messages load — could not be answered by pressing anything. Adds a
'Load 300 older' button that inserts a page with ids of its own, never a
renumbering of the messages already on screen.

Measured through it, at scrollTop 0 with the page inserted above: the anchored
row holds to within 40-60px, reproducibly. That is a real residual and smaller
than a row, not the row-sized slip this used to be; it is larger than the 0px
the same case measures on a lighter corpus, because these rows measure in later
than the compensation pass that reads them.

Also documents the estimatedItemSize bias, which is the one setting that can
make a drag look broken: too small and content grows as it measures, extending
the scroll range below you and leaving your position valid; too large and it
shrinks, and the browser clamps scrollTop into a range that just got smaller,
which nothing can undo.

* fix(lab): take the repricing decision once per pass, not per row

The size-average repricing decision lived inside effectiveAvg, which runs once
per row inside recompute's O(N) loop, and one of its gates is a clock reading.
A loop long enough to straddle the instant that gate opens repriced the tail of
the list and not the head: the pass published a geometry that was internally
inconsistent, restored scrollTop against it, and consumed geoChanged — so the
next pass, the one holding the consistent geometry and the correct target, found
the flag clear and never wrote. The landing was left short, permanently.

The odds scale with loop length and the gate re-crosses its threshold after
every gesture, so this is a size-amplified race rather than a large-list-only
bug. Measured upstream of this port on the same engine at 100k rows: a declared
jump landed up to 698,000px short in 25-50% of runs, 5/20 -> 0/17 after the fix,
with the smaller corpora unchanged at 0px on every axis.

repriceBuckets now takes the decision before the rebuild, from a single clock
reading, and effectiveAvg becomes a pure read — a pass always prices every row
from one set of numbers. priceFreeze additionally holds prices still while a
declared target is in flight and gives the release a frame of its own, so the
correction the averages owe is derived from a settled geometry instead of being
appended to the pass that just landed.

* fix(lab): the RO fallback measured a different box than the sync path

Both writers feed one size cache, and in 'ro' mode both actually run: a
row's first measurement comes from the sync pass's offsetHeight backstop,
every later one from the observer. contentRect is the CONTENT box, so on
a browser without borderBoxSize a padded row was cached short by its
padding and border, for as long as the fallback stayed the writer.

Fall back to offsetHeight on the observed element instead — the same box,
read off the same node as the sync path, so the two agree by construction
rather than by browser support.

* docs(lab): document ChatVirtualizer

The only component in the Chat directory without a doc, so the props that
carry a real contract — bias the estimate low, spacing lives inside the
row, pass the scroll container as an element — were readable only from the
source.

The scrollElement entry states why it takes an element rather than a ref:
a parent's ref attaches after its children's layout effects, so a ref
still reads null on the commit that first needs the scroller, and a ref
write is invisible to React, while an element held in state makes the
container's arrival a render and a real dependency.

No keywords field: family fields are inherited from the parent Chat doc,
and setting keywords here would replace that list rather than extend it.

* fix(lab): a head-change convergence let go of the anchor too early

Reaching the restore target does not end a head-change convergence. The
rows that arrived above are still measuring in, so the prices and the
offsets keep moving for several more passes — which is why the prices were
already held one pass longer, on a release of their own. The anchor half
was dropped on the spot instead, and in that gap the live-anchor refresh
re-derives from a scrollTop still mid-settle and freezes the intermediate
position as the new reference frame. Permanently: nothing later disagrees
with a stored anchor.

Both halves now lift on the same later pass, the one that sees the settled
numbers.

Measured on the virtualized story, reading at the top and pressing "Load
300 older": every visible row moved together by 33-53px and stayed there,
across every run. After: 0.1px, over five runs at the top and two in
mid-history, with follow-at-end and post-prepend scrolling unaffected.

No unit test: the defect lives in the window where the DOM has laid out
new rows at their real heights while the geometry still carries their
estimates, and jsdom has no layout to disagree with. The story is the
reproduction.

* Merge remote-tracking branch 'upstream/main' into chat-virtualizer-story

* fix(lab): ChatVirtualizer judges the reader by position, owns its scroller

Four carry-overs from the review of #5678, where the same ownership
questions were settled for useChatStreamScroll:

- A wheel no longer disengages follow by itself. One this scroller never
  consumes — over a nested scroller with room above, over one with
  `overscroll-behavior: contain`, an overscroll at the bottom — moves
  nothing here, and unpinning on it stranded the reader off the tail.
- The reader's displacement is measured from the position the list last
  WROTE, not from the last scroll event seen. A wheel between two writes
  coalesces with the next write into one event carrying the net, and
  against the previous event that net could read as "moved down".
- A non-echo scroll that lands exactly on the bottom is not displacement:
  with native anchoring off, that is the browser clamping onto a smaller
  bottom after a shrink no commit announced.
- Native anchoring is switched off through `data-astryx-chat-virtualized`
  and one injected rule (the highlightRanges pattern), never the inline
  style: in attach mode the scroller is the caller's, and their own
  `overflow-anchor` is neither read, written nor restored.

The story now runs the virtualizer in own-container mode inside a shell
of its own — ChatMessageList for the log semantics, the composer in a
dock — instead of attaching to ChatLayout's scroller. ChatLayout runs its
own follow on that scroller with no way to hand it off, and a position
with two writers is a position nobody owns. Attach mode stays for hosts
whose scroller has no follow of its own; the baseline story keeps
ChatLayout as the control.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(lab): ChatVirtualizer floors its extent, resets geometry on detach

React commits a window shift children-first: rows are removed before
any spacer or parent style changes, and useInsertionEffect runs only
after the whole subtree has mutated. A row whose unmount reads layout
saw the extent without the removed rows, the browser clamped scrollTop
and the live-anchor refresh adopted it (2381-2617px short, Chromium
and Firefox). Spacers and rows now sit in one content block whose
min-height is the modelled extent, written only by the correction
pass, so the previous extent holds through the commit. The insertion
effect is gone. Attach mode renders that block instead of a fragment.

Own-container mode now resets the attach-mode origin/below geometry;
switching back from scrollElement kept the host's offsets and aimed
every follow target past the end of the list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Merge remote-tracking branch 'upstream/main' into chat-virtualizer-story

* chore(registry): lock the ChatVirtualizer shadcn route

The route lock landed on main after this branch last synced, so the
new lab component was missing from it. Regenerated with
UPDATE_SHADCN_ROUTE_LOCK=1; the only change is the new entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(lab): file ChatVirtualizer under Chat, title its story by name

The docsite now requires every lab Chat* doc to carry group and
category 'Chat', and the PR accessibility scope maps stories to
components by title, which 'Lab/ChatVirtualization' did not match.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(lab): ChatVirtualizer attach mode names a follow-free host

The scrollElement JSDoc pointed callers at ChatLayout's scroller, the
one host that cannot work today: ChatLayout runs its own follow on
that element with no way to turn it off, so attaching there puts two
writers on one position. The example is now a scroller with no follow
of its own, and the doc says ChatLayout cannot host attach mode until
it exposes a seam to disable that follow. Comments that named
ChatLayout as the host follow suit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Merge main into chat-virtualizer-story

Resolves the generated route lists (the union of both sides' entries, in generator format) and refreshes any generated goldens; no other change.

* fix(lab): ChatVirtualizer review round — keyboard access, history kept off the log, Core's shared touch and anchoring

- Keyboard users reach and scroll the list's own scroller, a `group` named
  by its new `label` prop (default "Messages"), through Core's
  useScrollableArea; a row holding focus stays mounted while the window
  moves away from it.
- Rows the window mounts over history, or history loaded above, mark the
  content block `aria-busy` for that commit and the next frame, so the
  transcript's log does not read them out as new; tail appends stay news.
- The touch write-gate follows Core's useFingerScroll (and its onEnd) in
  place of the list's own touch listeners and settle clock.
- Scroll anchoring goes off through Core's scroll-anchoring writer instead
  of a copied rule and a hand-written private attribute.
- `apiRef` is `handleRef`, as in Core components; static styles move to
  StyleX; the docs limit the spacer-height wording to touch gestures.
- A draft component record holds the ownership lines and the verification
  map, with the screen-reader evidence gap for aria-busy.

Depends on the Core changes in #10172 and #10173.

* chore(storybook): the ChatVirtualizer comparison story moves to its own pull request

The Storybook comparison of virtualized and unvirtualized transcripts
lands in a follow-up pull request, so this one stays under the 2,000-line
review limit.

* fix(lab): ChatVirtualizer keeps a focused row pinned through a blur with no next target; keyExtractor is getRowKey

A blur with no next target can come while the row still holds focus, so
the pin drops only once focus has really left the list. The row identity
prop is `getRowKey`, as in Core's table row hooks.

* fix(lab): ChatVirtualizer observes sizes through Core's shared resize observer

Rows and the scroller register with observeResize from
@astryxdesign/core/utils instead of a ResizeObserver of their own; one
sync still runs per batch, after the last entry, and the registration's
own boxless call is skipped so it forces no layout.

* Merge branch 'main' into chat-virtualizer-story

* chore(cli): list ChatVirtualizer among the official Lab components

Regenerated with `pnpm bundle:cli-official-packages`.

* fix(ChatVirtualizer): measureMode is not a public prop

The measurement pipeline is an implementation detail (AST-002 DEC-1), so
the prop and ChatVirtualizerMeasureMode are gone; the list always uses
the ResizeObserver pipeline it shipped as the default. It never shipped,
so nothing migrates.

* fix(ChatVirtualizer): a message that arrives while the reader is in history mounts, unmarked

Away from the tail, the window never reaches a new message, so it did not
mount and the log had nothing to deliver; when the reader returned it
mounted inside an aria-busy block. Now such a row mounts on arrival after
a gap spacer below the window, as the focused-row pin does, and stays
mounted (streamed updates included) until the window reaches it (AR2).

* perf(ChatVirtualizer): read layout once per scroll event and twice per pass

The scroll handler reads the scroller's position and size in one batch
and writes nothing, so it forces no layout. Each correction pass writes
its spacers, reads in one batch, writes its spacers and scrollTop, and
reads scrollTop back once to claim any browser move, so it forces at most
two layouts; the size it needs after its writes comes from the batch. The
record gains FR4, the clause react-component-runtime INV18 asks for, and
a layout-trace test checks the bound.

* fix(ChatVirtualizer): arrivals in state; a replaced thread adds none; no pass for an idle commit

Tail arrivals are now state, updated during render when the data or the
window changes, not a ref mutated in render (react-component-runtime
INV4). Only a tail append adds to them: a replaced array (another thread)
shares no row with the previous data, so switching threads while the
reader is in history no longer mounts the whole thread for a commit.
Arrivals leave once the window reaches them. The correction pass now
skips a commit that changes nothing it reads (a parent re-render with the
same rows); FR4 lists every trigger the pass has. Tests cover the thread
switch and the skipped pass.

* fix(ChatVirtualizer): an appended batch mounts at most a window of rows

Arrivals are added only while the window does not reach the previous
last row, so a batch appended while following is left to the window, and
at most one window of the newest rows mounts as arrivals while the reader
is in history (this also covers a thread switch that shares a row key).
The correction pass also runs when a sizing prop changes, and FR4 names
that trigger. Tests append 2,000 rows while following and while in
history. The file header says which commits run the pass.

* fix(ChatVirtualizer): arrivals stay one window across batches in history

The cap on mounted arrivals now applies to the whole set after every
change, not only to the newest batch, so a second batch or a run of single
arrivals while the reader stays in history keeps one window of the newest
rows mounted. The test appends a second 2,000-row batch and three single
rows in history.

* fix(ChatVirtualizer): a loaded or replacing thread is history for the log

Rows count as news only for a tail append, when the walk stops at a row
the previous data held. A thread loaded into an empty list, or one that
replaces the rows, mounts as history, so the block is busy for that commit
and the log does not read old messages out as new. Test and the AR2
verification row cover both.

* fix(ChatVirtualizer): the first message of an empty transcript is news

One row arriving into an empty list counts as news, so the opening message
of a new conversation mounts unmarked and the log delivers it; a larger load
into an empty list stays history. Adds a test and the AR2 verification
state, a CLI Changeset for the discover package list, stable-function
notes on estimatedItemSize and getItemType, and trims the file header and
a history comment.

Co-authored-by: Cindy Zhang <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — a552a57a Deployed Nov 7, 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-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. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant