feat: open search panel on load when ?focus=search#1550
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1550 +/- ##
==========================================
+ Coverage 63.53% 63.57% +0.04%
==========================================
Files 67 67
Lines 6197 6202 +5
Branches 1376 1378 +2
==========================================
+ Hits 3937 3943 +6
+ Misses 2221 2220 -1
Partials 39 39 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR makes BookReader open the “Search inside” side panel on initial load when the URL contains an empty search query parameter (?q=), without triggering a search request. This supports embed/preview flows that want the panel visible immediately for discoverability.
Changes:
- Treat
?q=as “present” (empty string) rather than “absent” when parsing query params, by checkingsearchTerm != null. - In the Search plugin
init(), open the search panel wheninitialSearchTerm === ''without runningsearch().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/BookReader.js |
Preserves empty q values from the URL so they propagate into Search plugin initialization. |
src/plugins/search/plugin.search.js |
Opens the search side panel on init when initialSearchTerm is the empty string, without issuing a search request. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7cfa4b5 to
f5be0b0
Compare
cdrini
left a comment
There was a problem hiding this comment.
Lgtm! Updated it to use focus=search instead of the q parameter. A few future opportunities:
- This should likely be a hash-only parameter ; eg
/page/12#?focus=search. More accurate for what hashes are used for - This currently is immediately removed on load, but should stick around until the next change
When ?q=<term> is in the URL, BookReader already searches on load.
When ?q= is present but empty, it now opens the search panel without
running a search — making search-inside discoverable by default.
Two changes:
- BookReader.js: use `!= null` instead of truthiness check so that an
empty string from URLSearchParams.get('q') passes through to
initialSearchTerm (previously empty ?q= was silently ignored)
- plugin.search.js: add else-if branch for initialSearchTerm === '' that
calls toggleSidebar() to open the panel without triggering a search
Closes: internetarchive/openlibrary#11912
Related: #1166
Without ?q= in the URL, urlParams.get('q') returns null. The previous
ternary `searchTerm ? searchTerm : ''` converted null to '' which
caused the new `else if (initialSearchTerm === '')` branch in
plugin.search.js to fire toggleSidebar() on every page load, opening
the search panel unexpectedly and breaking the e2e tests.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
f5be0b0 to
21c0fe1
Compare
Summary
When
?q=<term>is in the URL, BookReader already searches on load and opens the search panel. This PR extends that so that?q=(empty value) opens the search panel without running a search — making search-inside discoverable by default.This is the BookReader-side prerequisite for internetarchive/openlibrary#11912, which will pass
&q=in the Preview embed URL so patrons see the search panel open immediately when they click "Preview" on a book.Changes
src/BookReader.js— 1 lineURLSearchParams.get('q')returns''(empty string) when?q=is present but empty, andnullwhen the param is absent entirely. The existingif (searchTerm)check treated empty string as falsy and ignored it. Changed toif (searchTerm != null)so an empty?q=passes through toinitialSearchTerm.src/plugins/search/plugin.search.js— 3 linesAdded an
else if (this.options.initialSearchTerm === '')branch ininit()that callsthis.searchView.toggleSidebar()to open the panel without triggering a search request.Behaviour matrix
qparam?q=(empty)?q=helloRelated