Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Can't perform a React state update on an unmounted component." - Third party router listener not disposed in time? #5947

Open
1 task done
adambremler opened this issue Nov 29, 2023 · 2 comments
Labels
triage Issues to be categorized by the team

Comments

@adambremler
Copy link

馃悰 Current behavior

When loading a page with the InstantSearch component that syncs with a third party router via start and dispose, then navigating away, the following error occurs: Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function..

馃攳 Steps to reproduce

  1. Load the initial page that renders the InstantSearch component, which is synced to a third party router (react-router-dom) via start and dispose.
  2. Navigate away by pressing a Link, and the error should appear in the console.

Live reproduction

https://codesandbox.io/p/sandbox/hopeful-night-flhh3j?file=%2Fsrc%2FApp.tsx

馃挱 Expected behavior

I would expect the dispose function to be run in time so that there is no attempt to sync the URL, which results in the state update on an unmounted component.

Package version

instantsearch.js 4.60.0, react-instantsearch 7.3.0

Operating system

macOS 13.2.1

Browser

Chrome 119.0.6045.159

Code of Conduct

  • I agree to follow this project's Code of Conduct
@adambremler adambremler added the triage Issues to be categorized by the team label Nov 29, 2023
@howells
Copy link

howells commented Jan 16, 2024

@adambremler I have this exact problem, but with Next.js's router, and I can't fathom how to solve it. Did you sort it out in the end?

@Haroenv
Copy link
Contributor

Haroenv commented Jan 16, 2024

Dispose indeed happens after the widget and component is unmounted, to prevent it being called twice during strict mode. React Router should be synchronisable with the history router directly, similar to the next integration: https://github.com/algolia/instantsearch/blob/master/packages/react-instantsearch-router-nextjs/src/index.ts#L99-L175, have you tried that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Issues to be categorized by the team
Projects
None yet
Development

No branches or pull requests

3 participants