Paging
Law
- Prefetch the next page into memory whenever the current page is shown.
- Next enabled ⇔ that cached next page exists and has
length > 0. Empty prefetch ⇒ disable Next. - On Next: paint the cached page immediately, then prefetch the page after it.
- Never derive
hasMore/ Next frompage.length === pageSize(lies when the last page is exactly full). - 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
hasMoreboolean; 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