Repository navigation
Closed
Description
Keep long conversations fast by rendering a window of recent items and loading older ones as the reader scrolls up, without moving the text they are reading. Write down how big a conversation this is built for.
Part of #94.
Why
Long chats get slow if every message is on the page. A window of recent items keeps them fast, but loading older items above the reader must not make the text jump. Hosts often page history from the server, so the hook has to work with in-memory history and with asynchronous paging alike.
What
src/hooks/use-history-window.ts:useHistoryWindow({ items, windowSize, step, hasEarlier, onLoadEarlier }). It starts at the latestwindowSizeitems, grows bystepnear the top, freezes while the reader is scrolled up and trims back when they return to the bottom. The "load more near the top" trigger (e.g.reachStart) is part of its public return value. Its doc comment records the windowing ceiling.src/ui/conversation-earlier.tsx:ConversationEarlier, the loading marker at the top.stories/chat/history-window.stories.tsx: the long sample chat from Add sample conversations for the chat stories #96, and a paged variant with a delayed loader.e2e/fixtures.tsx: ahistory-windowscenario, withe2e/history-window.spec.ts.src/hooks/use-history-window.test.ts; exports insrc/index.ts.
A reasonable starting point: keep 120 items and load 60 more near the top.
Requirements
- R25: window of the latest items; loads more near the top; freezes while scrolled up; trims on return; the item in view moves by no more than 1px when older items load.
- R26: works with host paging (
hasEarlier,onLoadEarlier);ConversationEarliershows the loading marker. - R27: the ceiling written beside the hook: why windowing rather than virtualization (native scrolling, find-in-page and focus within the window, variable heights with nothing to measure), the conversation size it is designed for, and when a host should page from the server instead.
- R5–R12: the shared component rules.
Constraints
- Use
captureAnchor/restoreAnchorfromuseConversation(Add Conversation and its scrolling #99) around each load; don't reimplement anchoring. - Never remove items while the reader is scrolled up.
- No wall-clock budgets in tests. Assert the ceiling deterministically (render counts, items mounted, number of trims).
- Tests use only the hook's public API.
- The shared rules in Replace the chat components with a stateless Conversation family #94 apply: no new dependency or peer, no optional-peer import, token-only styling, no change to existing modules, additions only to
src/index.tsande2e/fixtures.tsx.
Done when
- Unit tests cover:
- Window: starts at the latest
windowSize; the top trigger grows it bystep; returning to the bottom trims it back. - Paged: when the local slice is exhausted and
hasEarlieris true,onLoadEarlieris called once until it resolves. - Ceiling: over 10,000 in-memory items, the hook's work per update stays within the deterministic bound stated in its doc comment.
- Window: starts at the latest
- Browser spec: three loads in a row move the item in view by no more than 1px.
- No serious or critical axe violation in the new stories, in light or dark.
bun run check,bun run build,bun run test:e2eandbun run dep-guardpass.
Metadata
Metadata
Assignees
Labels
No labels
Activity