修复编译错误和React渲染警告
主要修复内容: 1. 修复ComfyUI服务初始化问题 - 修正ComfyuiConfig导入路径 - 添加自动初始化ComfyUI服务逻辑 - 修复通用工作流服务依赖问题 2. 修复React渲染警告 - 分离WorkflowFormGenerator中的状态更新逻辑 - 使用setTimeout避免渲染时状态更新 - 修复Cannot update component while rendering警告 3. 修复数据序列化问题 - 移除environment_type字段的serde rename属性 - 确保前后端数据格式一致性 4. 添加调试日志 - 在环境编辑功能中添加详细日志 - 便于排查环境类型显示问题 技术细节: - 使用ComfyuiConfig::default()而非ComfyUISettings - 通过setTimeout(0)延迟状态更新到下一个事件循环 - 自动初始化缺失的ComfyUI服务依赖
This commit is contained in:
parent
d5ef15a6d1
commit
050c706ab1
|
|
@ -1,4 +1,5 @@
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
use tracing::info;
|
||||||
use crate::data::repositories::project_repository::ProjectRepository;
|
use crate::data::repositories::project_repository::ProjectRepository;
|
||||||
use crate::data::repositories::material_repository::MaterialRepository;
|
use crate::data::repositories::material_repository::MaterialRepository;
|
||||||
use crate::data::repositories::model_repository::ModelRepository;
|
use crate::data::repositories::model_repository::ModelRepository;
|
||||||
|
|
@ -374,12 +375,31 @@ impl AppState {
|
||||||
|
|
||||||
/// 初始化通用工作流服务
|
/// 初始化通用工作流服务
|
||||||
pub fn initialize_universal_workflow_service(&self) -> anyhow::Result<()> {
|
pub fn initialize_universal_workflow_service(&self) -> anyhow::Result<()> {
|
||||||
|
// 首先尝试初始化 ComfyUI 服务(如果还没有初始化)
|
||||||
|
{
|
||||||
|
let comfyui_service_guard = self.comfyui_infrastructure_service.lock()
|
||||||
|
.map_err(|e| anyhow::anyhow!("Failed to acquire lock for ComfyUI service: {}", e))?;
|
||||||
|
|
||||||
|
if comfyui_service_guard.is_none() {
|
||||||
|
drop(comfyui_service_guard); // 释放锁
|
||||||
|
info!("ComfyUI服务未初始化,正在初始化...");
|
||||||
|
|
||||||
|
// 使用默认配置初始化 ComfyUI 服务
|
||||||
|
let default_config = crate::data::models::comfyui::ComfyuiConfig::default();
|
||||||
|
let comfyui_service = ComfyuiInfrastructureService::new(default_config)
|
||||||
|
.map_err(|e| anyhow::anyhow!("创建ComfyUI服务失败: {}", e))?;
|
||||||
|
|
||||||
|
*self.comfyui_infrastructure_service.lock().unwrap() = Some(comfyui_service);
|
||||||
|
info!("ComfyUI服务初始化成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 检查依赖服务是否已初始化
|
// 检查依赖服务是否已初始化
|
||||||
let comfyui_service = self.comfyui_infrastructure_service.lock()
|
let comfyui_service = self.comfyui_infrastructure_service.lock()
|
||||||
.map_err(|e| anyhow::anyhow!("Failed to acquire lock for ComfyUI service: {}", e))?;
|
.map_err(|e| anyhow::anyhow!("Failed to acquire lock for ComfyUI service: {}", e))?;
|
||||||
|
|
||||||
let comfyui_service = comfyui_service.as_ref()
|
let comfyui_service = comfyui_service.as_ref()
|
||||||
.ok_or_else(|| anyhow::anyhow!("ComfyUI服务未初始化,无法创建通用工作流服务"))?;
|
.ok_or_else(|| anyhow::anyhow!("ComfyUI服务初始化失败"))?;
|
||||||
|
|
||||||
// 检查工作流仓库是否已初始化
|
// 检查工作流仓库是否已初始化
|
||||||
let workflow_template_repo = self.workflow_template_repository.lock().unwrap();
|
let workflow_template_repo = self.workflow_template_repository.lock().unwrap();
|
||||||
|
|
|
||||||
|
|
@ -153,9 +153,23 @@ pub async fn execute_workflow_with_mapping(
|
||||||
let service_guard = state.get_universal_workflow_service()
|
let service_guard = state.get_universal_workflow_service()
|
||||||
.map_err(|e| format!("获取通用工作流服务失败: {}", e))?;
|
.map_err(|e| format!("获取通用工作流服务失败: {}", e))?;
|
||||||
|
|
||||||
service_guard.as_ref()
|
if service_guard.as_ref().is_none() {
|
||||||
.ok_or_else(|| "通用工作流服务未初始化,请先配置执行环境".to_string())?
|
// 尝试初始化通用工作流服务
|
||||||
.clone()
|
drop(service_guard); // 释放锁
|
||||||
|
if let Err(e) = state.initialize_universal_workflow_service() {
|
||||||
|
return Err(format!("初始化通用工作流服务失败: {}", e));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重新获取服务
|
||||||
|
let service_guard = state.get_universal_workflow_service()
|
||||||
|
.map_err(|e| format!("重新获取通用工作流服务失败: {}", e))?;
|
||||||
|
|
||||||
|
service_guard.as_ref()
|
||||||
|
.ok_or_else(|| "通用工作流服务初始化后仍然为空".to_string())?
|
||||||
|
.clone()
|
||||||
|
} else {
|
||||||
|
service_guard.as_ref().unwrap().clone()
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 转换请求格式到新的统一格式
|
// 转换请求格式到新的统一格式
|
||||||
|
|
|
||||||
|
|
@ -110,12 +110,19 @@ export const WorkflowFormGenerator: React.FC<WorkflowFormGeneratorProps> = ({
|
||||||
});
|
});
|
||||||
|
|
||||||
setFormData(initializedData);
|
setFormData(initializedData);
|
||||||
|
}, [uiConfig, initialData]);
|
||||||
|
|
||||||
// 通知父组件
|
// 单独的 useEffect 来通知父组件数据变化,避免渲染时调用
|
||||||
if (onFormDataChange) {
|
useEffect(() => {
|
||||||
onFormDataChange(initializedData);
|
if (onFormDataChange && Object.keys(formData).length > 0) {
|
||||||
|
// 使用 setTimeout 确保在下一个事件循环中执行,避免渲染时状态更新
|
||||||
|
const timeoutId = setTimeout(() => {
|
||||||
|
onFormDataChange(formData);
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
return () => clearTimeout(timeoutId);
|
||||||
}
|
}
|
||||||
}, [uiConfig]); // 只依赖uiConfig,由于useMemo的缓存,不会无限循环
|
}, [formData, onFormDataChange]);
|
||||||
|
|
||||||
// 更新表单数据
|
// 更新表单数据
|
||||||
const updateFormData = useCallback((fieldName: string, value: any) => {
|
const updateFormData = useCallback((fieldName: string, value: any) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue