algolia / algolia/docsearch

"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
Dominant language
TypeScript
Stars
4.4k
Forks
439
Avg merge
14h 32m
Merged PRs (30d)
19

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`):

```ts
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):

```ts
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 `lvl0`s).
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`)

Contributor guide

Open the contributing guide

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.