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

Open Beginner friendly
#2,922 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
react, typescript
Domain
frontend, search

Research direction

Read DocSearchModal.tsx to inspect how searchSuggestions is built, then compare it with the string[] usage in NoResultsScreen.tsx. Change the producer so suggestions remain an array and verify the no-results flow after first running a query with results, followed by a query with none; the “Try searching for” list should render.

Written by the indexing model from the issue text.

Description

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)
Dominant language
TypeScript
Stars
4.4k
Forks
438
Avg merge
17h 2m
Merged PRs (30d)
15

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from algolia/docsearch

All issues in algolia/docsearch

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.