Skip to content

"Try searching for" no-results suggestions never render in v4 (searchSuggestions built as an object, consumed as an array) #2922

Description

@LukasTy

Description

The "Try searching for" suggestions on the no-results screen never render in v4 (they did in v3). state.context.searchSuggestions is written as an object but consumed as an array, so NoResultsScreen's searchSuggestions.length > 0 guard is always false and the list is silently skipped.

Producer -- DocSearchModal.tsx (4.6.3 and main):

searchSuggestions: { ...(sourcesState.context.searchSuggestions ?? []), ...Object.keys(sources) }
// object-literal spread -> { 0: "...", 1: "..." }, not an array

Consumer -- NoResultsScreen.tsx (4.6.3 and main): typed string[], uses .length and .slice. v3 stored a plain array (searchSuggestions: Object.keys(sources)), which is why it worked there.

Fix: array spread instead of object spread (keeps the accumulate-across-searches intent):

searchSuggestions: [ ...(sourcesState.context.searchSuggestions ?? []), ...Object.keys(sources) ]

Steps to reproduce

  1. Open the DocSearch modal.
  2. Type a query that returns results (this populates the suggestions with the result group lvl0s).
  3. Type a query that returns no results.
  4. The "Try searching for:" list is missing (it appears in v3).

Expected behavior

The no-results screen shows the "Try searching for:" suggestions, as it does in v3.

Environment

  • OS: any (code-path bug, not environment specific)
  • Browser: any
  • DocSearch version: 4.6.3 (same code on main)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions