Skip to content

useRelatedProducts hook causes hydration error in SSR setup #6788

@daanjo3

Description

@daanjo3

🐛 Current behavior

At the moment I'm experiencing issues with the useRelatedProducts hook provided by react-instantsearch, specifically in an SSR setup.

At the moment, whenever components which use the useRelatedProducts hook are served by the server along with Algolia server state an hydration error occurs. On closer inspection it seems like the internal state of the hook does not seem to be stable. At the first render it will contain the results as provided by the server to the InstantSearchSSRProvider, however on re-render it will be empty, causing hydration issues.

🔍 Steps to reproduce

  1. Clone my repository which is linked below.
  2. Install dependencies: nvm use && corepack enable && pnpm install
  3. Run the client-only build using pnpm start-client, which should work as intended.
  4. Run the SSR build using pnpm start-server, which should throw hydration errors.

See the project README for a more detailed description.

Live reproduction

https://github.com/daanjo3/algolia-recommendations-ssr

💭 Expected behavior

I would expect the state (and thus the resulting items field) of the useRelatedProducts hook to remain stable across re-renders, as long as no dependencies change.

Package version

algoliasearch 5.41.0, instantsearch.js 4.81.0, react-instantsearch 7.17.0, react 18.3.1, react-dom 18.3.1

Operating system

Arch Linux, MacOS

Browser

Mozilla Firefox 144.0.2, Google Chrome 141.0.7390.107

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Library: React InstantSearch ≥ 7Issues in any of the react-instantsearch@7 packages (formerly named react-instantsearch-hooks)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions