Why this matters

The bug. Array.slice(start, end) is end-exclusive. To get pageSize items, end = start + pageSize. The + 1 returns pageSize + 1 items, leaking the next page's head.

Why it survives review. The off-by-one isn't visible until you scroll past page 1 and see a duplicate row. Unit tests usually only check length === pageSize, which fails noisily — but this version *also* fails noisily. So why does it ship? Because in many projects, infinite-scroll dedupes by id and the duplicate is invisible.

Heuristic. Anywhere you compute slice indices, write the test for page = 1, not just page = 0.

Review heuristic

When a comparison involves <, <=, >, >=, or -1, work the boundary case by hand: what happens with zero items? One item? n+1 items? Pagination, buffer length, and recursion are the three places where the bug is most likely.

External reference: CWE-193: Off-by-one Error.