Просмотр исходного кода

fix: correct ref declaration order and actually call via ref in Step4 auto-trigger

nonvioce 6 месяцев назад
Родитель
Сommit
20b3984721

+ 4 - 4
src/app/features/novel-writer/components/pipeline/Step4ContentEditor.tsx

@@ -656,8 +656,6 @@ ${antiText}
     }
   }, [apiSettings, projectPath, buildGenerationPrompt, ironRules, rollingSummaries]);
 
-  generateContentRef.current = generateContent;
-
   useEffect(() => {
     return () => {
       abortControllerRef.current?.abort();
@@ -679,11 +677,13 @@ ${antiText}
   const autoContentStartedRef = useRef(false);
   const autoDeAIStartedRef = useRef(false);
   const generateContentRef = useRef<() => Promise<void>>(async () => {});
+
+  generateContentRef.current = generateContent;
+
   useEffect(() => {
     if (autoMode && apiSettings && !autoContentStartedRef.current && !isGenerating) {
       autoContentStartedRef.current = true;
-      // Small delay to ensure all state is initialized
-      const timer = setTimeout(() => generateContent(), 200);
+      const timer = setTimeout(() => generateContentRef.current(), 300);
       return () => clearTimeout(timer);
     }
   }, [autoMode, apiSettings, isGenerating]);