Skip to content

React setState warnings on component navigation #157

@rmars

Description

@rmars

When you move around between views within the app, you sometimes get React warnings:

index_bundle.js:21229 Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op.

Please check the code for the TabbedMetricsTable component.

My theory on this is that if we leave a page in the middle of a fetch, after the fetch completes, the page still tries to update, even though it's unmounted.

We should either:

  • store an isMounted property in componentDidMount and unset it in componentWillUnmount, and only call setState if isMounted is true (<- band aid)
  • wrap our fetch calls in a cancelable promise (<- more ideal)

Helpful resource:
https://reactjs.org/blog/2015/12/16/ismounted-antipattern.html

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions