Update chat-providers-dialog.tsx

This commit is contained in:
Roland Tannous 2026-05-05 21:46:50 +04:00 committed by GitHub
commit a7b0c3b226
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -30,7 +30,7 @@ import {
} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { useEffect, useMemo, useState } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import { toast } from "sonner";
import {
createProviderConfig,
@ -138,6 +138,7 @@ export function ChatProvidersDialog({
const [mutatingProvider, setMutatingProvider] = useState(false);
const [manualModelIds, setManualModelIds] = useState("");
const [customProviderName, setCustomProviderName] = useState("Custom");
const providersRef = useRef(providers);
const reduceMotion = useReducedMotion();
const isCustomProvider = providerType === CUSTOM_PROVIDER_TYPE;
@ -177,6 +178,10 @@ export function ChatProvidersDialog({
[providers],
);
useEffect(() => {
providersRef.current = providers;
}, [providers]);
useEffect(() => {
if (!open) return;
let isMounted = true;
@ -196,7 +201,9 @@ export function ChatProvidersDialog({
}
return registryRows[0]?.provider_type ?? "";
});
const existingById = new Map(providers.map((provider) => [provider.id, provider]));
const existingById = new Map(
providersRef.current.map((provider) => [provider.id, provider]),
);
const syncedProviders: ExternalProviderConfig[] = configRows
.filter((config) => config.is_enabled)
.map((config) => {