mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-09 15:52:40 +02:00
fix(frontend): prevent infinite retry loop when chat clone fails
Add cloneError state to track clone failures and prevent the useEffect from continuously retrying when completeClone() fails.
This commit is contained in:
parent
b20fbaca4b
commit
22943972c2
1 changed files with 4 additions and 2 deletions
|
|
@ -143,6 +143,7 @@ export default function NewChatPage() {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [isInitializing, setIsInitializing] = useState(true);
|
const [isInitializing, setIsInitializing] = useState(true);
|
||||||
const [isCompletingClone, setIsCompletingClone] = useState(false);
|
const [isCompletingClone, setIsCompletingClone] = useState(false);
|
||||||
|
const [cloneError, setCloneError] = useState(false);
|
||||||
const [threadId, setThreadId] = useState<number | null>(null);
|
const [threadId, setThreadId] = useState<number | null>(null);
|
||||||
const [currentThread, setCurrentThread] = useState<ThreadRecord | null>(null);
|
const [currentThread, setCurrentThread] = useState<ThreadRecord | null>(null);
|
||||||
const [messages, setMessages] = useState<ThreadMessageLike[]>([]);
|
const [messages, setMessages] = useState<ThreadMessageLike[]>([]);
|
||||||
|
|
@ -333,7 +334,7 @@ export default function NewChatPage() {
|
||||||
|
|
||||||
// Handle clone completion when thread has clone_pending flag
|
// Handle clone completion when thread has clone_pending flag
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!currentThread?.clone_pending || isCompletingClone) return;
|
if (!currentThread?.clone_pending || isCompletingClone || cloneError) return;
|
||||||
|
|
||||||
const completeClone = async () => {
|
const completeClone = async () => {
|
||||||
setIsCompletingClone(true);
|
setIsCompletingClone(true);
|
||||||
|
|
@ -351,13 +352,14 @@ export default function NewChatPage() {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[NewChatPage] Failed to complete clone:", error);
|
console.error("[NewChatPage] Failed to complete clone:", error);
|
||||||
toast.error("Failed to copy chat content. Please try again.");
|
toast.error("Failed to copy chat content. Please try again.");
|
||||||
|
setCloneError(true);
|
||||||
} finally {
|
} finally {
|
||||||
setIsCompletingClone(false);
|
setIsCompletingClone(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
completeClone();
|
completeClone();
|
||||||
}, [currentThread?.clone_pending, currentThread?.id, isCompletingClone, initializeThread, queryClient]);
|
}, [currentThread?.clone_pending, currentThread?.id, isCompletingClone, cloneError, initializeThread, queryClient]);
|
||||||
|
|
||||||
// Handle scroll to comment from URL query params (e.g., from inbox item click)
|
// Handle scroll to comment from URL query params (e.g., from inbox item click)
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue