Skip to content

Keep the online activities filters when changing page - #3668

Merged
bernardhanna merged 1 commit into
masterfrom
fix/online-activities-filter-pagination
Sep 17, 2026
Merged

bernardhanna merged 1 commit into
masterfrom
fix/online-activities-filter-pagination

Conversation

@bernardhanna

Copy link
Copy Markdown
Collaborator

The report

From the ambassadors:

If you go one page further in the pagination, the filter resets. E.g. you select "english" and get 9 pages, go to page 2 and you have the results for "any language" again.

Reproduced and fixed.

Why it happened

The pagination partial renders plain links:

href="{{ $paginator->nextPageUrl() }}"

So moving to page two is a full browser navigation, not a Livewire round trip. Two things then conspired:

  1. Neither $selectedLanguage nor $selectedDate was in the query string, so the new request had no idea a filter was in force.
  2. mount() ran again on that fresh request and explicitly reset both properties.

page survived because Livewire's WithPagination already tracks it in the URL. The filters did not.

The change

  • #[Url(as: 'language')] and #[Url(as: 'month')] put both filters in the query string, so they survive a page load and the URL becomes shareable.
  • The two resets are dropped from mount(). They only restated the property defaults, and they overwrote whatever arrived from the URL.
  • The paginator gets ->appends($this->activeFilters()) so the generated page links carry the filters. Livewire::originalPath() returns a bare path, so without this the links would drop them again.
  • Each <option> now renders selected when it matches. Otherwise page two would show a correctly filtered list under a dropdown reading "All Languages", which looks like the same bug.

?language= and ?month= do not collide with anything else on the route; the locale middleware reads ?lang=.

Tests

tests/Feature/OnlineActivitiesFilterPaginationTest.php, six tests. All six fail on master and pass with this change:

  • the_language_filter_survives_a_jump_to_the_second_page — the reported case, 25 English activities plus one German, requesting page two with the language filter.
  • choosing_a_language_then_paginating_keeps_the_language — the same in the order a user hits it: set the dropdown through Livewire, then follow the rendered page-two link as a browser would.
  • the_month_filter_survives_a_jump_to_the_second_page
  • pagination_links_carry_the_active_filters
  • the_dropdowns_show_the_filter_that_is_in_force
  • the_filters_are_read_from_the_query_string

The 16 existing tests in OnlineEventsWorkflowTest still pass.

Made with Cursor

The pagination links are ordinary hrefs, so clicking page two is a full
browser navigation. Neither filter was in the URL and mount() reset both
on every request, so the new page came back unfiltered.

Carry the language and month in the query string, append them to the
page links, and mark the matching option selected so the dropdowns agree
with the list.

Co-authored-by: Cursor <cursoragent@cursor.com>
@bernardhanna
bernardhanna merged commit ef74a27 into master Sep 17, 2026
1 check failed
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