Explorar el Código

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

nonvioce hace 6 meses
padre
commit
20b3984721

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

@@ -656,8 +656,6 @@ ${antiText}
     }
     }
   }, [apiSettings, projectPath, buildGenerationPrompt, ironRules, rollingSummaries]);
   }, [apiSettings, projectPath, buildGenerationPrompt, ironRules, rollingSummaries]);
 
 
-  generateContentRef.current = generateContent;
-
   useEffect(() => {
   useEffect(() => {
     return () => {
     return () => {
       abortControllerRef.current?.abort();
       abortControllerRef.current?.abort();
@@ -679,11 +677,13 @@ ${antiText}
   const autoContentStartedRef = useRef(false);
   const autoContentStartedRef = useRef(false);
   const autoDeAIStartedRef = useRef(false);
   const autoDeAIStartedRef = useRef(false);
   const generateContentRef = useRef<() => Promise<void>>(async () => {});
   const generateContentRef = useRef<() => Promise<void>>(async () => {});
+
+  generateContentRef.current = generateContent;
+
   useEffect(() => {
   useEffect(() => {
     if (autoMode && apiSettings && !autoContentStartedRef.current && !isGenerating) {
     if (autoMode && apiSettings && !autoContentStartedRef.current && !isGenerating) {
       autoContentStartedRef.current = true;
       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);
       return () => clearTimeout(timer);
     }
     }
   }, [autoMode, apiSettings, isGenerating]);
   }, [autoMode, apiSettings, isGenerating]);