Commit 1a68aa9
committed
[sat fixit] Don't call
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/D34577setState for unmounted components1 parent 539b056 commit 1a68aa9
1 file changed
+8
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | | - | |
49 | | - | |
50 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
| |||
155 | 158 | | |
156 | 159 | | |
157 | 160 | | |
| 161 | + | |
158 | 162 | | |
159 | 163 | | |
160 | 164 | | |
161 | 165 | | |
162 | 166 | | |
| 167 | + | |
163 | 168 | | |
164 | 169 | | |
165 | 170 | | |
| |||
0 commit comments