Persist document list pagination across navigation - #1288
Persist document list pagination across navigation#1288Pallavikumarimdb wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthrough
ChangesPagination localStorage persistence
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
76f9fad to
984076f
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@apps/papra-client/src/modules/shared/pagination/query-synchronized-pagination.test.ts`:
- Around line 62-72: The pagination fallback test verifies localStorage loading,
but it does not assert the mount-time URL synchronization introduced by
`createParamSynchronizedPagination`. Update this test to also expect the initial
`setSearchParams(..., { replace: true })` call when `pageSize` is missing from
the URL, using the same `createRoot` setup and `getPagination` flow so the
regression is covered.
In
`@apps/papra-client/src/modules/shared/pagination/query-synchronized-pagination.ts`:
- Around line 26-32: Reject invalid persisted page sizes in
query-synchronized-pagination by tightening the localStorage restore logic: in
the pagination initialization path, only accept values that are positive
integers instead of any numeric string, and ignore/reset anything like 0,
negatives, fractions, or Infinity. Update the validation around the stored value
used to set initialPageSize so that getPagination and downstream callers such as
fetchOrganizationDocuments never receive a bad pageSize from stale storage. Also
apply the same validation anywhere the persisted page size is read or written so
the URL and storage stay in sync with only valid values.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 47c262b0-4d92-473a-b9de-521ee3773c9b
📒 Files selected for processing (5)
apps/papra-client/src/modules/document-views/pages/document-view.page.tsxapps/papra-client/src/modules/documents/pages/documents.page.tsxapps/papra-client/src/modules/organizations/pages/organization.page.tsxapps/papra-client/src/modules/shared/pagination/query-synchronized-pagination.test.tsapps/papra-client/src/modules/shared/pagination/query-synchronized-pagination.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/papra-client/src/modules/shared/pagination/query-synchronized-pagination.ts (1)
61-80: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winNormalize invalid query params too, not just missing ones.
When
pageorpageSizeis present but invalid (for example?pageSize=-100),getPagination()falls back to storage/defaults, but this effect will not repair the URL because it only checks=== undefined. That leaves the address bar out of sync with the active pagination state and keeps the bad value around on refresh/share/back-navigation. Treat invalid params the same as missing ones when deciding whether to writenextParams.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/papra-client/src/modules/shared/pagination/query-synchronized-pagination.ts` around lines 61 - 80, The pagination sync effect in query-synchronized-pagination.ts only repairs missing query params, so invalid values like negative or non-numeric page/pageSize can remain in the URL while getPagination() falls back to defaults. Update the createEffect block to validate the current searchParams values for pageIndexParamName and pageSizeParamName, and treat invalid values the same as undefined when building nextParams. Keep the fix localized to the createEffect/getPagination flow so setSearchParams still rewrites the URL with the normalized pagination state.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In
`@apps/papra-client/src/modules/shared/pagination/query-synchronized-pagination.ts`:
- Around line 61-80: The pagination sync effect in
query-synchronized-pagination.ts only repairs missing query params, so invalid
values like negative or non-numeric page/pageSize can remain in the URL while
getPagination() falls back to defaults. Update the createEffect block to
validate the current searchParams values for pageIndexParamName and
pageSizeParamName, and treat invalid values the same as undefined when building
nextParams. Keep the fix localized to the createEffect/getPagination flow so
setSearchParams still rewrites the URL with the normalized pagination state.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 76306d02-6f01-471d-8563-1db969b75194
📒 Files selected for processing (2)
apps/papra-client/src/modules/shared/pagination/query-synchronized-pagination.test.tsapps/papra-client/src/modules/shared/pagination/query-synchronized-pagination.ts
Contributor License Agreement✅ Everyone who contributed to this pull request has signed the CLA for it. |
Description
Resolves an issue where changing the page limit/pagination preference on the document list was lost when navigating away and returning to the page.
Changes
createEffecttocreateParamSynchronizedPaginationthat automatically synchronizes active URL parameters with non-default stored page limits/indices fromlocalStorageon mount or navigation.Closes: #1085
Summary by CodeRabbit