Skip to content

SCIX-867 feat: add SearchModifierBar with ADS Compatibility mode#866

Open
thostetler wants to merge 2 commits into
adsabs:masterfrom
thostetler:worktree-search-mode-bar
Open

SCIX-867 feat: add SearchModifierBar with ADS Compatibility mode#866
thostetler wants to merge 2 commits into
adsabs:masterfrom
thostetler:worktree-search-mode-bar

Conversation

@thostetler
Copy link
Copy Markdown
Member

@thostetler thostetler commented May 14, 2026

The app had no way for users to scope searches to ADS-style astronomy and physics content with date-sorted results. ADS users arriving via referrer also had no awareness that their experience was configured differently.

  • Add SearchModifierBar dropdown (All relevant content / ADS Compatibility mode) on the landing page when in Astrophysics mode
  • Persist mode in Zustand store and scix_prefs cookie, seeded by middleware on ADS referrer detection and discipline route redirects
  • Apply fq_database filter and date sort when ADS Compatibility mode is active; strip them on mode switch
  • Show toast notification when arriving from ADS referrer (fromADS param)
  • Submit-time mode application on landing and abstract form pages
  • Strip ads_compat param from Solr query key to prevent double-fetch on AppMode sync
  • SearchModifierBar is shown only on the landing page (ASTROPHYSICS mode) — search results page intentionally omitted (tentative product decision, may be revisited)

@thostetler thostetler force-pushed the worktree-search-mode-bar branch from 2c52eba to 5692120 Compare May 14, 2026 17:24
@thostetler thostetler changed the title feat: add SearchModifierBar with ADS Compatibility mode SCIX-867 feat: add SearchModifierBar with ADS Compatibility mode May 14, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

❌ Patch coverage is 87.37864% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.9%. Comparing base (4141a42) to head (3056275).

Files with missing lines Patch % Lines
src/store/store.ts 21.5% 22 Missing ⚠️
src/utils/common/prefs-cookie.ts 86.9% 4 Missing and 1 partial ⚠️
src/middleware.ts 93.2% 3 Missing ⚠️
src/utils/common/searchMode.ts 95.2% 2 Missing and 1 partial ⚠️
src/components/SearchQueryLink/SearchQueryLink.tsx 85.8% 2 Missing ⚠️
src/ssr-utils.ts 91.0% 2 Missing ⚠️
...components/SearchModifierBar/SearchModifierBar.tsx 98.7% 0 Missing and 1 partial ⚠️
src/config.ts 0.0% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master    #866     +/-   ##
========================================
+ Coverage    62.7%   62.9%   +0.3%     
========================================
  Files         323     327      +4     
  Lines       38053   38306    +253     
  Branches     1721    1768     +47     
========================================
+ Hits        23824   24091    +267     
+ Misses      14189   14171     -18     
- Partials       40      44      +4     
Files with missing lines Coverage Δ
src/lib/useSearchMode.ts 100.0% <100.0%> (ø)
src/store/slices/appMode.ts 100.0% <100.0%> (ø)
src/types.ts 100.0% <ø> (ø)
...components/SearchModifierBar/SearchModifierBar.tsx 98.7% <98.7%> (ø)
src/config.ts 99.1% <0.0%> (-0.9%) ⬇️
src/components/SearchQueryLink/SearchQueryLink.tsx 76.1% <85.8%> (+1.8%) ⬆️
src/ssr-utils.ts 74.8% <91.0%> (+4.8%) ⬆️
src/middleware.ts 94.4% <93.2%> (+2.6%) ⬆️
src/utils/common/searchMode.ts 95.2% <95.2%> (ø)
src/utils/common/prefs-cookie.ts 86.9% <86.9%> (ø)
... and 1 more

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@thostetler thostetler force-pushed the worktree-search-mode-bar branch 2 times, most recently from dd3966a to d8f7067 Compare May 19, 2026 19:37
@thostetler thostetler marked this pull request as ready for review May 19, 2026 19:41
Copilot AI review requested due to automatic review settings May 19, 2026 19:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 introduces an “ADS Compatibility mode” search option intended to scope searches to ADS-like astronomy/physics content (with date sorting) and persist that preference via Zustand + a scix_prefs cookie seeded by middleware/SSR.

Changes:

  • Adds a SearchMode model (ADS_COMPAT vs ALL_RELEVANT) with helpers to apply/strip ADS defaults and to build outgoing search params.
  • Introduces scix_prefs cookie read/write utilities and SSR seeding of mode/searchMode from that cookie.
  • Adds the SearchModifierBar dropdown component and wires parts of the app to use buildSearchOutgoing when navigating to /search.

Risk summary

High regression risk due to (1) cookie format/encoding inconsistencies, (2) incomplete/mismatched mode enabling behavior for ADS referrers, and (3) adding _app.getInitialProps (which changes Next.js rendering/optimization behavior app-wide).

Findings (priority order)

blocker

  • Cookie written by middleware is raw JSON and not safely encoded, while readers assume URL-encoded content; this can break parsing and preference seeding.
  • Legacy ADS referrer flow does not actually enable ADS Compatibility mode (only sets mode), yet the UI claims it did; behavior and messaging diverge.
  • Classic form unconditionally sets ads_compat=1 and still doesn’t apply the ADS defaults consistently, making the param misleading and behavior incorrect.
  • Search results page does not render the SearchModifierBar despite PR description (and there’s no implemented “immediate switch” behavior there).

high

  • _app.getInitialProps is introduced solely to pass cookies into Chakra’s cookieStorageManagerSSR, which opts the entire app out of automatic static optimization and can have significant performance/operational impact.

