Skip to content

feat: open search panel on load when ?focus=search#1550

Merged
cdrini merged 4 commits into
masterfrom
11912/open-search-panel-on-preview
Jul 2, 2026
Merged

feat: open search panel on load when ?focus=search#1550
cdrini merged 4 commits into
masterfrom
11912/open-search-panel-on-preview

Conversation

@mekarpeles

Copy link
Copy Markdown
Member

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 line
URLSearchParams.get('q') returns '' (empty string) when ?q= is present but empty, and null when the param is absent entirely. The existing if (searchTerm) check treated empty string as falsy and ignored it. Changed to if (searchTerm != null) so an empty ?q= passes through to initialSearchTerm.

src/plugins/search/plugin.search.js — 3 lines
Added an else if (this.options.initialSearchTerm === '') branch in init() that calls this.searchView.toggleSidebar() to open the panel without triggering a search request.

Behaviour matrix

URL param Before After
No q param Panel closed Panel closed (no change)
?q= (empty) Panel closed Panel opens, no search
?q=hello Panel opens, searches "hello" Panel opens, searches "hello" (no change)

Related

@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.57%. Comparing base (65d2212) to head (21c0fe1).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 checking searchTerm != null.
  • In the Search plugin init(), open the search panel when initialSearchTerm === '' without running search().

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.

Comment thread src/plugins/search/plugin.search.js
@cdrini cdrini changed the title feat: open search panel on load when ?q= is present but empty feat: open search panel on load when ?focus=search Jul 2, 2026
@cdrini cdrini force-pushed the 11912/open-search-panel-on-preview branch from 7cfa4b5 to f5be0b0 Compare July 2, 2026 16:18

@cdrini cdrini left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm! Updated it to use focus=search instead of the q parameter. A few future opportunities:

  1. This should likely be a hash-only parameter ; eg /page/12#?focus=search . More accurate for what hashes are used for
  2. This currently is immediately removed on load, but should stick around until the next change

mekarpeles and others added 4 commits July 2, 2026 16:25
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>
@cdrini cdrini force-pushed the 11912/open-search-panel-on-preview branch from f5be0b0 to 21c0fe1 Compare July 2, 2026 16:28
@cdrini cdrini merged commit aab2d6a into master Jul 2, 2026
13 checks passed
@cdrini cdrini deleted the 11912/open-search-panel-on-preview branch July 2, 2026 16:33
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.

3 participants