fix(headless): acknowledge server-side query correction when automaticallyCorrectQuery is disabled#7828
fix(headless): acknowledge server-side query correction when automaticallyCorrectQuery is disabled#7828alexprudhomme wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: aac4286 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
…callyCorrectQuery is disabled
@coveo/atomic
@coveo/atomic-hosted-page
@coveo/atomic-legacy
@coveo/atomic-react
@coveo/auth
@coveo/bueno
@coveo/create-atomic
@coveo/create-atomic-component
@coveo/create-atomic-component-project
@coveo/create-atomic-result-component
@coveo/create-atomic-rollup-plugin
@coveo/headless
@coveo/headless-react
@coveo/shopify
commit: |
|
Important Testing in progress…🟢 UI Tests: 433 tests unchanged |
|
Tip All tests passed and all changes approved!🟢 UI Tests: 433 tests unchanged |
There was a problem hiding this comment.
Pull request overview
This PR addresses a headless edge case where the server applies a query correction (e.g., via pipeline override) even though the client has automaticallyCorrectQuery: false. The change makes headless “acknowledge” the server-corrected query so subsequent requests (like facet “Show More”) use the corrected query rather than the original.
Changes:
- Update search thunk processors to recognize
queryCorrection.correctedQueryeven whenautomaticallyCorrectQueryis disabled. - Add unit tests covering the new behavior for the main search thunk processor.
- Add a changeset for
@coveo/headlessdescribing the patch.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/headless/src/features/search/search-actions-thunk-processor.ts | Adds an early-return path to update state.query.q when the server already applied a correction despite automaticallyCorrectQuery: false. |
| packages/headless/src/features/search/search-actions-thunk-processor.test.ts | Adds coverage for server-applied query correction when automaticallyCorrectQuery is false. |
| packages/headless/src/features/insight-search/insight-search-actions-thunk-processor.ts | Mirrors the same correction-acknowledgement behavior for insight search. |
| .changeset/fix-server-query-correction.md | Publishes the change as a patch for @coveo/headless. |
| if (!automaticallyCorrectQuery) { | ||
| if ( | ||
| !isNullOrUndefined(queryCorrection) && | ||
| !isNullOrUndefined(queryCorrection.correctedQuery) | ||
| ) { | ||
| return this.processModernDidYouMeanAutoCorrection(fetched); | ||
| } | ||
| return null; | ||
| } |
| if (!automaticallyCorrectQuery) { | ||
| if ( | ||
| !isNullOrUndefined(queryCorrection) && | ||
| !isNullOrUndefined(queryCorrection.correctedQuery) | ||
| ) { | ||
| return this.processNextDidYouMeanAutoCorrection(fetched); | ||
| } | ||
| return null; | ||
| } |
| import type {Relay} from '@coveo/relay'; | ||
| import type {Logger} from 'pino'; | ||
| import {type Mock} from 'vitest'; | ||
| import type {SearchAPIClient} from '../../api/search/search-api-client.js'; |
| if (!automaticallyCorrectQuery) { | ||
| if ( | ||
| !isNullOrUndefined(queryCorrection) && | ||
| !isNullOrUndefined(queryCorrection.correctedQuery) | ||
| ) { | ||
| return this.processNextDidYouMeanAutoCorrection(fetched); |
KIT-5824
Problem
When a search pipeline overrides
automaticallyCorrecttowhenNoResultsbut the headless client hasautomaticallyCorrectQuery: false, clicking "Show More" on a facet causes facet values to disappear.Root cause: The server applies the correction and returns results for the corrected query. Headless displays those results and facets. However, because
automaticallyCorrectQueryisfalse, headless never updatesstate.query.qto the corrected query. When "Show More" triggers afetchFacetValuesrequest, it uses the original uncorrected query (e.g.,"hone") which returns 0 results and empty facets.Discussion: is this a product bug or client misconfiguration?
Argument for client misconfiguration:
automaticallyCorrecttowhenNoResults, contradicting their frontend setting ofautomaticallyCorrectQuery: false. These should agree.Argument for product bug (the approach taken here):
automaticallyCorrectQuery: falseis documented as controlling whether headless retries a failed query — not whether it acknowledges a correction the server already applied.Solution
In
processQueryCorrectionsOrContinue, whenautomaticallyCorrectQueryisfalsebut the server returned a non-emptyqueryCorrection.correctedQuery, headless now callsprocessModernDidYouMeanAutoCorrectionto updatestate.query.qto the corrected query. This ensures subsequent requests use the correct query.