Skip to content

fix(completion): prevent error when getting activeItem with an empty collection#623

Merged
shortcuts merged 2 commits intonextfrom
fix/completion
Jul 8, 2021
Merged

fix(completion): prevent error when getting activeItem with an empty collection#623
shortcuts merged 2 commits intonextfrom
fix/completion

Conversation

@shortcuts
Copy link
Copy Markdown
Member

Summary

With an empty collections, itemInputValue was undefined which was throwing an error when destructuring it.

Result

  • We now check that itemInputValue exists before returning it, otherwise, we return null.
  • The activeItemId returned was -1, we now return null if there's no items in the collections.

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented Jul 7, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9d55b06:

Sandbox Source
@algolia/autocomplete-example-github-repositories-custom-plugin Configuration
@algolia/autocomplete-example-instantsearch Configuration
@algolia/autocomplete-example-playground Configuration
@algolia/autocomplete-example-preview-panel-in-modal Configuration
@algolia/autocomplete-example-react-renderer Configuration
@algolia/autocomplete-example-starter-algolia Configuration
@algolia/autocomplete-example-starter Configuration
@algolia/autocomplete-example-voice-search Configuration
@algolia/autocomplete-example-vue Configuration

Copy link
Copy Markdown
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these ! are much more dangerous than they seem sometimes, we need some kind of way to avoid them in the code more (same for InstantSearch)

@shortcuts shortcuts merged commit 0e0ce81 into next Jul 8, 2021
@shortcuts shortcuts deleted the fix/completion branch July 8, 2021 08:14
@francoischalifour
Copy link
Copy Markdown
Contributor

@Haroenv They are, but to be clear, this wasn't the code responsible for the bug, this was only a refactor. The fix happens in getNextActiveItemId.

@Haroenv
Copy link
Copy Markdown
Contributor

Haroenv commented Jul 9, 2021

Thanks for the clarification!

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.

3 participants