This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index at /llms.txt, or add .md to any page's URL.
Recipe: a long list or grid that loads more
A long list or grid that loads more: virtualized rows, each holding N cards.
Virtualize rows, each holding N cards (two here). The list has one direct keyed
for; its template has one root in normal flow. Loading content follows the
for as a fixed child.
Load more rows as a list scrolls
Paste this into Claude, Cursor, Codex, or another agent.
contract
shape Product
id: string
title: string
shape GridRow
id: string
cards: Product[]
shape Catalog
rows: GridRow[]
hasNext: bool
shape Reply
ok: bool
component Shop
resource catalog = loadCatalog() as shape Catalog else empty()
mutation more as shape Reply refreshes catalog
derive loading = pending(catalog) or pending(more)
action loadMore
if catalog.hasNext and not loading
send more = nextPage()
view
list id="products" testId="products" virtualized=true appearance="none"
height="100%" estimated-item-height=124 reachend=loadMore reach-margin="100%"
for r in catalog.rows key=r.id
row gap=12 padding=12
for p in r.cards key=p.id
column flex=1 min-width=0 min-height=100
text p.title testId=`product-${p.id}`
if loading
text "Loading…" role="status" padding=12 testId="loading"
In app.ts, append the page before refreshes re-reads the resource's answer
(after a write). This fake API has three pages of twenty;
replace fetchPage with your API and its next cursor, and name its origin in grants:
ts
import type { Answer, Result, Sources } from './app.contract.d.ts';
export const grants = '';
type Product = Result<'loadCatalog'>['rows'][number]['cards'][number];
let items: Product[] = [];
async function fetchPage(page: number) {
return { items: Array.from({ length: 20 }, (_, i) => {
const id = String(page * 20 + i + 1);
return { id, title: `Product ${id}` };
}), next: page < 2 ? page + 1 : null };
}
let cursor: number | null = 0;
async function append() {
if (cursor === null) return;
const page = await fetchPage(cursor);
items = items.concat(page.items);
cursor = page.next;
}
const sources: Sources = {
loadCatalog: async () => {
if (cursor === 0) await append();
return { hasNext: cursor !== null, rows: items.filter((_, i) => i % 2 === 0)
.map((p, i) => ({ id: p.id, cards: items.slice(i * 2, i * 2 + 2) })) };
},
nextPage: async () => { await append(); return { ok: true }; },
};
export const answer: Answer = (source, args, store, storage, native) => sources[source](args, store, storage, native);
•
The loading child stays mounted while a page is out and is separate from the
keyed data. It appears after the last row, including when there are no rows.
hasNext stops requests after the last page; the pending guard prevents
duplicates. A failed mutation leaves the previous answer intact.
•
reach-margin is a nonnegative px or % of the port (default "100%").
Increase it to prefetch earlier. Flings extend the lead. A first page
shorter than two ports loads the next on first paint.
•
Is this helpful
Last updated November 18, 2026