Final step of the virtualization plan. Turns the virtualized render
path on in production behind a row-count threshold, and adds regression
tests covering every gate.
- `VIRTUALIZATION_ROW_THRESHOLD = 60`. Short lists stay on the direct
render path (no wrapper, no position: absolute, no measurement
churn). Above the threshold the virtualizer takes over. Threshold is
sized so conversations under ~one session of activity don't pay the
virtualization cost; it activates once scrolling through a longer
history.
- `shouldVirtualize` now requires `renderRows.length >= threshold` in
addition to the existing opt-in and scroll-ref checks.
- `MessagesPanel` opts into virtualization for every layout it wires
(inline / sidebar / bottom-sheet). The internal threshold then
decides when to actually enable it, so callers don't need per-layout
heuristics.
- Tests: adds a new `ActivityTimeline virtualization threshold` block
covering (a) below-threshold list stays on the direct path,
(b) no viewport → direct path regardless of count, (c) above
threshold + viewport with `virtualizationEnabled` flips to the
virtualized render path (simulated by clicking "show all" past
pagination).
With this in, #70 → #74 combine to deliver:
- correct IntersectionObserver roots in scroll containers
- atomic render rows with stable keys
- windowed rendering with DOM-measured scrollMargin and measureElement
- auto-on when the cost of direct rendering actually shows up
Fifth step of the virtualization plan. Two small, coupled changes that
make the virtualized path stable without a merged-ref helper.
- Attach `rowVirtualizer.measureElement` to the existing virtualizer
wrapper div. Because the wrapper carries no padding or margin, its
bounding box matches the inner row, so the observer ref (which stays
on the inner AnimatedHeightReveal node) and the measure ref (on the
outer wrapper) address the same effective height. No merged ref
callback is needed.
- Suppress mount-based entry animation inside the virtualized path.
The virtualizer mounts and unmounts rows as the user scrolls them in
and out; without this, the "new item" fade would replay every time
an older row re-entered the viewport. `renderTimelineRow` now takes
an optional `suppressEntryAnimation` flag and forwards `isNew=false`
to both `LeadThoughtsGroupRow` and `MemoizedMessageRowWithObserver`
when set. The direct render path is unchanged.
Still dormant in this release — `viewport.virtualizationEnabled` stays
false at every call site. PR #6 adds the threshold gate, tests, and
opt-in wiring.
Fourth step of the virtualization plan. Adds `useVirtualizer` wiring
with a DOM-measured `scrollMargin`, gated behind
`viewport.virtualizationEnabled`. Dormant in this release — no caller
flips the flag yet — so behavior is unchanged.
- Imports `useVirtualizer` from `@tanstack/react-virtual`. Fixed
per-kind estimates (`ROW_SIZE_ESTIMATES`) drive `estimateSize`. Keys
come from `row.key`, so row identity matches the renderRows model.
- `shouldVirtualize` requires all of: contract says enabled, a scroll
element ref is present, and there is at least one row. Otherwise the
render falls back to the direct `renderRows.map(...)` path from PR
#72.
- Measures `scrollMargin` via `ResizeObserver` on both the scroll
element and the timeline root, plus `scroll` and `resize` listeners,
all rAF-batched. Avoids hand-summed heights that drift when
composer/status/padding change.
- Virtualized path renders an absolute-positioned list inside a sized
container (`height = getTotalSize()`). `translateY` subtracts
`scrollMargin` so rows align to the timeline's own origin rather
than the scroll container's top.
This PR intentionally does *not* enable `measureElement` (PR #5) or
flip `virtualizationEnabled` for any layout (PR #6) — both rely on
this wiring landing first.
Third step of the virtualization plan. Pure refactor — no UI change, no
virtualization yet. Prepares the timeline for row-level windowing.
- Introduces `TimelineRow`, a discriminated union of `session-separator`,
`lead-thought-group` (pinned and non-pinned), `compaction-divider`,
and `message-row`. Each row maps 1:1 to a single visual element.
- Adds a `renderRows` useMemo that walks `timelineItems` once and emits
atomic rows, hoisting session separators out of the Fragment bundle
that used to pair them with their owning item. This is the shape a
windowing layer needs: each row measurable and addressable
independently.
- Extracts a `renderTimelineRow(row)` helper that switches on `row.kind`
and returns the same JSX the previous inline render produced. Logic
per kind is identical — keys, memoization, collapse props, pinned
thought "live" semantics — so there is no visual diff.
- The render body collapses from two blocks (pinned + `.slice().map()`)
into a single `renderRows.map(renderTimelineRow)` call.
Follow-ups will virtualize `renderRows` with measured row heights and
tighten observer/animation wiring; pagination, collapse state, zebra
striping, and `groupTimelineItems` are untouched.
Second step of the virtualization plan. No virtualization yet. This PR
makes IntersectionObserver-based visibility tracking correct inside
scroll containers (sidebar, bottom-sheet), which is a prerequisite for
virtualizing the timeline.
- Introduces `TimelineViewport` — a grouped contract passed as a single
`viewport` prop on `ActivityTimeline`. Holds `scrollElementRef`,
`observerRoot`, `scrollMargin`, and `virtualizationEnabled`.
- `MessageRowWithObserver` and `LeadThoughtsGroupRow` now create their
`IntersectionObserver` with `root = observerRoot?.current ?? null`
instead of defaulting to the document viewport. Unread marking now
fires when rows enter their real scroll parent.
- `MessagesPanel` resolves the active scroll owner from `position`
(inline from parent ref, sidebar from `sidebarScrollRef`, bottom-sheet
from `bottomSheetScrollRef`) and passes it into ActivityTimeline.
- Tests: stubs `IntersectionObserver` to capture `options.root` and
asserts null when no viewport is passed, and the provided element when
`viewport.observerRoot` is set.
`scrollMargin` and `virtualizationEnabled` are included in the contract
but not consumed yet — they land in follow-up PRs (#4/#5).