fix(feed): clamp lounge page pagination#359
Conversation
Greptile SummaryThis PR routes the lounge feed page's
Confidence Score: 5/5Safe to merge — a minimal, targeted fix with full regression test coverage and no new risk surface. The change is a single-line swap to a well-tested, already-in-use helper. The helper's output is provably bounded (integer 1–1000), so the Supabase No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["searchParams.page (string | undefined)"] --> B["parsePageParam(value)"]
B --> C["parseInt(value || '1', 10)"]
C --> D{Number.isFinite?}
D -- No (NaN / Infinity) --> E["return 1"]
D -- Yes --> F["Math.max(parsed, 1)"]
F --> G["Math.min(result, 1000)"]
G --> H["safe page integer (1–1000)"]
H --> I["offset = (page - 1) * limit"]
I --> J["supabase .range(offset, offset + limit - 1)"]
Reviews (2): Last reviewed commit: "test(feed): cover negative infinity page..." | Re-trigger Greptile |
| const sort = resolvedParams.sort || "hot"; | ||
| const tag = resolvedParams.tag || undefined; | ||
| const page = Number(resolvedParams.page) || 1; | ||
| const page = parsePageParam(resolvedParams.page); |
There was a problem hiding this comment.
Same unsafe pattern exists in two other files —
src/components/search/SearchResults.tsx (line 37) and src/app/api/gigs/route.ts (line 27) still use Number(searchParams.get("page")) || 1, which has the same Infinity-bypass that this PR fixes here. Those pages are not part of this diff but share the identical pre-fix behaviour.
Summary
parsePageParamhelperpagevalues from producing unsafe Supabase rangesFixes #358.
Paid task context: https://ugig.net/gigs/abd6b2a0-e728-48cf-a46f-f99e419ed94e
Verification
.\node_modules\.bin\vitest.CMD run src/lib/pagination.test.ts.\node_modules\.bin\eslint.CMD src/app/feed/page.tsx src/lib/pagination.test.tsgit diff --checkExisting upstream check blockers
.\node_modules\.bin\tsc.CMD --noEmitreaches unrelated existing errors insrc/app/api/affiliates/offers/route.test.ts:53andsrc/app/api/applications/[id]/route.test.ts:21.corepack pnpm run buildcompiles successfully and progresses through static generation when given a process-local dummy OpenAI key, then stops because the local checkout has no Supabase service-role configuration.