SCIX-867 feat: add SearchModifierBar with ADS Compatibility mode#866
SCIX-867 feat: add SearchModifierBar with ADS Compatibility mode#866thostetler wants to merge 2 commits into
Conversation
2c52eba to
5692120
Compare
Codecov Report❌ Patch coverage is 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
🚀 New features to boost your workflow:
|
dd3966a to
d8f7067
Compare
There was a problem hiding this comment.
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
SearchModemodel (ADS_COMPATvsALL_RELEVANT) with helpers to apply/strip ADS defaults and to build outgoing search params. - Introduces
scix_prefscookie read/write utilities and SSR seeding ofmode/searchModefrom that cookie. - Adds the
SearchModifierBardropdown component and wires parts of the app to usebuildSearchOutgoingwhen 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=1and 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.getInitialPropsis introduced solely to pass cookies into Chakra’scookieStorageManagerSSR, 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.
applySearchModeDefaultsstrips ADS database filters when leaving ADS mode but does not revert the ADS-impliedsort=date desc, so “All relevant content” can remain date-sorted.
low
readPrefsCookie’s regex requires"; "(semicolon + space) which is not guaranteed in realCookieheaders, 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
AbstractSearchFormcurrently renders onlySearchBarand doesn’t include the modifier UI. If abstract pages should allow changing search mode, addSearchModifierBarhere (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>
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
2801e69 to
3056275
Compare
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.