fix: stop canvas reload effect loop
This commit is contained in:
parent
f1ffeed9f2
commit
365eabead1
@ -413,13 +413,20 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
workflowMaterials,
|
||||
workflowSelections,
|
||||
]);
|
||||
const currentWorkflowPersistedStateRef = useRef<AgentWorkflowPersistedState>(
|
||||
buildCurrentWorkflowPersistedState()
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
currentWorkflowPersistedStateRef.current = buildCurrentWorkflowPersistedState();
|
||||
}, [buildCurrentWorkflowPersistedState]);
|
||||
|
||||
// 加载画布数据
|
||||
useLayoutEffect(() => {
|
||||
console.log('[Canvas] Loading project:', id);
|
||||
|
||||
const loadProject = async () => {
|
||||
const preservedWorkflowState = buildCurrentWorkflowPersistedState();
|
||||
const preservedWorkflowState = currentWorkflowPersistedStateRef.current;
|
||||
const shouldPreserveCurrentWorkflowState =
|
||||
requestedAgentMode &&
|
||||
lastLoadedCanvasIdRef.current === id &&
|
||||
@ -532,7 +539,7 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
};
|
||||
|
||||
loadProject();
|
||||
}, [buildCurrentWorkflowPersistedState, id, requestedAgentMode]);
|
||||
}, [id, requestedAgentMode]);
|
||||
|
||||
useEffect(() => {
|
||||
const updateViewportWidth = () => setViewportWidth(window.innerWidth);
|
||||
@ -596,6 +603,11 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
workflowMaterials,
|
||||
workflowSelections,
|
||||
]);
|
||||
const persistedAgentProjectStateRef = useRef(buildPersistedAgentProjectState());
|
||||
|
||||
useEffect(() => {
|
||||
persistedAgentProjectStateRef.current = buildPersistedAgentProjectState();
|
||||
}, [buildPersistedAgentProjectState]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isAgentMode) return;
|
||||
@ -724,7 +736,7 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
try {
|
||||
const result = await agentProjectService.createProject({
|
||||
title: buildDefaultAgentProjectTitle(),
|
||||
projectState: buildPersistedAgentProjectState(),
|
||||
projectState: persistedAgentProjectStateRef.current,
|
||||
});
|
||||
if (!result.success || !result.data) {
|
||||
throw new Error(result.error || "创建生图项目失败");
|
||||
@ -751,7 +763,6 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
};
|
||||
}, [
|
||||
agentProjectId,
|
||||
buildPersistedAgentProjectState,
|
||||
isAgentWorkspaceEnabled,
|
||||
requestedAgentMode,
|
||||
updateCanvasSearchParams,
|
||||
@ -773,7 +784,7 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
const persistedState = normalizeAgentGenerationProjectPersistedState(
|
||||
result.data.projectState
|
||||
);
|
||||
const currentWorkflowState = buildCurrentWorkflowPersistedState();
|
||||
const currentWorkflowState = currentWorkflowPersistedStateRef.current;
|
||||
const persistedWorkflow = hasMeaningfulWorkflowState(persistedState.workflowState)
|
||||
? persistedState.workflowState
|
||||
: hasMeaningfulWorkflowState(currentWorkflowState)
|
||||
@ -814,7 +825,7 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [agentProjectId, buildCurrentWorkflowPersistedState, requestedAgentMode]);
|
||||
}, [agentProjectId, requestedAgentMode]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAgentMode || !agentProjectId || isAgentProjectLoading) return;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user