You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 15, 2019. It is now read-only.
[sat fixit] Don't call setState for unmounted components
Summary:
Before this change, in very rare cases, `component.setState()` was
being called on components that weren't actually mounted. In particular, this
happened in SAT when:
1. A component (call it `A`) was subscribed to a store using
`StateFromStoreMixin` and triggered a flux change in that store to navigate
to a new URL.
2. Backbone started updating the `StateFromStoreMixin`s that were subscribed to
that store.
3. The parent component of `A` received the update, re-rendered, and `A`
was no longer in the render tree, and was unmounted.
4. Backbone continued updating the `StateFromStoreMixin` instances, eventually
reaching `A`'s instance.
5. `A`'s `StateFromStoreMixin` attempted to call `.setState()` to update to
the new values, but `A` is no longer mounted.
The solution to this is for `StateFromStore` to check whether the component is
mounted before calling `.setState()`. We could do this using
`component.isMounted()` but
[`.isMounted` is an antipattern](https://facebook.github.io/react/blog/2015/12/16/ismounted-antipattern.html)
and will be deprecated. Instead, we manually keep track of an `isMounted`
value (as suggested by the article) and check that.
Test Plan:
- Visit http://localhost:8081/mission/sat/practice/math
- Open a practice task
- See no warning about `setState()` being called on an unmounted component.
Reviewers: amy, mattdunnrankin
Reviewed By: amy
Subscribers: lauren, #gtp
Differential Revision: https://phabricator.khanacademy.org/D34577
0 commit comments