Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

fix: reset dialog state and abort in-flight test on cancel (#2048) (#2072)

hunterxtangb9f89b43553c
diff --git a/frontend/app/settings/_components/connector-cards.tsx b/frontend/app/settings/_components/connector-cards.tsx
index d2393b26a..d0896694c 100644
--- a/frontend/app/settings/_components/connector-cards.tsx
+++ b/frontend/app/settings/_components/connector-cards.tsx
@@ -126,11 +126,19 @@ export default function ConnectorCards() {
</div>
{dialogDescriptors.map((descriptor) => {
+ // Render only while open so the component unmounts on close, which
+ // resets all useState/useForm state automatically and eliminates
+ // stale field values, error messages, and stuck loading indicators
+ // on reopen. The exit animation is foregone — an acceptable tradeoff
+ // for correctness.
+ if (openDialog !== descriptor.connectorType) return null;
const Dialog = descriptor.SettingsDialog!;
return (
<Dialog
key={descriptor.connectorType}
- open={openDialog === descriptor.connectorType}
+ // mounted only while open; open is always true here,
+ // unmount handles "close"
+ open={true}
setOpen={(open: boolean) =>
setOpenDialog(open ? descriptor.connectorType : null)
}
diff --git a/frontend/enhancements/connectors/azure-blob/settings-dialog.tsx b/frontend/enhancements/connectors/azure-blob/settings-dialog.tsx
index c9e6ef5e5..7164e25d2 100644
--- a/frontend/enhancements/connectors/azure-blob/settings-dialog.tsx
+++ b/frontend/enhancements/connectors/azure-blob/settings-dialog.tsx
@@ -1,7 +1,7 @@
"use client";
import { useQueryClient } from "@tanstack/react-query";
-import { useEffect, useState } from "react";
+import { useEffect, useRef, useState } from "react";
import { FormProvider, useForm } from "react-hook-form";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
@@ -62,7 +62,24 @@ export default function AzureBlobSettingsDialog({
const configureMutation = useAzureBlobConfigureMutation();
+ // Holds the AbortController for the currently in-flight test request so it
+ // can be cancelled if the user closes the dialog or starts a new test.
+ const testAbortRef = useRef<AbortController | null>(null);
+
+ // Abort any in-flight test request when the component unmounts (i.e. when
+ // the dialog is closed, since connector-cards renders it only while open).
+ useEffect(() => {
+ return () => {
+ testAbortRef.current?.abort();
+ };
+ }, []);
+
const handleTestConnection = handleSubmit(async (data) => {
+ // Cancel any previous in-flight test before starting a new one.
+ testAbortRef.current?.abort();
+ const controller = new AbortController();
+ testAbortRef.current = controller;
+
setIsFetchingContainers(true);
setContainersError(null);
setFormError(null);
@@ -74,6 +91,7 @@ export default function AzureBlobSettingsDialog({
const res = await fetch("/api/connectors/azure_blob/test", {
method: "POST",
headers: { "Content-Type": "application/json" },
+ signal: controller.signal,
body: JSON.stringify({
auth_mode: data.auth_mode,
connection_string: data.connection_string || undefined,
@@ -90,11 +108,20 @@ export default function AzureBlobSettingsDialog({
setContainers(fetched);
setSelectedContainers((prev) => prev.filter((c) => fetched.includes(c)));
} catch (err: unknown) {
+ // Ignore cancellations — they are intentional (dialog closed or new test
+ // started) and must not surface an error message to the user.
+ if (err instanceof DOMException && err.name === "AbortError") return;
setContainersError(
err instanceof Error ? err.message : "Connection failed",
);
} finally {
- setIsFetchingContainers(false);
+ // Only clear the loading flag if this invocation is still the active one.
+ // If the user started a second test while this one was in flight, the
+ // second call already replaced testAbortRef.current; clearing here would
+ // flicker the spinner off for the still-running request.
+ if (testAbortRef.current === controller) {
+ setIsFetchingContainers(false);
+ }
}
});