algolia / instantsearch

⚡️ Libraries for building performant and instant search and recommend experiences with Algolia. Compatible with JavaScript, TypeScript, React and Vue.
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/
MIT License
3.67k stars 514 forks source link

Map + InfiniteHits has weird behavior: loading next items removes previous items from map #5437

Closed joepio closed 1 year ago

joepio commented 1 year ago

🐛 Current behavior

I'm using react-instantsearch-hooks-web to render both a map and InifiteHits. This combination leads to weird behavior: when clicking the Show more results button, the first page results disappear from the map.

I'm not entirely sure if this could be classified as a bug, but the behavior is definitely confusing to users.

🔍 Steps to reproduce

  1. Create a useGeoSearch connector for a map (docs)
  2. Use InfiniteHits component.
  3. Do a query, press show more results
  4. See how the first x results disappear from the map

Live reproduction

no

💭 Expected behavior

the items from useGeoSearch (= useConnector) should return all items from currently shown list in InifiniteHits

Package version

"react-instantsearch-hooks-web": "6.38.3"

Operating system

macOS m1

Browser

Chrmoe

Code of Conduct

Haroenv commented 1 year ago

The reason this happens is because the full list of items of infiniteHits is stored inside infiniteHits itself, not somewhere global, meaning that geo search doesn't have access to that.

A workaround could be to use useGeoSearch for the boundaries etc, but still use useInfiniteHits for displaying the hits on the map, as you can still access _geoLoc.

Would that work for your use case?

joepio commented 1 year ago

That's a great idea! Works perfectly :)