8 – How do I force the pager to update?

I have a custom form built with the Form API. The general flow is:

  1. Build and display form
  2. Get user input
  3. Rebuild and form
    • query based on user input with added

      $query = $query
        ->extend('Drupal\Core\Database\Query\PagerSelectExtender')
        ->limit($values('items'));
      

This all works well for the first submission and for paging between submissions, but when a user enters a different value for the query, while the search results change, the pager does not update (it displays the same number of result pages as with the old query and stays on the same page of the query.

So if the first query (e.g. “duck”) resulted in 14 pages of results, and I am on the 3rd page of duck results, when I change the query field to “chicken” and submit, the actual results show the right things, but the pager still shows 14 pages instead of the 35 for chicken and it keeps me on the 3rd page instead of taking me to the first page).

How do I force the pager to update?