diff options
author | Fabio Berger <me@fabioberger.com> | 2018-01-31 03:12:32 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-01-31 03:12:32 +0800 |
commit | e219772b2a25712f41fb819be36917d3b889201f (patch) | |
tree | c9720d042e65d896c33d68eed918e69c3ad3771c /packages/website/ts/pages | |
parent | 144a507a2e0e341e8c8b97f67a25e1283ebc3687 (diff) | |
download | dexon-sol-tools-e219772b2a25712f41fb819be36917d3b889201f.tar dexon-sol-tools-e219772b2a25712f41fb819be36917d3b889201f.tar.gz dexon-sol-tools-e219772b2a25712f41fb819be36917d3b889201f.tar.bz2 dexon-sol-tools-e219772b2a25712f41fb819be36917d3b889201f.tar.lz dexon-sol-tools-e219772b2a25712f41fb819be36917d3b889201f.tar.xz dexon-sol-tools-e219772b2a25712f41fb819be36917d3b889201f.tar.zst dexon-sol-tools-e219772b2a25712f41fb819be36917d3b889201f.zip |
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
Diffstat (limited to 'packages/website/ts/pages')
-rw-r--r-- | packages/website/ts/pages/documentation/documentation.tsx | 23 | ||||
-rw-r--r-- | packages/website/ts/pages/wiki/wiki.tsx | 21 |
2 files changed, 28 insertions, 16 deletions
diff --git a/packages/website/ts/pages/documentation/documentation.tsx b/packages/website/ts/pages/documentation/documentation.tsx index 13a85c301..a5ecd9e1c 100644 --- a/packages/website/ts/pages/documentation/documentation.tsx +++ b/packages/website/ts/pages/documentation/documentation.tsx @@ -78,8 +78,10 @@ const styles: Styles = { }; export class Documentation extends React.Component<DocumentationAllProps, DocumentationState> { + private _isUnmounted: boolean; constructor(props: DocumentationAllProps) { super(props); + this._isUnmounted = false; this.state = { docAgnosticFormat: undefined, }; @@ -92,6 +94,9 @@ export class Documentation extends React.Component<DocumentationAllProps, Docume // tslint:disable-next-line:no-floating-promises this._fetchJSONDocsFireAndForgetAsync(preferredVersionIfExists); } + public componentWillUnmount() { + this._isUnmounted = true; + } public render() { const menuSubsectionsBySection = _.isUndefined(this.state.docAgnosticFormat) ? {} @@ -367,13 +372,15 @@ export class Documentation extends React.Component<DocumentationAllProps, Docume ); const docAgnosticFormat = this.props.docsInfo.convertToDocAgnosticFormat(versionDocObj as DoxityDocObj); - this.setState( - { - docAgnosticFormat, - }, - () => { - this._scrollToHash(); - }, - ); + if (!this._isUnmounted) { + this.setState( + { + docAgnosticFormat, + }, + () => { + this._scrollToHash(); + }, + ); + } } } diff --git a/packages/website/ts/pages/wiki/wiki.tsx b/packages/website/ts/pages/wiki/wiki.tsx index a3cf72450..daf5c27a7 100644 --- a/packages/website/ts/pages/wiki/wiki.tsx +++ b/packages/website/ts/pages/wiki/wiki.tsx @@ -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); |