You've already forked DataMate
fix(components): 修复组件中定时器内存泄漏问题
- 在TopLoadingBar组件中添加timeoutRef并正确清理定时器 - 在Agent页面中添加timeoutRef管理AI响应模拟定时器 - 修复BasicInformation组件中useCallback依赖数组缺失问题 - 在CreateDataset页面中传递hidden属性控制数据源显示 - 在Orchestration页面中添加intervalRef管理工作流执行进度 - 在SynthesisTask中添加testTimeoutRef管理模板测试定时器 - 确保所有组件卸载时正确清除定时器避免内存泄漏
This commit is contained in:
@@ -4,6 +4,7 @@ const TopLoadingBar = () => {
|
||||
const [isVisible, setIsVisible] = useState(false);
|
||||
const [progress, setProgress] = useState(0);
|
||||
const intervalRef = useRef(null);
|
||||
const timeoutRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
// 监听全局事件
|
||||
@@ -33,8 +34,13 @@ const TopLoadingBar = () => {
|
||||
clearInterval(intervalRef.current);
|
||||
intervalRef.current = null;
|
||||
}
|
||||
// 清除旧的timeout
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
timeoutRef.current = null;
|
||||
}
|
||||
setProgress(100);
|
||||
setTimeout(() => {
|
||||
timeoutRef.current = setTimeout(() => {
|
||||
setIsVisible(false);
|
||||
setProgress(0);
|
||||
}, 300);
|
||||
@@ -49,6 +55,9 @@ const TopLoadingBar = () => {
|
||||
if (intervalRef.current) {
|
||||
clearInterval(intervalRef.current);
|
||||
}
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
}
|
||||
window.removeEventListener("loading:show", handleShow);
|
||||
window.removeEventListener("loading:hide", handleHide);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user