Skip to content

Commit b63d3ca

Browse files
committed
fix(pagination): derive page from explicit offset
1 parent bacd8bc commit b63d3ca

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

libs/storefront-data/src/products/pagination.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ export function resolvePagination(
1616
): PaginationState {
1717
const limit = input.limit ?? defaultLimit
1818
const offset =
19-
input.offset ?? (input.page ? (input.page - 1) * limit : 0)
20-
const page = input.page ?? (limit > 0 ? Math.floor(offset / limit) + 1 : 1)
19+
input.offset ?? (input.page != null ? (input.page - 1) * limit : 0)
20+
const page =
21+
input.offset != null
22+
? limit > 0
23+
? Math.floor(offset / limit) + 1
24+
: 1
25+
: input.page ?? (limit > 0 ? Math.floor(offset / limit) + 1 : 1)
2126

2227
return { page, limit, offset }
2328
}

0 commit comments

Comments
 (0)