Skip to content

fix(virtual-list): render and measure the new range before the first frame paints - #281

Merged
rostislavrotaru merged 13 commits into
mainfrom
dev1/275-first-frame
Nov 30, 2026
Merged

rostislavrotaru merged 13 commits into
mainfrom
dev1/275-first-frame

Conversation

@rostislavrotaru

@rostislavrotaru rostislavrotaru commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Issue: #275

Part of #275: the virtual list's first painted frame now shows its rows measured, at the right scroll. The issue's TeamRun check on macOS comes after this change.

Cause

measure(), the list's ResizeObserver callback, runs after layout and before paint. It set the padding and the scroll at once, but the rows the new range holds come from signals Angular renders on its next tick, so the painted frame showed the old range at the measured offsets. Read last before each paint, on Linux, macOS and Windows alike, with a 160 px estimate in a 600 px view:

Feed Main's first frame with rows Settled
10 rows of 55 px scroll 160, rows 2–9 from 160 px, a blank top scroll 0, rows 0–9 from 0
1000 rows of 60 px rows 991–998, 40 px off rows 990–999
10 rows of 75 px the same rows, at scroll 320 scroll 150
1000 rows of 40 to 400 px already settled

Change

src/app/components/virtual-list/virtual-list.component.ts:

  • measure() applies the measures; when they change which rows the range holds, it renders the list (detectChanges), sets the padding for the new range, measures every rendered row, and applies those, until no measure moves a row. A pass whose rows are already on the page, in order, with the range's space below them, doesn't render. A render also checks the rows' contents, so a row's pending work, such as a message revealing its text, would otherwise grow it within the callback.
  • The loop stops after 16 renders (VirtualListResources.virtualListMeasurePasses) with a console warning (formatVirtualListMeasurePassesWarning). Rows that change height at every check reach it.
  • After a render within the callback, the observer stops observing the rows, the rows' box and the clamp checker's view until the next render observes them again. The browser delivers sizes in a frame's later passes only to boxes deeper than the shallowest it just delivered. It reports a ResizeObserver loop error for each box it leaves undelivered, and removed rows, the rows' box resized by the render, and a view that grows with its rows would each be one. Their first sizes come in the next frame, as their changes after a render did before. The measuring observer keeps the view, since it takes every view size as a change.
  • When the first measure since the source was set moves the scroll, the list reports its position, as the scroll event a frame later did on main. A scroll the browser clamps in any pass, which main reported at once, now joins that report: one measure makes at most one report, after its last pass.
  • A row drawn before its item came holds the estimate's height until the item is rendered into it, and that height is no longer taken as the row's measure. The open report comes with the first measure of a row with its item, and a scroll the browser makes before it, with no input from the person, joins that report instead of making one of its own. A person's scroll still reports at once.

src/app/models/height-ledger.ts: renderRangeFor gives the rows to render and read: rangeFor's, reaching further where rows aren't measured yet, counting each at the mean height of the rows measured so far rather than the estimate. The list's rendered range and its read-ahead use it; the visible range and the offsets don't change. This is in this PR because its CI needs it: with rows at a quarter of the estimate or less, each pass reached only a few rows further, so 1000 rows of 2 px took 14 frames of growing work (600 rows rendered and measured up to 16 times a frame, up to 700 ms a frame on macOS) and ran past the 15 s settle limit on CI's macOS x64. They now settle a frame after the first frame that shows rows.

src/app/interfaces/i-measured-box.ts: a measured box, a ResizeObserver entry's or a row's the list measures itself.

documents/kit/virtual-list.md: the first painted frame, the bound and its warning, and the position at open.

Consumers of the open position

With the render in the callback, the list no longer moved its scroll after the first paint, so it reported no position at open, which main did through the scroll event. A search of ui-components, teamrun and git for positionChange found two consumers, both in teamrun:

  • The history's saved reading place doesn't need it: the place stays in the chat store, which opening a chat doesn't clear.
  • The reply history does: it loads older replies only when a reported position's index is under 10 rows, and nothing else calls that load. So the list keeps reporting its position when its first measure moves its scroll, and a list placed where its scroll doesn't move reports none, as on main.

Tests

tests/app/components/virtual-list/virtual-list-first-frame.spec.ts:

  • For each feed above, the first frame that shows rows, read by a ResizeObserver made after the list's, the last script before the paint, equals the frame it settles at, which ends at the newest row. No ResizeObserver loop error and no warning fires.
  • A feed of 1000 rows of 60 px reports exactly one position at open, row 990 at distance 0, following; rows at the estimate, whose first measure leaves the scroll where it was, report none.
  • A source whose reads finish in a ResizeObserver made before the list's, so the items come after the rows are drawn and before the list measures them, still opens at row 990 with one report and a settled first frame. On the previous head it reported "991 40" alone, the place the browser's scroll passed through, which macOS once showed by chance.
  • 1000 rows of 2 px settle at their end within two frames of the first that shows rows, with no warning or loop error.
  • Rows that change height at every check never settle, so they reach the bound: the warning fires, with no loop error.
  • height-ledger.spec.ts: renderRangeFor reaches over unmeasured rows at the measured mean, and gives rangeFor's range while nothing is measured.

