From d809d4cc549b84dec4a55a28455e3e6517dfdf77 Mon Sep 17 00:00:00 2001 From: allenve Date: Wed, 10 May 2023 16:26:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20tpl=E7=BB=84=E4=BB=B6=E9=94=80=E6=AF=81?= =?UTF-8?q?=E6=97=B6=E5=8F=96=E6=B6=88setState?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis/src/renderers/Tpl.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/amis/src/renderers/Tpl.tsx b/packages/amis/src/renderers/Tpl.tsx index 7e3729fa1..5ce656f6f 100644 --- a/packages/amis/src/renderers/Tpl.tsx +++ b/packages/amis/src/renderers/Tpl.tsx @@ -63,12 +63,14 @@ export class Tpl extends React.Component { }; dom: any; + mounted: boolean; constructor(props: TplProps) { super(props); this.state = { content: this.getContent() }; + this.mounted = true; } componentDidUpdate(prevProps: Readonly): void { @@ -85,13 +87,17 @@ export class Tpl extends React.Component { this.updateContent(); } + componentWillUnmount() { + this.mounted = false; + } + @autobind updateContent() { const {tpl, html, text} = this.props; if (html || tpl || text) { this.getAsyncContent().then(content => { - this.setState({content}); + this.mounted && this.setState({content}); }); } }