Scaled scroll (spike S3)
SAFE_MAX is 10,000,000 px.
Context
- Spike: S3 in
docs/plan.md, section 11
A browser has a maximum height for one element. The values that we know are approximately 33.5M px in Chrome and 17.9M px in Firefox. We did not confirm these values, and we do not know the Safari value. A list of 1M rows at 32 px is 32M px. That is near the Chrome cap and more than the Firefox cap. Above the cap, the sizer element gets shorter than the list, and the last rows cannot be reached.
The plan of record (section 11, S3) is a safe cap of 10M px. Above the cap, Lattice maps the
virtual offset to scrollTop with a ratio. Wheel, keyboard and touch input move in virtual
space. A "row N of M" hint shows during a scrollbar drag.
Decision drivers
Not recorded in the original ADR.
Options considered
Not recorded in the original ADR.
Decision
SAFE_MAXis 10,000,000 px. The sizer element ismin(totalSize, SAFE_MAX).- The ratio is the ratio of the two scroll ranges:
(totalSize - viewport) / (sizer - viewport). Thus offset 0 and the end map exactly. A ratio of total sizes does not map the end exactly. BelowSAFE_MAXthe ratio is 1 and the map is the identity. - The virtual offset is the truth.
ScaledScrollkeeps it. When it writesscrollTop, the read-back of that write gives the same virtual offset, not a value mapped back fromscrollTop. Only a scroll thatScaledScrolldid not write (a scrollbar drag) maps the real offset back to a virtual offset. This is necessary becausescrollTophas whole-pixel precision. At 100M rows of 32 px the ratio is approximately 320, so one real pixel is 10 rows. bindScaledInputmoves wheel and key input in virtual space while the list is scaled. It listens withpassive: falseand callspreventDefault. One wheel step of N px moves the list N virtual px. A wheel event in lines (deltaMode1, Firefox) is 16 px for each line. PageUp and PageDown move one viewport. BelowSAFE_MAXthe browser keeps all input. A ctrl+wheel (zoom) and a wheel with no vertical part go to the browser. The sideways part of a diagonal wheel goes toscrollLeft. Ascrolllistener sends a scroll that the layer did not write (a drag) toonScroll.- The renderer gets two values from
ScaledScroll:sizerSizefor the sizer element, andshift(realOffset - virtualOffset). The real position of an item isitem.start + shift. This puts the item at the virtual offset at the top of the viewport. rowAt(virtualOffset, count, totalSize)gives the 1-based row for the "row N of M" hint. It assumes rows of one size. With measured rows, usegetVirtualItemForOffset.- The scaled layer is Lattice code in
src/scaled-scroll.ts. The portedsrc/core/has one Lattice change for it: thescrollScaleoption (see the wire-up below).
The wire-up into the Virtualizer
The Virtualizer options observeElementOffset and scrollToFn are not sufficient. The
Virtualizer also reads the element directly in two private methods:
_readElementOffsetreadsscrollTopto find its own writes._elementMaxScrollOffsetreadsscrollHeight - clientHeightfor the end clamp.
Above the cap, both values are real, not virtual. Without a change, the end clamp stops
scrollToIndex at the sizer height.
The Virtualizer has one new option, scrollScale: ScaledScroll. When it is set, four places
go through it:
- The
observeElementOffsetcallback:scale.onScroll(offset)gives the virtual offset. - The write (
_scrollToOffset):scale.scrollTo(target)gives the real offset forscrollToFn. The target includes the adjustments, soscrollToFngets no adjustments. _readElementOffset:scale.toVirtual(offset). This read does not change theScaledScroll. It gives the exact virtual offset for a read-back of an own write._elementMaxScrollOffset:toVirtualOffset(max, scale.size), so the real end maps to the virtual end.
Before each of these, the Virtualizer sets scale.size to its getTotalSize() and its
viewport size. Thus the owner does not keep the sizes current. The change is a Lattice change
to src/core/index.ts, recorded in PORT_MAP.md. The renderer still gives the sizer element
scale.sizerSize and moves each item by scale.shift. The VirtualizerState bridge does not
set scrollScale yet.
Consequences
- A list of any length can scroll to its last row, in every browser, with a sizer of 10M px or less.
- Wheel and key steps feel the same at 1k rows and at 100M rows.
- A scrollbar drag is coarse above the cap. One real pixel is
ratiovirtual pixels. At 1M rows of 32 px the ratio is approximately 3.2, so a drag can stop at each row. At 100M rows it can stop only at each tenth row. The drag hint shows the row. - Touch momentum stays in real pixels, so a fling above the cap moves
ratiotimes further than below the cap. This is a known limit. A fix needs a custom fling (pointer events and our own momentum), and that is not in this spike. - Native "find in page" and anchor links do not work on rows that are not rendered. That is true for all virtual scroll, not only for scaled scroll.
- The docs recommend the server row model above approximately 1M rows (plan section 11).
- If the CI check shows that scaled scroll fails in a browser, the fallback is paged virtual scroll (a jump list).
Confirmation
Evidence
Tests: packages/virtual/tests/scaled-scroll.test.ts (Vitest and fast-check, jsdom).
- Property tests for lists of 1 to 5M rows, with row sizes from 20 to 60 px:
- Offset 0 and the end map exactly, in both directions.
- The map is monotonic (not decreasing) after the real offset is rounded to whole pixels.
- A virtual offset goes to a whole-pixel
scrollTopand back within 1 row. The error of this round trip is at mostratio / 2, so the bound is true below approximately 20M rows. Above that, decision 3 is necessary.
ScaledScrollat 100M rows (ratio approximately 320): its own write reads back to the exact virtual offset for any target. One wheel delta of N moves N virtual px. 1000 steps of 3 px give 3000 px, with no drift.bindScaledInputin jsdom: a wheel event and a PageDown key move in virtual space and callpreventDefault. BelowSAFE_MAXthe input goes to the browser.
Tests: packages/virtual/tests/scaled-virtualizer.test.ts (Vitest, jsdom, an element with a
whole-pixel scrollTop that clamps to the sizer).
- At 100M px,
scrollToIndex(count - 1, { align: 'end' })putsscrollTopat the sizer end andscrollOffsetat the virtual end. The last row is in the range. scrollToOffset(50_000_001)reads back as exactly 50,000,001.- A
scrollTopthat the layer did not write (a drag) maps totoVirtualOffset. - With
bindScaledInput, one wheel step of 100 px movesscrollOffsetby 100 px. - Below
SAFE_MAXthe map is the identity.
jsdom has no layout, so these tests do not prove the browser caps or the scrollTop
precision.
Real-browser checks (CI in Chrome, Firefox and Safari)
The CI test is not part of this spike. It must assert these items in each browser:
- The cap. A sizer of
SAFE_MAX(10M px) givesscrollHeightequal to 10M px. Record the largest height that the browser keeps, to confirm or correct the values in this ADR. - The
scrollTopprecision at large values. A write of a value near 10M px reads back within 1 px. - The end. A scroll to the end (End key, and
scrollToIndex(count - 1)) shows the last row fully, with its bottom edge at the bottom of the viewport. - The start. A scroll to the start (Home key) shows row 1 at the top.
- The wheel. One wheel step moves the first visible row by the step in px divided by the row
size (a few rows), not by the step times the ratio. In Firefox, check that
deltaMode1 (lines) gives the same distance as in Chrome. - The listener. The wheel listener is not passive, so
preventDefaultstops the native scroll. There is no double move (native and virtual). - The keys. PageDown moves one viewport. ArrowDown moves 40 px. The keys work only when the scroll element has focus.
- The drag. During a scrollbar drag the hint shows row N. After release, row N is the first visible row (within 1 row when the ratio is less than the row size).
- Touch (Safari on iOS). Record the distance of a fling above the cap. This is the known limit in the consequences.
- Each test runs at 1M rows and at 100M rows of 32 px.
Interview record
Each question of the interview with its answer and its source. A fact from the code or a document, a question that the author did not ask, and an assumption are rows too.
| Question | Answer | Source |
|---|---|---|
| Where does the text of this page come from? | From the Markdown file docs/adr/0003-scaled-scroll.md at commit 4c77ac4. The text of each section is the text of the Markdown file. A section that the Markdown file does not have says so. | Document: docs/adr/0003-scaled-scroll.md |
Changelog
| Date | Author | Change |
|---|---|---|
| 2026-12-01 | Joe Gaudet | Status in the Markdown file: Proposed. The math, the input layer and the wire-up into the Virtualizer have tests. The real-browser checks are not done. |
| 2026-12-03 | Joe Gaudet | Commit 7ce4af2: Lattice 1.0 (#1) |
| 2026-12-04 | Joe Gaudet (agent) | Converted from docs/adr/0003-scaled-scroll.md to this page. The text is the text of the Markdown file. |
The adr skill of skillsaw wrote this page. The HTML in this file is the source of truth. The diagrams are the Mermaid sources in it.