From f1d75921b7b9980f774f90f1aab28ca58d31d237 Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2698393+2betop@users.noreply.github.com> Date: Fri, 11 Oct 2024 17:36:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20tpl=20=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E6=97=B6=E5=BA=8F=E9=97=AE=E9=A2=98=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E6=B8=B2=E6=9F=93=E9=94=99=E8=AF=AF=20(#11016)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis/src/renderers/Tpl.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/amis/src/renderers/Tpl.tsx b/packages/amis/src/renderers/Tpl.tsx index ecd272e11..2c1a7650e 100644 --- a/packages/amis/src/renderers/Tpl.tsx +++ b/packages/amis/src/renderers/Tpl.tsx @@ -73,6 +73,7 @@ export class Tpl extends React.Component { dom: any; mounted: boolean; + sn: number = 0; constructor(props: TplProps) { super(props); @@ -102,7 +103,13 @@ export class Tpl extends React.Component { @autobind async updateContent() { + let sn = ++this.sn; const content = await this.getAsyncContent(); + + // 解决异步时序问题,防止较早的运算覆盖较晚的运算结果 + if (sn !== this.sn) { + return; + } this.mounted && this.setState({content}); }