algolia / algolia/autocomplete
LocalStorageRecentSearchesPlugin not working with other hooks than onSubmit
- Dominant language
- TypeScript
- Stars
- 5.3k
- Forks
- 341
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 5
Description
## Description
You can’t use `LocalStorageRecentSearchesPlugin` with autocomplete option `defaultActiveItemId` (e.g. `defaultActiveItemId: 0`), because `onSubmit` lifecycle hook is not fired by autocomplete in this case. `LocalStorageRecentSearchesPlugin` is based on this hook. It would be good to have the choice, which lifecycle hooks trigger the plugin. In practice also `onSelect` is needed, but it’s currently only for `querySuggestionsPlugin` implemented: https://github.com/algolia/autocomplete/blob/dc8b6f2b585d0992bcb22d2c61053388c1c90590/packages/autocomplete-plugin-recent-searches/src/createRecentSearchesPlugin.ts#L57
PS: It's unclear, whether incompatibility with `defaultActiveItemId` is intended behavior or a bug. At least it's [very confusing](https://discourse.algolia.com/t/recently-search-onsubmit/14677) and not mentioned anywhere in the [docs](https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-recent-searches/createLocalStorageRecentSearchesPlugin/).
## Expected behavior
`LocalStorageRecentSearchesPlugin` should handle `onSubmit` and `onSelect` hook. At least, it should be mentioned in the docs, if it's not possible.
## Environment
- Autocomplete version: 1.7.1
Contributor guide
Research direction
Start in packages/autocomplete-plugin-recent-searches/src/createRecentSearchesPlugin.ts, especially the linked lifecycle-hook logic, and compare how onSubmit and onSelect are handled. Review the linked recent-searches documentation and verify that the plugin behavior or its limitations clearly cover defaultActiveItemId; done means the requested hook behavior is supported or explicitly documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend, search
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100