Skip to content

fix: show page number when totalPages equals 1 in Pagination#1670

Closed
polpo666 wants to merge 1 commit intothemesberg:mainfrom
polpo666:fix/pagination-single-page
Closed

fix: show page number when totalPages equals 1 in Pagination#1670
polpo666 wants to merge 1 commit intothemesberg:mainfrom
polpo666:fix/pagination-single-page

Conversation

@polpo666
Copy link
Copy Markdown

@polpo666 polpo666 commented Apr 12, 2026

Summary

Fixes issue #1048 - "Pagination is broken if there is only one page".

The range() helper was returning an empty array when start >= end, but it should return a single element when start === end (i.e., when totalPages = 1).

Changes

  • Modified helpers.ts: Changed condition from start >= end to start > end
  • Updated test to verify edge case behavior

Verification

Tested manually:

  • range(1, 1) returns [1] (single page) ✓
  • range(1, 5) returns [1, 2, 3, 4, 5] (normal case) ✓
  • range(20, 10) returns [] (invalid range) ✓

Breaking changes

None.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected pagination range calculation to properly handle boundary conditions where start and end values are equal.

The range() helper was returning an empty array when start >= end, but it should
return a single element when start equals end (i.e., totalPages = 1).

This fixes the bug where the current page number was not displayed when
there is only one page in the Pagination component.

Fixes themesberg#1048
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 12, 2026

⚠️ No Changeset found

Latest commit: 95b3948

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 12, 2026

Someone is attempting to deploy a commit to the Bergside Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 12, 2026

📝 Walkthrough

Walkthrough

The range() function in pagination helpers was updated to return a single-element array [n] when start === end, instead of returning an empty array. Previously, the boundary condition was start >= end; it is now start > end. Tests were updated accordingly to verify this behavioral change.

Changes

Cohort / File(s) Summary
Pagination Range Function
packages/ui/src/components/Pagination/helpers.ts, packages/ui/src/components/Pagination/helpers.test.ts
Modified range(start, end) boundary condition from start >= end to start > end, allowing range(n, n) to return [n] instead of []. Test cases updated to reflect this new behavior with a dedicated test for the equality case.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A hop, a skip, a boundary fixed—
Where once was empty, now a mix!
When start meets end in harmony,
One element hops wild and free! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix: adjusting the range() boundary condition to display page numbers when there is only one page in the Pagination component.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/ui/src/components/Pagination/helpers.ts (1)

5-5: ⚠️ Potential issue | 🟡 Minor

Update JSDoc to match the new boundary behavior.

The return description on Line 5 still says “greater than or equal to end,” but the function now returns [] only when start > end.

📝 Suggested doc fix
- * `@returns` An array of numbers from start to end. Returns empty array if start is greater than or equal to end.
+ * `@returns` An array of numbers from start to end. Returns empty array if start is greater than end.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/ui/src/components/Pagination/helpers.ts` at line 5, Update the JSDoc
for the range function in packages/ui/src/components/Pagination/helpers.ts:
change the `@returns` description to state that the function returns an empty
array when start > end (not "greater than or equal to end"), so the docs match
the current implementation of range.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/ui/src/components/Pagination/helpers.ts`:
- Line 5: Update the JSDoc for the range function in
packages/ui/src/components/Pagination/helpers.ts: change the `@returns`
description to state that the function returns an empty array when start > end
(not "greater than or equal to end"), so the docs match the current
implementation of range.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a8991189-1357-4b8c-a6e3-70bb74dda1c2

📥 Commits

Reviewing files that changed from the base of the PR and between 0f526aa and 95b3948.

📒 Files selected for processing (2)
  • packages/ui/src/components/Pagination/helpers.test.ts
  • packages/ui/src/components/Pagination/helpers.ts

@polpo666 polpo666 closed this Apr 13, 2026
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.

1 participant