openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Pagination previous arrow on history page links to the same page

Open Saad259 opened this issue 7 months ago • 4 comments

Problem

On the revision history page (/help?m=history), navigating to page 2 enables the "previous page" arrow that links back to page 2 instead of page 1. Clicking it reloads back to page 2.

Reproducing the bug

  1. Navigate to https://openlibrary.org/help?m=history
  2. Click the next page (→) arrow at the bottom of the table to go to page 2 (/help?m=history&page=2)
  3. Click the previous page (←) arrow at the bottom of the table

Expected behaviour

The previous page arrow on page 2 should link to /help?m=history (page 1), and more generally the previous arrow on page n should link to page n-1.

Actual behaviour

The previous page arrow on page 2 links to page=2 (the current page), so clicking it does nothing.

Context

  • Browser (Chrome, Safari, Firefox, etc):
  • OS (Windows, Mac, etc):
  • Logged in (Y/N):
  • Environment (prod, dev, local): prod

Breakdown

Implementation Details (for maintainers)

Requirements Checklist

  • [ ]

Related files

Stakeholders


Instructions for Contributors

  • Please run these commands to ensure your repository is up to date before creating a new branch to work on this issue and each time after pushing code to Github, because the pre-commit bot may add commits to your PRs upstream.

Saad259 avatar Apr 17 '26 14:04 Saad259

I'm ready to work on this as I've looked into it and the fix seems fairly trivial. Happy to get feedback on the direction.

Saad259 avatar Apr 17 '26 14:04 Saad259

Thank you @Saad259 for submitting this issue!

⚠️ Contributors, this issue will be ready to work on once:

  • [x] Triage — maintainers will add Priority: * and Lead: @* to replace Needs: Triage and Needs: Lead
  • [ ] Needs: Breakdown — issue lacks concrete implementation steps; not yet actionable

Context

This is a regression from PR #12169 (merged March 2026), which migrated all pagination to the ol-pagination web component.

Root cause: history.html:78-79 reads page_num from the URL's page parameter (0-indexed, default "0") and passes page_num + 1 to OlPaginationArrows. The component's _getPageUrl (OlPagination.js:184-196) generates 1-indexed URLs where page 1 = no ?page param and page 2 = ?page=2. On initial load (no ?page), page_num=0 so the component receives current-page=1 and generates ?page=2 for "next". When that URL loads, the server (recentchanges.py:203-204) uses offset = 20 * page (0-indexed), interpreting ?page=2 as offset=40 (third batch of data). history.html then sets page_num=2, passes current-page=3 to the component, and the prev-page URL resolves to ?page=2 — the current URL — causing the loop.

The correct pattern is already used in admin/people/edits.html: 1-indexed page (default "1"), offset = (page - 1) * limit, and page passed directly to OlPaginationArrows.


Issue Assessment

Action items

  • [ ] Fill in the browser, OS, and logged-in fields in the Context section
  • [ ] Fill in the requirements checklist and related files in the Breakdown section

Suggested breakdown

The fix requires aligning history.html and recentchanges_view to the 1-indexed page convention used elsewhere. All four changes can go in a single PR and the combined task is a candidate for Good First Issue once triaged.

  • [ ] recentchanges.py:203: Change web.input(page=0) → web.input(page=1)
  • [ ] recentchanges.py:204: Change offset = 20 * safeint(i.page) → offset = 20 * (safeint(i.page) - 1)
  • [ ] history.html:78: Change query_param("page", "0") → query_param("page", "1")
  • [ ] history.html:79: Change page_num + 1 → page_num

cc @lokesh (pagination component author)


Full triage checklist (maintainers / Pam)
  • [ ] Triage — correct labels applied or removed: Needs: Breakdown, Needs: Investigation, Needs: Design, Needs: Staff Decision, Needs: Staff / Admin, Good First Issue, Blocked, Blocker
  • [x] Problem / opportunity — problem is clear, audience identified, actionable
  • [x] Scope — issue is well-scoped; single pagination regression
  • [ ] Justification — no note on how broadly this affects all /{key}?m=history pages across the site
  • [ ] Success & testing criteria — no explicit test criteria stated
  • [ ] Proposal & breakdown — requirements checklist and related files left as template placeholders
  • [x] If bug: environment & repro steps — environment noted as prod; step-by-step repro and actual vs. expected present
  • [x] Risks, concerns, open questions — no significant risks; straightforward regression fix
  • [x] Pam context — regression traced to PR #12169; root cause confirmed in recentchanges.py and history.html
  • [ ] References — no screenshots (not blocking for a URL-based bug)

[!NOTE] This comment was automatically generated by Pam, Open Library's Project AI Manager, on behalf of @mekarpeles. Pam is designed to provide status visibility, perform basic project management functions and relevant codebase research, and provide actionable feedback so contributors aren't left waiting.

mekarpeles avatar Apr 17 '26 14:04 mekarpeles

Bumping in priority after hearing feedback from @seabelis that this is blocking librarian work.

cdrini avatar Apr 21 '26 16:04 cdrini

Ah actually apologies these are subtly different.

cdrini avatar Apr 21 '26 16:04 cdrini