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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel any pending requests if component is unmounted #248

Closed
OsamaShabrez opened this issue Aug 12, 2018 · 3 comments · Fixed by #356
Closed

Cancel any pending requests if component is unmounted #248

OsamaShabrez opened this issue Aug 12, 2018 · 3 comments · Fixed by #356

Comments

@OsamaShabrez
Copy link

Can't call setState (or forceUpdate) 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 the componentWillUnmount method

If you quickly switch between different components and Map is still loading, react complains of memory leak.

We need something similar to axios pending request cancelation in this library to cancel all pending requests and gracefully let the component unmount.

@afuller611-animas
Copy link

@OsamaShabrez Did you ever resolve this issue?
I have the same problem.

@OsamaShabrez
Copy link
Author

@afuller611-animas no, I used this library in a small project for some prototyping and never got back to it. Generally, if nothing else works, a state can be kept as a class field which can be queried before calling setState. A very quick dirty code:

class MyClass extends Component {
  isMounted = false;

  componentDidMount() { isMounted = true; }
  componentWillUnmount() { isMounted = false; }
}

query this field before calling setState.

@afuller611-animas
Copy link

Yeah, was hoping to resolve this without using that method -- but it gets the job done since I can't control this library. Thanks a ton.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants