19

I typically set my pagination limit to 50 on the homepage. While experiencing, researching, and finding this post on the limit resetting when changing pages (which happens intermittently for me at 50), I noticed another odd and related behavior:

When the limit is set to 15 or 30 and already on the last page, switching to a higher limit has the effect of returning no search results instead of reloading the last N results given the new pagination limit.

That's a miss

Sorry, that filter combination has no results. Please try different criteria.

Seems like the current page number is being applied before the new limit, so the change to a higher limit is always beyond the boundaries of the result set.

To reproduce:

  1. Navigate to the homepage
  2. Set "per page" to 15 or 30
  3. Navigate to the last page (7 if set to 15)
  4. Switch the "per page" to 50.
  5. No results returned "That's a miss" message

Expected behavior:

Something gets returned when changing the limit from the last page. My expectation would be the last full page of results for the new limit if available, or even the last page of results at the old limit if requerying is costly or impractical.

2
  • +1. More specifically, I'd expect the new view after the page size change to show the same first item as the old view before the change, or as close to that as rounding allows. Commented Jan 4, 2016 at 10:52
  • I would expect, on going to a page later than what exists, would be that it just redirects to the actual last page - whether or not the limit is different than a previous request disregarded.
    – Vivian
    Commented Aug 31, 2016 at 20:47

1 Answer 1

2

I agree that this is a UI bug: a properly implemented pager should never send the user to a page that it knows is outside the valid range of page numbers.

The "old navigation" works somewhat better in this regard: it simply always sends the user back to the first page when the page size is changed. Still, a more reasonable behavior IMO would be for the pager to actually maintain the user's position in the list, at least as accurately as it can.

For an example of what I'd consider "a properly implemented pager", see e.g. Wikipedia's edit history. Instead of a page number, the MediaWiki pager keeps track of the sort key (in this case, the timestamp) of the first item on the page. This allows keeping the first item fixed even if the page size is changed, and also means that adding new items to the front of the list while someone is browsing it won't mess up the pagination. (Not entirely coincidentally, it also makes the back-end SQL queries more efficient than an offset / page number based pagination system would be.)

While the SE pagination system, being based on page numbers, cannot be made as robust as Wikipedia's, it would be desirable to at least try to approximately maintain the user's position on the list. For example, if the user is viewing page 4 at 30 items per page, and decides to switch to just 15 items per page, then they should end up at page 7 or 8 (and thus see the first or last 15 of the 30 items they were previously viewing).


I've included a client-side fix that implements this into my Stack Overflow Unofficial Patch (SOUP) user script. Actually, it's already been there for a while (even in the stable branch since v1.44, released in February 2016), but it seems I never remembered to actually post about it here. Oops.

The actual JS code is a bit ugly, because of various corner cases. Basically, it looks for elements with the page-sizer class name (which is used both in the old and the new pagination system; fortunately, it appears that they're quite similar on the HTML level), finds the page size change buttons within them and tweaks the URLs of those button links to include a page number that points (approximately) to the same position in the list. A fairly large part of the code is devoted to determining the current page number, since that turns out to be one detail that is not consistently exposed in an easily parseable way by the various pager implementations used around SE. I would expect a proper implementation of this feature in the SE codebase to look a lot cleaner and less klugey than the ugly JS hacks I had to use in SOUP.

In any case, the whole kluge seems to work: I've been using it myself for over a year with no problems, and nobody else has reported any, either. The next release of SOUP will contain a slight tweak to the page number rounding algorithm (basically, round the page number down when increasing the page size, round up if decreasing it), but that shouldn't have much noticeable effect. Mostly it should just (somewhat) improve the overlap between the previous and the resized page views in cases where perfect overlap is not possible due to rounding.

Not the answer you're looking for? Browse other questions tagged .