From cca70348ecf65b9e50d7331a9aa8a3eeb4dda8c7 Mon Sep 17 00:00:00 2001 From: therealrinku <76877078+therealrinku@users.noreply.github.com> Date: Fri, 1 Aug 2025 12:11:46 +0545 Subject: [PATCH] fix: prevent reloading chat widget after adding api key --- frontend/src/components/widgets/ChatWidget.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/widgets/ChatWidget.jsx b/frontend/src/components/widgets/ChatWidget.jsx index 0f9d9abd3..e81e159be 100644 --- a/frontend/src/components/widgets/ChatWidget.jsx +++ b/frontend/src/components/widgets/ChatWidget.jsx @@ -29,7 +29,8 @@ const ChatWidget = ({ const [apiKey, setApiKey] = useState(''); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); - const hasApiKey = useMemo(() => !!sessionStorage.getItem('openai_api_key'), []); + + const [hasApiKey, setHasApiKey] = useState(!!sessionStorage.getItem('openai_api_key')); // Add this state to store the processed context const [sourceContext, setSourceContext] = useState(null); @@ -169,7 +170,8 @@ const ChatWidget = ({ if (apiKey.trim()) { sessionStorage.setItem('openai_api_key', apiKey.trim()); setShowSettings(false); - window.location.reload(); // Refresh to update hasApiKey state + + setHasApiKey(true); } };