Search: Fix modal rejecting valid responses with content type "docs"#3456
Conversation
The navigation-search contract changed the result item type value from "doc" to "docs", but the frontend Zod schemas still enumerated ['doc', 'api'], causing SearchResponse.parse() to throw on every result item and surface "Error loading search results" even for healthy 200 responses. Also adds a console.error + logError branch for non-ApiError query failures so ZodError/parse mismatches are no longer completely silent. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR aligns search result type contracts and breadcrumb rendering across Modal and Navigation search components. The 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/Elastic.Documentation.Site/Assets/web-components/ModalSearch/useModalSearchQuery.ts (1)
38-45:⚠️ Potential issue | 🟠 Major | ⚡ Quick winKeep the result type parser rollout-compatible.
Accepting only
'docs'means any still-legacy'doc'payload from a staggered deploy, stale cache, or partial reindex will keep failing with the same parse error. Parse both values here and normalize later so search stays up during the transition.Suggested change
const SearchResultItem = z.object({ - type: z.enum(['docs']), + type: z.enum(['doc', 'docs']), url: z.string(), title: z.string(), description: z.string(), score: z.number(), parents: z.array(SearchResultItemParent), })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/Elastic.Documentation.Site/Assets/web-components/ModalSearch/useModalSearchQuery.ts` around lines 38 - 45, The SearchResultItem Zod schema currently only accepts type 'docs', which will reject legacy 'doc' payloads during a rollout; update the parser for SearchResultItem.type to accept both 'docs' and 'doc' (e.g., using an enum/union for ['docs','doc']) and then normalize the value downstream where SearchResultItem is consumed so callers always see a single canonical value (e.g., map 'doc' -> 'docs') to maintain compatibility during staggered deploys.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In
`@src/Elastic.Documentation.Site/Assets/web-components/ModalSearch/useModalSearchQuery.ts`:
- Around line 38-45: The SearchResultItem Zod schema currently only accepts type
'docs', which will reject legacy 'doc' payloads during a rollout; update the
parser for SearchResultItem.type to accept both 'docs' and 'doc' (e.g., using an
enum/union for ['docs','doc']) and then normalize the value downstream where
SearchResultItem is consumed so callers always see a single canonical value
(e.g., map 'doc' -> 'docs') to maintain compatibility during staggered deploys.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: d508d3f5-2341-4bf8-990d-95a6709641e9
📒 Files selected for processing (5)
src/Elastic.Documentation.Site/Assets/web-components/ModalSearch/ModalSearchResultsList.tsxsrc/Elastic.Documentation.Site/Assets/web-components/ModalSearch/useModalSearchQuery.tssrc/Elastic.Documentation.Site/Assets/web-components/NavigationSearch/NavigationSearchTelemetry.test.tsxsrc/Elastic.Documentation.Site/Assets/web-components/NavigationSearch/SearchResultsList.tsxsrc/Elastic.Documentation.Site/Assets/web-components/NavigationSearch/useNavigationSearchQuery.ts
|
@copilot this fix is wrong. The schema changed. It's now content_type with the value "docs". Just change the key and fix the value in the zod schema |
Fixed in the latest commit — renamed the key from |
|
Merging because this is broken on live elastic codex. |
Why
The upstream search contract (
Elastic.Internal.Search.Contract) changed the field name fromtypetocontent_typeand updated the value from"doc"to"docs"on indexed documents. The frontend Zod schemas still declaredtype: z.enum(['doc', 'api']), soSearchResponse.parse()threw aZodErroron every result item — rejecting the entire valid 200 response and showing "Error loading search results" in the codex search modal.What
type→content_typeand updatedz.enum(['doc', 'api'])toz.enum(['docs'])in bothuseModalSearchQueryanduseNavigationSearchQuery.result.type === 'api'branch from both result list components; codex is docs-only sotypePrefixis always'Docs'.else if (query.error)branch to the error-logging effect in both hooks, soZodError/parse failures are no longer silent — they now emitlogErrorto OTLP andconsole.errorto devtools.content_type: 'docs'.