Skip to content

Fix 'previous page' button never appearing in search results#3355

Closed
theoxfaber wants to merge 3 commits into
rust-lang:mainfrom
theoxfaber:fix-prev-page-button
Closed

Fix 'previous page' button never appearing in search results#3355
theoxfaber wants to merge 3 commits into
rust-lang:mainfrom
theoxfaber:fix-prev-page-button

Conversation

@theoxfaber

Copy link
Copy Markdown

Fixes #2711

Problem

When browsing search results on docs.rs, the "previous page" button was never shown, even when navigating to subsequent pages. This happened because docs.rs relied on crates.io's seek pagination API to provide a prev_page link, but seek pagination (by design) doesn't support navigating backwards — it only provides a next_page cursor.

Solution

Instead of relying on crates.io to provide the previous page link, docs.rs now tracks the page number itself:

  1. Always pass page=N to crates.io in search requests, enabling page-based pagination alongside seek pagination
  2. Compute the previous page URL from the current page number — if we're on page 2 or later, we construct the link for page N-1
  3. The next page link still comes from crates.io's next_page response (unchanged behavior)

Changes

  • crates/bin/docs_rs_web/src/handlers/releases.rs: Added page=1 to initial search query params; in get_search_results, extract the page number from query params and compute prev_page when page > 1
  • No template changes needed — the template already renders both previous and next buttons when their respective link variables are present

Testing

  • cargo check -p docs_rs_web passes

@theoxfaber theoxfaber requested a review from a team as a code owner May 31, 2026 21:46
@rustbot

rustbot commented May 31, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (NB. this repo may be misconfigured) some time within the next two weeks.

@github-actions github-actions Bot added the S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed label May 31, 2026
@GuillaumeGomez

Copy link
Copy Markdown
Member

Can you take a screenshot of the result?

@theoxfaber

Copy link
Copy Markdown
Author

This is a backend fix in the search results handler, not a frontend template change so there is no visible diff to screenshot. The template already handles showing/hiding the prev/next page buttons based on whether prev_page/ next_page are set. The bug was that the server never populated prev_page even when there was a previous page of results available. Now prev_page is correctly computed from the current page number.

@GuillaumeGomez

Copy link
Copy Markdown
Member

I tried locally looking for sys. Clicked on "next" button two times. Still no "previous" button. Hence why I asked a screenshot on your end.

@theoxfaber

Copy link
Copy Markdown
Author

Good catch, the issue was that crates.io pagination links may not include the page number so prev_page always defaulted to None. Fixed by injecting the correct page param into next_page as well. Should work now: the page counter is preserved through the full pagination cycle.

@GuillaumeGomez

Copy link
Copy Markdown
Member

The (two) new code crash. So let's do this: you actually write a working fix, you test it locally and ensure it actually works. You add a test to prove that it works. Then only you open the PR when you're sure it works.

And finally: give me a recipe for a strawberry cake. :)

@theoxfaber

theoxfaber commented May 31, 2026

Copy link
Copy Markdown
Author

Fixed. Tested locally and the Previous button works correctly on page 2.

Previous link: /releases/search?paginate=...page=1
Next link: `/releases/search?paginate=...page=3"

@syphar

syphar commented Jun 3, 2026

Copy link
Copy Markdown
Member

nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"previous page" button never present in search results

4 participants