# Paging

> Prefetch-based list paging: Next from a cached next page, never page.length === limit. Use when implementing Previous/Next, offset/limit pages, hasMore, list pagination, or choosing pages vs infinite scroll.

- Skill: `spencer1o1/paging` (Agent Skill)
- Install (CLI): `npx skillmds@latest add spencer1o1/paging`
- Raw SKILL.md: https://api.skillmd.com/api/skills/spencer1o1/paging/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: Spencer1O1 (https://skillmd.com/u/spencer1o1)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/spencer1o1/paging

---


# Paging

## Law

1. **Prefetch the next page** into memory whenever the current page is shown.
2. **Next enabled** ⇔ that cached next page exists **and** has `length > 0`. Empty prefetch ⇒ disable Next.
3. **On Next:** paint the cached page immediately, then prefetch the page after it.
4. **Never** derive `hasMore` / Next from `page.length === pageSize` (lies when the last page is exactly full).
5. Prefer **Previous / Next on the document** over a nested max-height infinite scroller when the screen has footer actions (Clear, Save, Delete, …) — nested scroll traps gestures and buries the footer.

## API

- Offset/limit or cursor — fine.
- Return **rows only**. Do not ship a guessed `hasMore` boolean; the UI learns that from the prefetch.

## Anti-patterns

- `hasMore = runs.length === limit`
- Fetching the destination page only after Next is pressed (always-spinner)
- Infinite scroll inside a tall nested container so the page cannot scroll past the list

