Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-13451-fixed-1772457963491.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Fixed
---

IAM / Entities & Roles client-side pagination on page refresh ([#13451](https://github.com/linode/manager/pull/13451))
8 changes: 4 additions & 4 deletions packages/manager/src/hooks/usePaginationV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ describe('usePaginationV2', () => {
expect(mockNavigate).not.toHaveBeenCalled();
});

it('should handle page clamping to 1 for empty data', async () => {
it('should not reset page when data is empty (e.g. still loading) to preserve URL on reload', async () => {
queryClient.setQueryData(['profile', 'preferences'], {
pageSizes: { 'test-key': 25 },
});
Expand All @@ -826,9 +826,9 @@ describe('usePaginationV2', () => {
expect(result.current.page).toBe(1);
});

await waitFor(() => {
expect(mockNavigate).toHaveBeenCalled();
});
// Should not trigger navigation when totalCount is 0 so that page from URL
// is preserved on reload while data is still loading
expect(mockNavigate).not.toHaveBeenCalled();
});

it('should auto-reset page when data changes and current page becomes invalid', async () => {
Expand Down
9 changes: 7 additions & 2 deletions packages/manager/src/hooks/usePaginationV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,15 @@ export const usePaginationV2 = <T extends TableSearchParams, D = unknown>({
}, [clientSidePaginationData, clampedPage, pageSize]);

React.useEffect(() => {
if (paginatedData !== undefined && clampedPage !== page) {
if (
paginatedData !== undefined &&
totalCount !== undefined &&
totalCount > 0 &&
clampedPage !== page
) {
setPage(clampedPage);
}
}, [clampedPage, page, paginatedData, setPage]);
}, [clampedPage, page, paginatedData, setPage, totalCount]);

return {
handlePageChange: setPage,
Expand Down