Virtual log: an older page is asked for while fewer than 8,000 px stand over the view (#15)
jonas, 2026-11-28 15:39 UTC · 6b9b11341db61dd09293e4817323c263c3672d47 · parent d1184ed
1 file changed
M src/components/virtual-log/virtual-log.tsx
@@ -79,9 +79,18 @@ /** The tail's height until it is measured. */ const TAIL_ESTIMATE = 48; -/** Older pages are asked for when the top of the view is this near the top of what is loaded. */ -const LOAD_OLDER_WITHIN_PX = 1_500; +/** Newer pages (a detached window of history) are asked for when the view's end is this near the + * end of what is loaded. */ +const LOAD_NEWER_WITHIN_PX = 1_500; +/** READ AHEAD OF THE READER. An older page is asked for while fewer than this many px stand over + * the view: about ten screens, and each page that lands asks for the next until they do. A page + * is one read of the mind and takes about a second, so at 1,500 px a reader who went up at a + * steady pace met the list's top and its "reading older" line again and again (Jonas, 28 Nov + * 2026: "proactively load more events in the past […] too many loading breaks when scrolling + * up"). A view that wants its pages later wraps `older.loadOlder` (the agent chat does). */ +export const READ_AHEAD_PX = 8_000; + /** What the list needs to know of a row. Stable across renders (a constant, or `useMemo`): the * virtualizer lays every row out again when these change. */ export type VirtualLogRowInfo<Row> = { @@ -702,7 +711,8 @@ return () => observer.disconnect(); } -/** Loads older or newer pages when the scroll position stands within `LOAD_OLDER_WITHIN_PX` of an unexhausted edge. */ +/** Asks for an older page while fewer than `READ_AHEAD_PX` stand over the view, and for a newer one + * within `LOAD_NEWER_WITHIN_PX` of the end. After each render: a page that lands asks for the next. */ function usePageEdges( scrollRef: { current: HTMLDivElement | null }, older: OlderPages, @@ -710,12 +720,11 @@ ) { useEffect(() => { const el = scrollRef.current!; - if (!older.loading && !older.exhausted && el.scrollTop < LOAD_OLDER_WITHIN_PX) - older.loadOlder(); + if (!older.loading && !older.exhausted && el.scrollTop < READ_AHEAD_PX) older.loadOlder(); if ( !newer.loading && !newer.exhausted && - el.scrollHeight - el.clientHeight - el.scrollTop < LOAD_OLDER_WITHIN_PX + el.scrollHeight - el.clientHeight - el.scrollTop < LOAD_NEWER_WITHIN_PX ) newer.loadNewer(); });