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:
@@ -151,6 +151,15 @@ export default function AgentPage() {
|
||||
const [isTyping, setIsTyping] = useState(false);
|
||||
const messagesEndRef = useRef<HTMLDivElement>(null);
|
||||
const inputRef = useRef<any>(null);
|
||||
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
const scrollToBottom = () => {
|
||||
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
||||
@@ -174,8 +183,13 @@ export default function AgentPage() {
|
||||
setInputValue("");
|
||||
setIsTyping(true);
|
||||
|
||||
// 清理旧的 timeout
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
}
|
||||
|
||||
// 模拟AI响应
|
||||
setTimeout(() => {
|
||||
timeoutRef.current = setTimeout(() => {
|
||||
const response = generateResponse(content);
|
||||
const assistantMessage: Message = {
|
||||
id: (Date.now() + 1).toString(),
|
||||
|
||||
Reference in New Issue
Block a user