OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
fix: onboarding timeout cleanup issue (#1977)
Mike Fortman13364b35921e
diff --git a/frontend/app/onboarding/_components/onboarding-card.tsx b/frontend/app/onboarding/_components/onboarding-card.tsxindex 0229ece0d..49be6119c 100644--- a/frontend/app/onboarding/_components/onboarding-card.tsx+++ b/frontend/app/onboarding/_components/onboarding-card.tsx@@ -196,6 +196,10 @@ const OnboardingCard = ({// Track which tasks we've already handled to prevent infinite loopsconst handledFailedTasksRef = useRef<Set<string>>(new Set());+ // Ref for the completion timeout so it persists across effect re-runs+ const completeTimeoutRef = useRef<ReturnType<typeof setTimeout>>(undefined);+ useEffect(() => () => clearTimeout(completeTimeoutRef.current), []);+// Query tasks to track completionconst { data: tasks } = useGetTasksQuery({enabled: currentStep !== null && !isCompleted, // Only poll when onboarding has started and stop once step is complete@@ -277,7 +281,6 @@ const OnboardingCard = ({// Monitor tasks and call onComplete when all tasks are doneuseEffect(() => {- let completeTimeoutId: NodeJS.Timeout;if (currentStep === null || !tasks || !isEmbedding) {return;}@@ -376,6 +379,7 @@ const OnboardingCard = ({failed_files: taskWithFailure.failed_files,});+ clearTimeout(completeTimeoutRef.current);setError(errorMessage);setCurrentStep(totalSteps);rollbackMutation.mutate({ embedding_only: isEmbedding });@@ -409,13 +413,12 @@ const OnboardingCard = ({// Set to final step to show "Done"setCurrentStep(totalSteps);- // Wait a bit before completing- completeTimeoutId = setTimeout(() => {+ // Wait a bit before completing — stored in a ref so the timeout+ // survives the re-render caused by setCurrentStep above.+ completeTimeoutRef.current = setTimeout(() => {onComplete();}, 1000);}-- return () => clearTimeout(completeTimeoutId);}, [tasks,currentStep,diff --git a/frontend/app/onboarding/_components/onboarding-upload.tsx b/frontend/app/onboarding/_components/onboarding-upload.tsxindex b18e32fff..2900c0059 100644--- a/frontend/app/onboarding/_components/onboarding-upload.tsx+++ b/frontend/app/onboarding/_components/onboarding-upload.tsx@@ -18,6 +18,7 @@ interface OnboardingUploadProps {const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {const fileInputRef = useRef<HTMLInputElement>(null);+ const completeTimeoutRef = useRef<ReturnType<typeof setTimeout>>(undefined);const [isUploading, setIsUploading] = useState(false);const [currentStep, setCurrentStep] = useState<number | null>(null);const [uploadedFilename, setUploadedFilename] = useState<string | null>(null);@@ -44,10 +45,11 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {const { refetch: refetchNudges } = useGetNudgesQuery(null);+ useEffect(() => () => clearTimeout(completeTimeoutRef.current), []);+// Monitor tasks and call onComplete when file processing is doneuseEffect(() => {let cancelled = false;- let completeTimeoutId: NodeJS.Timeout;if (currentStep === null || !tasks || !uploadedTaskId) {return;}@@ -95,6 +97,7 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {}}+ clearTimeout(completeTimeoutRef.current);setError(errorMessage);setCurrentStep(null);setUploadedTaskId(null);@@ -159,33 +162,25 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {}).finally(() => {setIsCreatingFilter(false);- // Refetch nudges to get new onesrefetchNudges();- // Wait a bit before completing (after filter is created)- if (!cancelled) {- completeTimeoutId = setTimeout(() => {- if (!cancelled) onComplete();+ if (!cancelled && !completeTimeoutRef.current) {+ completeTimeoutRef.current = setTimeout(() => {+ onComplete();}, 1000);}});- } else if (!isCreatingFilter) {- // No filter to create, just complete- // Refetch nudges to get new ones+ } else if (!isCreatingFilter && !completeTimeoutRef.current) {refetchNudges();- // Wait a bit before completing- if (!cancelled) {- completeTimeoutId = setTimeout(() => {- if (!cancelled) onComplete();- }, 1000);- }+ completeTimeoutRef.current = setTimeout(() => {+ onComplete();+ }, 1000);}}return () => {cancelled = true;- clearTimeout(completeTimeoutId);};}, [tasks,