fix: reset in-memory facet state on navigation in the bootstrap theme#3170
Merged
Conversation
The bootstrap search theme keeps filter state client-side in two stores: state.facets (written by sidebar facet clicks) and state.fields (written by the search-options label dropdown). Sidebar facet clicks only mutate state.facets and call runSearch() directly, so the selection is never written to the URL. runFromUrl() re-derives filter state from the URL on every navigation but only reset state.fields/lang/geo/exQ, leaving state.facets and state.facetQueries untouched. As a result a previously clicked facet survived a search-options submit (which navigates with only fields.* in the URL) and was merged back into the request, applying both the old facet label and the newly selected one. Clear state.facets and state.facetQueries in runFromUrl() so the URL is the single source of truth on every navigation (search-options submit, header search, browser back/forward). Paging and facet clicks call runSearch() directly without navigating, so an active facet still persists within the same result view as before.
state.sdh is another memory-only filter that is merged into the search request but is never written to the URL, so runFromUrl() did not re-derive it. After a similarity search (clicking a result's "similar documents" link), a subsequent header search or search-options submit navigated without sdh in the URL, yet runSearch() re-attached the stale state.sdh and silently kept the old similarity constraint. Clear state.sdh in runFromUrl() alongside the facet stores so all memory-only, URL-less filter state is reset on every navigation. The similar-docs link handler calls runSearch() directly without navigating, so an active similarity search still persists within the same result view.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In the bootstrap search theme, selecting a label via the sidebar facet and then
refining the search through the search-options panel keeps the previously
selected facet applied, even though it is no longer part of the new selection.
Steps to reproduce:
both and the result count reflects both labels, even though the URL only
contains
fields.label=B.Root cause
Filter state is kept client-side in two stores:
state.facets— written only by sidebar facet clicks. Facet clicks callrunSearch()directly, so the selection is never serialized to the URL.state.fields— written by the search-options label dropdown.runFromUrl()re-derives state from the URL on every navigation, but it onlyreset
state.fields/lang/geo/exQ, leavingstate.facetsandstate.facetQueriesintact. The search-options submit navigates with onlyfields.*in the URL, so the stalestate.facetssurvived andrunSearch()merged both stores together.
Fix
Reset
state.facetsandstate.facetQueriesinrunFromUrl()so the URL isthe single source of truth on every navigation (search-options submit, header
search, browser back/forward). Paging and facet clicks call
runSearch()directly without navigating, so an active facet still persists within the same
result view as before.
Testing
Traced the control flow in
search.js(facet click handler, search-optionssubmit handler,
runFromUrl, therunSearchfield merge, and pagination).Confirmed the stale store is cleared on navigation and that paging/facet
interactions are unaffected because they do not navigate.