fix(search): use URL mode per-tab instead of shared localStorage#12028
Open
ManthanNimodiya wants to merge 2 commits intointernetarchive:masterfrom
Open
fix(search): use URL mode per-tab instead of shared localStorage#12028ManthanNimodiya wants to merge 2 commits intointernetarchive:masterfrom
ManthanNimodiya wants to merge 2 commits intointernetarchive:masterfrom
Conversation
Fixes internetarchive#11960 Signed-off-by: ManthanNimodiya <manthannimodiya989898@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a cross-tab state leak where mode (ebooks vs everything) could be overwritten via shared localStorage, causing mismatched radio state and inconsistent search URLs across tabs.
Changes:
- Stop writing
?mode=from the URL into sharedlocalStorageon page load. - Make
SearchBarandSearchPageprefer URL-provided mode per-tab until the user explicitly changes the radio button, then allowlocalStorageto take over naturally. - Extend
composeSearchUrlto accept an optionalmodeoverride so submissions/autocomplete preserve per-tab mode.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| openlibrary/plugins/openlibrary/js/ol.js | Removes eager localStorage write on load; passes parsed URL params into SearchBar/SearchPage. |
| openlibrary/plugins/openlibrary/js/SearchPage.js | Adds per-tab URL-mode override logic for mode inputs until user interaction. |
| openlibrary/plugins/openlibrary/js/SearchBar.js | Tracks _activeMode (URL-first) and uses it for submits/autocomplete; defers mode.sync init firing. |
Addresses PR review: normalizeMode() in SearchUtils guards SearchBar and SearchPage against invalid/unsanitized urlParams.mode values. Also adds JSDoc for composeSearchUrl mode param. Signed-off-by: ManthanNimodiya <manthannimodiya989898@gmail.com>
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.
Summary
Fixes #11960
The search mode (
?mode=everything/?mode=ebooks) was being written tolocalStorageon every page load inol.js:Changes
ol.js— RemovedsearchMode.write(urlParams.mode); passesurlParamsdown toSearchPageSearchBar.js— Addedthis._activeMode(URL mode takes priority, falls back to localStorage for homepage); replaced eagermode.syncwith a deferred sync that only fires on explicit user radio interaction;composeSearchUrlgets an optionalmodeparam;submitFormandrenderAutocompletionResultsusethis._activeModeSearchPage.js— AcceptsurlParams, stores_urlMode;updateModeInputsprefers_urlModeuntil user clicks a radio button, then hands back to localStorage naturallyTesting
/search?q=python&mode=everything, Tab B/search?q=python&mode=ebooksmode=everything?mode=in URL): radio reflects localStorage fallback as before