medium

  • Search mode UI injects a zero-width space into the displayed label to satisfy tests; this is brittle for UX/accessibility/i18n and should be solved in tests instead.
  • applySearchModeDefaults strips ADS database filters when leaving ADS mode but does not revert the ADS-implied sort=date desc, so “All relevant content” can remain date-sorted.

low

  • readPrefsCookie’s regex requires "; " (semicolon + space) which is not guaranteed in real Cookie headers, so valid cookies may be missed.

Reviewed changes

Copilot reviewed 25 out of 26 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
tsconfig.json Switches TS module resolution to bundler.
src/utils/common/searchMode.ts Adds SearchMode enum/options + helpers to apply/strip ADS defaults and build outgoing params.
src/utils/common/prefs-cookie.ts Adds scix_prefs cookie read/write helpers.
src/utils/common/tests/searchMode.test.ts Unit tests for ADS defaulting/stripping behavior.
src/utils/common/tests/prefs-cookie.test.ts Unit tests for cookie parsing/writing behavior.
src/store/store.ts Adjusts SSR hydration behavior to avoid overriding user searchMode and to sync mode earlier.
src/store/slices/appMode.ts Adds searchMode + actions; writes prefs cookie on updates.
src/ssr-utils.ts Seeds mode/searchMode from prefs cookie with validation and precedence rules.
src/tests/ssr-utils.test.ts Updates SSR tests for cookie-based mode/searchMode seeding and precedence.
src/lib/useSearchMode.ts Adds a small Zustand-backed hook for reading/updating searchMode.
src/lib/tests/useSearchMode.test.ts Hook unit tests.
src/middleware.ts Sets scix_prefs cookie on discipline redirects and ADS referrer redirects (currently incomplete).
src/pages/index.tsx Adds landing-page SearchModifierBar + toast for ADS referrer + outgoing query building.
src/pages/search/index.tsx Syncs searchMode from URL param and strips it from query key; uses buildSearchOutgoing on submit.
src/components/SearchModifierBar/* New dropdown component + tests.
src/components/SearchQueryLink/SearchQueryLink.tsx Ensures links to /search include ADS mode defaults when active.
src/components/AbstractSearchForm/AbstractSearchForm.tsx Uses buildSearchOutgoing when submitting from abstract pages.
src/components/ClassicForm/ClassicForm.tsx Forces ads_compat=1 on submit (currently incorrect behavior).
src/pages/_app.tsx Adds cookies to pageProps via _app.getInitialProps.
src/providers.tsx / src/pages/_document.tsx Wires Chakra cookie-based color mode SSR.
src/config.ts Adds dev-only small per-page options.
src/components/SearchBar/tests/SearchBar.test.tsx Test timing adjustments to reduce runtime flakiness.
src/types.ts Removes trailing whitespace line.
Comments suppressed due to low confidence (1)

src/components/AbstractSearchForm/AbstractSearchForm.tsx:71

  • PR description says the SearchModifierBar dropdown is shown on abstract pages, but AbstractSearchForm currently renders only SearchBar and doesn’t include the modifier UI. If abstract pages should allow changing search mode, add SearchModifierBar here (and consider disabling it during submit/loading, consistent with the landing page behavior).
  return (
    <form method="get" action="/search" onSubmit={handleOnSubmit}>
      <SearchBar query={query} showBackLinkAs="results" />
    </form>

Comment thread src/middleware.ts
Comment thread src/middleware.ts Outdated
Comment thread src/pages/index.tsx
Comment thread src/pages/index.tsx
Comment thread src/components/ClassicForm/ClassicForm.tsx
Comment thread src/components/SearchModifierBar/SearchModifierBar.tsx
Comment thread src/pages/search/index.tsx
Comment thread src/pages/_app.tsx
Comment thread src/utils/common/prefs-cookie.ts
Comment thread src/utils/common/searchMode.ts
Adds a search mode selector that scopes results to astronomy and physics
content (fq_database filter + date sort) when ADS Compatibility mode is
active. Mode persists in a scix_prefs cookie seeded by middleware on
legacy ADS referrer detection.

- SearchModifierBar component (landing page only, ASTROPHYSICS mode gated)
- SearchMode enum, applySearchModeDefaults, buildSearchOutgoing helpers
- scix_prefs cookie read/write utilities (prefs-cookie.ts)
- useSearchMode hook backed by Zustand appMode slice
- Middleware seeds cookie on /astrophysics discipline routes and ADS referrer
- SSR reads cookie to hydrate mode/searchMode before first render
- ADS referrer redirects to /?fromADS=true; landing page shows info toast
- store.ts: synchronous mode sync on navigation, searchMode excluded from
  navigation merge to preserve user changes
- searchMode.test.ts: applySearchModeDefaults and buildSearchOutgoing
- prefs-cookie.test.ts: read/write round-trips including encoding
- useSearchMode.test.ts: hook returns mode and calls store setter
- SearchModifierBar.test.tsx: renders, mode switching, disabled state
- ssr-utils.test.ts: cookie-seeded mode/searchMode hydration and precedence
- middleware.routes.integration.test.ts: discipline-route cookie setting,
  ADS referrer redirect to /?fromADS=true, and loop-guard cases
- appMode.test.ts: setMode ADS_COMPAT-clear branch, setSearchMode persistence
- SearchBar.test.tsx: timer isolation fixes to prevent suite timeouts
@thostetler thostetler force-pushed the worktree-search-mode-bar branch from 2801e69 to 3056275 Compare May 21, 2026 16:56
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.

2 participants