fix: EchartsExt auto-refresh stops when widget leaves DOM (is_in_dom check)

This commit is contained in:
Hermes Agent 2026-06-24 16:50:58 +08:00
parent 8d0848fd9d
commit 3d88fb5548

View File

@ -47,6 +47,11 @@ bricks.EchartsExt = class extends bricks.VBox {
if (this._refresh_timer) return; // 防止重复启动
const doRefresh = () => {
if (!this.is_in_dom()) {
console.log('EchartsExt: widget not in DOM, stop auto-refresh');
this._refresh_timer = null;
return;
}
this.render_urldata().then(() => {
// 继续下一轮
if (this._refresh_timer) { // 检查是否已被取消
@ -54,7 +59,11 @@ bricks.EchartsExt = class extends bricks.VBox {
}
}).catch(err => {
console.error('Auto-refresh failed:', err);
this._refresh_timer = setTimeout(doRefresh, this.refresh_period * 1000); // 失败也重试
if (this.is_in_dom()) {
this._refresh_timer = setTimeout(doRefresh, this.refresh_period * 1000); // 失败也重试
} else {
this._refresh_timer = null;
}
});
};