Skip to content

[docsearch-react] Bug Fix: Preserve searchSuggestions array shape for no-results suggestions#2928

Open
Fenz-art wants to merge 3 commits into
algolia:mainfrom
Fenz-art:fix/docsearch-react-search-suggestions
Open

[docsearch-react] Bug Fix: Preserve searchSuggestions array shape for no-results suggestions#2928
Fenz-art wants to merge 3 commits into
algolia:mainfrom
Fenz-art:fix/docsearch-react-search-suggestions

Conversation

@Fenz-art

@Fenz-art Fenz-art commented Jul 20, 2026

Copy link
Copy Markdown

Description

Fixes an issue where "Try searching for" suggestions were not displayed on the no-results screen.

The issue was caused by searchSuggestions being converted from an array into an object-like structure when updating the state in DocSearchModal.

NoResultsScreen expects searchSuggestions to remain an array and uses array operations such as .length and .slice(). Because the value was stored with the wrong shape, the no-results suggestions were silently skipped.

Closes #2922

Changes

  • Updated DocSearchModal to preserve searchSuggestions as an array by using array spread instead of object spread.
  • Added a regression test covering the previous successful search → no-results flow.

Root Cause

Before:

searchSuggestions: {
  ...(previousSuggestions ?? []),
  ...Object.keys(sources)
}


This converted the array into an object:

{
  0: "Suggestion A",
  1: "Suggestion B"
}

After:

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

This keeps the expected array structure:

[
  "Suggestion A",
  "Suggestion B"
]
Test Plan
Before
Open the DocSearch modal.
Perform a search that returns results to populate suggestions.
Search for a query that returns no results.
Verify that the "Try searching for" suggestions are missing.
After

Added a regression test verifying that previous search suggestions are displayed on the no-results screen.

Command:

yarn vitest run packages/docsearch-react/src/__tests__/api.test.tsx -t "renders no-results suggestions from previous successful searches"

Result:

 1 passed
 14 skipped

The targeted regression test passes with this change.

Note: The full API test file still reports an unrelated Ask AI failure in this environment.


---

## Commit message

```bash
fix(docsearch-react): preserve searchSuggestions array shape

@netlify

netlify Bot commented Jul 20, 2026

Copy link
Copy Markdown

👷 Deploy request for docsearch pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 119c58a

@netlify

netlify Bot commented Jul 20, 2026

Copy link
Copy Markdown

Deploy Preview for docsearch-demo ready!

Name Link
🔨 Latest commit 119c58a
🔍 Latest deploy log https://app.netlify.com/projects/docsearch-demo/deploys/6a5dffb02d908000088bcc8e
😎 Deploy Preview https://deploy-preview-2928--docsearch-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant