Skip to content

Commit 478e1b9

Browse files
ratsonPatrick Williams
authored andcommitted
Avoid setState after unmount (#111)
1 parent 1084355 commit 478e1b9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Resolver.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ export default class Resolver extends React.Component {
142142
resolved: { ...this.state.resolved, ...resolved },
143143
};
144144

145-
this.setState(nextState);
145+
this.setAtomicState(nextState);
146+
}
147+
148+
componentWillUnmount() {
149+
this._unmounted = true;
146150
}
147151

148152
computeState(thisProps, nextState) {
@@ -279,10 +283,18 @@ export default class Resolver extends React.Component {
279283
resolved: { ...state.resolved, ...resolved },
280284
};
281285

282-
this.setState(nextState);
286+
this.setAtomicState(nextState);
283287
});
284288
}
285289

290+
setAtomicState(nextState) {
291+
if (this._unmounted) {
292+
return;
293+
}
294+
295+
this.setState(nextState);
296+
}
297+
286298
shouldComponentUpdate(nextProps, nextState) {
287299
// Prevent updating when parent is changing values
288300
if (this.isParentPending()) {

0 commit comments

Comments
 (0)