Fix all setState calls after unmounted errors. Decided to create our own flag rather then using a cancellablePromise since there was little to be gained from this alternative
This commit is contained in:
@@ -45,8 +45,10 @@ const styles: Styles = {
|
||||
|
||||
export class Wiki extends React.Component<WikiProps, WikiState> {
|
||||
private _wikiBackoffTimeoutId: number;
|
||||
private _isUnmounted: boolean;
|
||||
constructor(props: WikiProps) {
|
||||
super(props);
|
||||
this._isUnmounted = false;
|
||||
this.state = {
|
||||
articlesBySection: undefined,
|
||||
};
|
||||
@@ -56,6 +58,7 @@ export class Wiki extends React.Component<WikiProps, WikiState> {
|
||||
this._fetchArticlesBySectionAsync();
|
||||
}
|
||||
public componentWillUnmount() {
|
||||
this._isUnmounted = true;
|
||||
clearTimeout(this._wikiBackoffTimeoutId);
|
||||
}
|
||||
public render() {
|
||||
@@ -179,14 +182,16 @@ export class Wiki extends React.Component<WikiProps, WikiState> {
|
||||
return;
|
||||
}
|
||||
const articlesBySection = await response.json();
|
||||
this.setState(
|
||||
{
|
||||
articlesBySection,
|
||||
},
|
||||
() => {
|
||||
this._scrollToHash();
|
||||
},
|
||||
);
|
||||
if (!this._isUnmounted) {
|
||||
this.setState(
|
||||
{
|
||||
articlesBySection,
|
||||
},
|
||||
() => {
|
||||
this._scrollToHash();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
private _getMenuSubsectionsBySection(articlesBySection: ArticlesBySection) {
|
||||
const sectionNames = _.keys(articlesBySection);
|
||||
|
Reference in New Issue
Block a user