fix: 修复 tpl 渲染时序问题导致的渲染错误 (#11016)

This commit is contained in:
liaoxuezhi 2024-10-11 17:36:57 +08:00 committed by GitHub
parent 94ebe12715
commit f1d75921b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -73,6 +73,7 @@ export class Tpl extends React.Component<TplProps, TplState> {
dom: any;
mounted: boolean;
sn: number = 0;
constructor(props: TplProps) {
super(props);
@ -102,7 +103,13 @@ export class Tpl extends React.Component<TplProps, TplState> {
@autobind
async updateContent() {
let sn = ++this.sn;
const content = await this.getAsyncContent();
// 解决异步时序问题,防止较早的运算覆盖较晚的运算结果
if (sn !== this.sn) {
return;
}
this.mounted && this.setState({content});
}