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}); }); } }