algolia / react-instantsearch

āš”ļø Lightning-fast search for React and React Native applications, by Algolia.
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/react/
MIT License
1.97k stars 386 forks source link

Nexjts SSR broken functionality with reactStrictMode enabled #3537

Closed abusada closed 1 year ago

abusada commented 2 years ago

šŸ› Bug description

I'm following this guide trying to achieve server side rendering with nextjs and react-instantsearch-hooks.

once i wrap my code with InstantSearchSSRProvider, search functionality simple stops working, screenshot- 2022-06-23 at 15 57 31

Live reproduction:

https://codesandbox.io/s/hungry-stitch-b070o2?file=/pages/index.tsx:990-1014

šŸ” Bug reproduction

Steps to reproduce the behavior:

  1. Go to the provided sandbox: https://codesandbox.io/s/hungry-stitch-b070o2?file=/pages/index.tsx:990-1014
  2. Try using the search box

šŸ’­ Expected behavior

Expect search to work and hits to update, notice how in the withour-ssr page the search functionality is working properly.

screenshot- 2022-06-23 at 16 03 39

Environment

please note the following configs in next.config.js:

module.exports = {
  reactStrictMode: true,
  swcMinify: true
};

update setting reactStrictMode to false fixes the issue, here is a fork of the above sandbox with strict mode turned off: https://codesandbox.io/s/lucid-cache-n7h0no?file=/next.config.js:19-45

Haroenv commented 2 years ago

There's indeed an issue with strict mode in server side rendering we haven't yet been able to pinpoint (the destroy method is called in the wrong order, and all state is reset, including refinements).

For now disabling strict mode in server side rendering is a workaround

abusada commented 2 years ago

Could you possibly point me to the code where you suspect the issue is happening? perhaps i could be of help!

Haroenv commented 2 years ago

There's some tests:

Also there's a more complex part where widgets get added more than once in hydration, but that might not be the cause of the issue

francoischalifour commented 2 years ago

This issue may be addressed in v6.30.2. Could you please upgrade and let us know how it goes?

FabienMotte commented 1 year ago

@kanehara Did the fix mentioned by @francoischalifour fixed your issue?

We're doing a round of cleanup before migrating this repository to the new InstantSearch monorepo. This issue seems not to have generated much activity lately, so we're going to close it, feel free to reopen if needed.