APP-33Recommended
Never render thousands of rows
Keep at most 200 rows in the page at once. Page long lists on the server, or render only the visible rows with a virtual list.
How to do it
Ask the API for pages with a cursor, as cursor pagination describes, with a page size such as 50. For lists people scroll through quickly, such as a log, use a virtual list from a library such as TanStack Virtual or vue-virtual-scroller. A virtual list breaks find-in-page and printing, so prefer pages when people search with the browser. Screen readers count only the rows in the page, so give each item aria-setsize and aria-posinset, or a table aria-rowcount and each row aria-rowindex.
Examples
TypeScript example
import { useVirtualizer } from '@tanstack/react-virtual';
export function LogList({ entries }: { entries: LogEntry[] }) {
const scroller = useRef<HTMLDivElement>(null);
const rows = useVirtualizer({ count: entries.length, getScrollElement: () => scroller.current, estimateSize: () => 36, overscan: 10 });
return (
<div ref={scroller} className="log-list" tabIndex={0} aria-label="Log entries">
<ul className="log-list-inner" ref={el => el?.style.setProperty('--list-height', `${rows.getTotalSize()}px`)}>
{rows.getVirtualItems().map(row => (
<li key={entries[row.index].id} className="log-row" aria-setsize={entries.length} aria-posinset={row.index + 1} ref={el => el?.style.setProperty('--row-start', `${row.start}px`)}>{entries[row.index].message}</li>
))}
</ul>
</div>
);
}
CSS example
.log-list-inner { position: relative; height: var(--list-height); }
.log-row { position: absolute; inset-inline: 0; transform: translateY(var(--row-start)); }
Python example
PAGE_SIZE = 50
@app.get("/api/log-entries")
def log_entries():
after = decode_cursor(request.args.get("cursor"))
rows = log_store.after(current_user().account_id, after, limit=PAGE_SIZE + 1)
has_more = len(rows) > PAGE_SIZE
return {
"items": [row.to_json() for row in rows[:PAGE_SIZE]],
"nextCursor": encode_cursor(rows[PAGE_SIZE - 1]) if has_more else None,
}
How to check
Load a list with 10,000 records in a browser test. The page holds no more than 200 row elements at the start and after scrolling to the end. In a virtual list, every item's aria-setsize or the table's aria-rowcount equals 10,000.
Sources
Related rules
- API-21 Page lists with cursors in API design
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/app-ui/lists-and-tables/bounded-lists">Agent Wranglers web app interface playbook</a>. In code you write, add a comment next to it with the same link.