Virtual log: a drawn row is not drawn again when the drawn window moves #8
merged dash-scroll-memo was squashed into main as a633bd0 by jonas, 2026-11-28 01:23 UTC. jonas opened it 2026-11-28 01:23 UTC.
The list renders at each change of its window and called renderRow for every row of the window each time: about 155 rows in the Dash's Context Explorer since the overscan is 1,600 px (#6), where 20 of 603 frames on the way down were over 50 ms (0-2 before #6). Now each row is a memo component: it renders again when its row, its index or the caller's renderRow changes. For a caller: rows that read other state must get a new renderRow when that state changes (a useCallback with its dependencies, or no memo at all). pnpm check passes on 77668ee (113 files, 1,257 tests); the browser check shows 0 jumps and no dropped row in its 10 scenarios. Card: tasks/make-the-dash-scroll-and-render-smoothly-on-large-logs-like.md of /repos/task-board. Session: claude e7bfeefe-1067-494b-8f63-82177cb1beb9 on beelink 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0158EjAGDfCugWqZ9a2JTTgL
Conversation
Nobody has said anything yet.
Sign in to comment or to merge.
Files
1 file changed
M src/components/virtual-log/virtual-log.tsx
@@ -42,7 +42,15 @@ // Vertical breathing room is `paddingStart` and `paddingEnd`, not wrapper padding the virtualizer // cannot see. A row's spacing is padding, not margin, and a row renders its real height at once (no // deferred content): the first measurement is the one the anchor trusts. -import { useCallback, useEffect, useLayoutEffect, useRef, useState, type ReactNode } from "react"; +import { + memo, + useCallback, + useEffect, + useLayoutEffect, + useRef, + useState, + type ReactNode, +} from "react"; import { ArrowDownIcon, ArrowUpIcon } from "lucide-react"; import { elementScroll, @@ -266,9 +274,15 @@ ref={virtualizer.measureElement} className="absolute top-0 left-0 w-full" > - {virtualItem.index < rows.length - ? renderRow(rows[virtualItem.index]!, virtualItem.index) - : visibleTail} + {virtualItem.index < rows.length ? ( + <LogRow + row={rows[virtualItem.index]!} + index={virtualItem.index} + renderRow={renderRow as RenderRow} + /> + ) : ( + visibleTail + )} </div> ))} </div> @@ -346,6 +360,25 @@ </ScrollBubble> ); } + +type RenderRow = (row: unknown, index: number) => ReactNode; +/** A ROW THAT IS DRAWN IS NOT DRAWN AGAIN WHEN THE DRAWN WINDOW MOVES. The list renders at each + * change of its window (a scroll that brings one row in), and it called `renderRow` for every + * row of the window each time: about 155 rows in the Context Explorer, where 20 of 600 frames on + * the way down were over 50 ms (28 Nov 2026). A row renders again when its row, its index or + * the caller's `renderRow` changes: so a caller whose rows read other state gives a new + * `renderRow` when that state changes (a `useCallback` with its dependencies, or no memo). */ +const LogRow = memo(function LogRow({ + row, + index, + renderRow, +}: { + row: unknown; + index: number; + renderRow: RenderRow; +}) { + return renderRow(row, index); +}); type LayoutSnapshot = { rows: readonly unknown[];