question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`connectStateResults` does not provide up-to-date values in server side rendering

See original GitHub issue

Describe the bug 🐛

In some cases, connectStateResults does not provide the correct up-to-date values.

To Reproduce 🔍

Unfortunately, it’s not possible for me to give a working example here. But the flow is as follow:

  • The user lands on the search page.
  • They see a list of results L1.
  • They update and submit a new query.
  • They do see the list of results L2. In the network tab, the request fired to Algolia API works successfully. But because connectStateResults is not correctly updated, searching remains true - and, in our implementation, the spinner keeps spinning, on top of several other unwanted side-effects. The provided searchResults is also not correctly updated.

Expected behavior 💭

connectStateResults should always provide the latest values. There should not be a difference between the provided searchResults.hits and the hits provided by connectHits, for instance. Nor there should be a difference between the provided searchState.query and searchResults.query.

Environment:

  • OS: MacOS
  • Browser: Chrome
  • Version: 88

Additional context

We’re using the latest 6.10.0 version of both react-instantsearch-core and react-instantsearch-dom.

We’re using the following connectors:

  • connectSearchBox. When submitting the search query, I’m calling the provided refine method with the query.
  • connectHits. The hits are always up to date, there is absolutely no issue there.
  • connectStateResults. Somehow, when using the React inspector, we can see that:
    • searchState is up to date. It contains the latest query.
    • searching sometimes remains true until a new search query is fired.
    • searchResults sometimes contain the previous results until a new search query is fired. This also means that searchResults.query contains the previous query, as opposed to searchState.query, where the up-to-date query can be found.

We’re also using server-side rendering, click analytics, and conversion analytics. Here is how the configure component looks like:

        <Configure
            optionalFilters={optionalFilters}
            filters={filters}
            queryLanguages={queryLanguages}
            hitsPerPage={hitsPerPage}
            removeWordsIfNoResults="lastWords"
            clickAnalytics
            analytics
        />

The search is performed on a single index, correctly passed to InstantSearch.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Haroenvcommented, Mar 10, 2021

I simplified the example and found the following things that matter: https://codesandbox.io/s/stoic-hermann-98bx9?file=/pages/index.js

  1. stateResults behind hits has the issue, before it doesn’t
  2. a hitComponent must be given in default Hits component

For your specific use case, can you try putting StateResults in front of Hits?

1reaction
Haroenvcommented, Mar 10, 2021

Found some more things: https://codesandbox.io/s/billowing-browser-gd3kn?file=/src/App.js

  • resultsState is required for this to misbehave
  • it doesn’t have to be server-side rendered
  • only the first StateResults has outdated results
  • if key is index (not objectID), the issue doesn’t happen
Read more comments on GitHub >

github_iconTop Results From Across the Web

`connectStateResults` does not provide up-to-date values in ...
Describe the bug. In some cases, connectStateResults does not provide the correct up-to-date values. To Reproduce.
Read more >
Improve performance for React InstantSearch - Algolia
Learn how to optimize your React InstantSearch app.
Read more >
react-instantsearch-core | Yarn - Package Manager
This is the React version of Algolia's instantsearch library. Go to the React InstantSearch website or the React InstantSearch GitHub repository for more ......
Read more >
Source - GitHub
... (2021-08-02) ### Bug Fixes * **server side rendering:** return a value from ... (2021-02-23) ### Bug Fixes * **infiniteHits:** do not cache...
Read more >
How to use the react-instantsearch-dom.connectStateResults ...
connectStateResults examples, based on popular ways it is used in public ... Use Snyk Code to scan source code in minutes - no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found