The checks:

  • With main's virtual-list.component.ts and .resources.ts, on Linux, the 55 px, 60 px and 75 px cases fail and the 40–400 px one passes. The bound's test names the new resources, so that run left it out.
  • At this head, the virtual list's specs and those of its users pass on Linux, macOS and Windows: the diff view, the gallery, the message and the virtual list row. These are the same ResizeObserver loop error counts as main, none.
  • virtual-list.component.spec.ts's test that lays out none of its settling after a render elsewhere, which reads the last position, passes unchanged.

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium

…ures, so its first painted frame shows them measured

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
…next render

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
…t the viewport until the next render

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
…ader may load more when it opens near an edge

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
… release the clamp checker's view after an in-frame render

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
… work doesn't resize them in the observer's callback

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
…osition

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
@rostislavrotaru rostislavrotaru self-assigned this Nov 30, 2026
…ast it

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium

@rostislavrotaru rostislavrotaru left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed: #281 at 2f04ccd
Verdict: Changes needed
Findings: 4 Should fix, 0 Low, as line comments

Agent: REVIEW1 (reviewer)
Agent-Model: Anthropic Opus 5.5, High

… report at open

A clamp in any pass and the open's moved scroll now make one report after the last
pass. The first-frame spec reads the reports, declares its fields, keeps its helpers
in classes, and stops reading frames even when an open fails.

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
…les, when items come after their rows

A row drawn before its item came holds the estimate's height; measuring it there took
the estimate for the row and spent the open report, and the browser's scroll as the row
bound reported a passing place. Such a row is no measure now, and a scroll the browser
makes before the rows' first measure joins the open report.

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
…red rows' mean height

Rows far below the estimate reached only a few rows further each pass, so 1000 rows of
2 px took 14 frames of growing work to settle and ran out the settle limit on CI. The
range the list renders and reads now counts an unmeasured row at the mean measured height,
and settles in a frame or two. The bound test settles those rows and counts its frames;
rows that change at every check reach the bound instead.

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium

@rostislavrotaru rostislavrotaru left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed: #281 at 7182604
Verdict: Approve
Findings: 0 Should fix, 0 Low, as line comments
Why it's right: the open reports once, after the first measure of a row with its item (placeholder slots no longer count), and the render range counts unmeasured rows at the measured mean, so a list of tiny rows settles in one frame; specs cover one report at open, none when unmoved, the gated double report, and the ledger's range. CI is green; macOS x64's rise is a slow runner (its build step rose as much), well under the limit.

Agent: LEAD (lead)
Agent-Model: Anthropic Opus 5.5, High

@rostislavrotaru
rostislavrotaru merged commit 79d6f5c into main Nov 30, 2026
19 checks passed
@rostislavrotaru
rostislavrotaru deleted the dev1/275-first-frame branch November 30, 2026 21:02
rostislavrotaru added a commit that referenced this pull request Nov 30, 2026
Closes #280

Built on #281, now merged; the branch merged main after it, so it holds
only this change.

## Change

`VirtualListComponent.focusRow(index)` scrolls the list the least that
shows the row at that position, renders it if it isn't rendered, and
focuses it once it is drawn, as the arrow keys do. It's for an app that
keeps its own cursor in a list and today has to reach into the list's
markup to focus a row.

- `virtual-list.component.ts`: `focusRow` clamps the position to the
list, so a position before the start focuses the first row and one past
the end the last; an empty list does nothing. It moves the focus the way
the keys do (`moveTo`).
- `virtual-list.component.ts`, `virtual-list.resources.ts`: a feed's row
takes a pending focus only once it has its `tabindex`, which it gets
when its item binds, a render after the row is drawn; before, the
pending focus was dropped on that first render and the row never took
it.
- `api/index.d.ts`: the method, with a file-panel example; the docs
site's component page shows it from the d.ts.
`documents/kit/virtual-list.md`: a line on it.

Limit: a row whose item is still loading takes the focus when it is
drawn only if the focus was in the list, as with the keys.

## Tests

`virtual-list.component.spec.ts`:
- a rendered row: focused in place, no scroll, and the list's Tab stop
moves to it;
- a row outside the rendered range (500 of 1000): rendered, scrolled
into view and focused, its box 270px to 296px from the view's top;
- positions out of range: -5 focuses the first row, 5000 the last; an
empty list leaves the focus where it was;
- a feed's row: focused once its item binds.

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
rostislavrotaru added a commit that referenced this pull request Dec 1, 2026
Closes #286

Moves the kit to 0.0.48, with what has merged since 0.0.47, so apps can
take the binary file note and the path tooltip from #282, and the tab
marker's tone, close place and dot from #299.

## What changes

- `version.json` is at 0.0.48.
- `CHANGELOG.md` has the 0.0.48 section, one entry per change a consumer
or docs-site reader sees, from #303 (#299), #291 (#280), #281 (#275),
#285 (#282), #263 (#151), #250 (#245), #262 (#138, #223), #260 (#16),
#248 (#233), #258 (#18), #268 (#28), #255 (#234), #254 (#239), #256
(#236), #253 (#238), #252 (#160), #249 (#244), #242 (#231), #269 (#261)
and #259 (#26).
- Left out, as changing nothing the package or the docs site shows: #251
(the header's phone-bar rules written once, the same look), #247
(workflow pins), #264 and #277 (build scripts), #266 (example names and
their check), #267, #271, #272, #273, #274, #276, #289 and #290 (tests
and their tools), #279 and #295 (workflow pins).

## Checks

No test covers these two files. The product names check reads the new
section in CI; it names no product.

Agent: DEV2 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant