fix(search): normalize client pagination state#362
Conversation
Greptile SummaryThis PR normalizes the
Confidence Score: 5/5Safe to merge — the normalization logic is correct, the test covers the key regression, and no incorrect data is ever displayed. The clamping and URL-replacement logic is straightforward and correct. The only notable side-effect (a redundant second fetch when the URL is normalized) does not produce wrong data or visible bad state in practice — both fetches use identical parameters and return identical results. The change is narrow in scope and well-tested. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Browser
participant SearchResults
participant router
participant API
Browser->>SearchResults: "Mount with ?page=-4"
SearchResults->>SearchResults: parsePageParam("-4") → 1
Note over SearchResults: rawPageParam ≠ String(pageParam)
SearchResults->>router: "replace("/search?q=...") [no page param]"
SearchResults->>API: "fetch /api/search?page=1&..."
API-->>SearchResults: "{ page:1, total:20, ... }"
SearchResults->>Browser: Render "Page 1 of 2"
router-->>SearchResults: searchParams updated (URL now clean)
SearchResults->>SearchResults: "Effect re-fires (rawPageParam = null)"
SearchResults->>API: "fetch /api/search?page=1&... (2nd, redundant)"
API-->>SearchResults: Same data
SearchResults->>Browser: Re-render (loading flash possible)
Reviews (2): Last reviewed commit: "fix(search): replace malformed paginatio..." | Re-trigger Greptile |
Summary
/search?page=before client state and fetches use itThis is a distinct follow-up to #325: that PR clamps the API route, while the search component could still render impossible page numbers from the URL.
Paid task: https://ugig.net/gigs/abd6b2a0-e728-48cf-a46f-f99e419ed94e
Testing
corepack pnpm exec vitest run src/components/search/SearchResults.test.tsxcorepack pnpm exec eslint src/components/search/SearchResults.tsx src/components/search/SearchResults.test.tsxgit diff --checkcorepack pnpm type-check(blocked by pre-existing errors insrc/app/api/affiliates/offers/route.test.tsandsrc/app/api/applications/[id]/route.test.ts)corepack pnpm build(compiles successfully, then page-data collection is blocked by missingOPENAI_API_KEYfor/api/profile/import)