Skip to content

Conversation

@gethinwebster
Copy link
Member

@gethinwebster gethinwebster commented Mar 3, 2025

Remove logic that resets current page index to 1 if a value greater than the total available number of pages is passed in. Why? This logic causes problems when trying to load subsequent pages of data from a paginated (but not filter-/sort-enabled) API.

Issue #, if available: Xw9JA4nAmlRd

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link

codecov bot commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.22%. Comparing base (fdb530d) to head (dd37e05).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #99   +/-   ##
=======================================
  Coverage   99.21%   99.22%           
=======================================
  Files          14       14           
  Lines         512      515    +3     
  Branches      181      183    +2     
=======================================
+ Hits          508      511    +3     
  Misses          4        4           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gethinwebster gethinwebster marked this pull request as ready for review March 4, 2025 08:46
@gethinwebster gethinwebster requested a review from a team as a code owner March 4, 2025 08:46
@gethinwebster gethinwebster requested review from orangevolon and removed request for a team March 4, 2025 08:46
const pageSize = pagination.pageSize ?? DEFAULT_PAGE_SIZE;
const pagesCount = Math.ceil(items.length / pageSize);
let pageIndex = currentPageIndex ?? 1;
if (pageIndex < 1 || pageIndex > pagesCount || Number.isNaN(pageIndex)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the subsequent pages are about to load, shouldn't the consumer set the pagesCount too? So that, if currently i'm on page 10 out of 10, and I wanna go next and I set the page number to 11, then shouldn't I also set the pagesCount to 11?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pagesCount is calculated internally by collection hooks, not passed in

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which is the root of the problem here: when clamping the pageIndex to the calculated pagesCount, it becomes impossible to proactively set the pageIndex to the index of a lazily/not-yet loaded page, because the previous logic then reset the pageIndex to one

@gethinwebster gethinwebster added this pull request to the merge queue Mar 5, 2025
Merged via the queue into main with commit b6007dd Mar 5, 2025
38 checks passed
@gethinwebster gethinwebster deleted the dev-v3-gethinw-remove-clamping branch March 5, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants