π OpenHands: AI-Driven Development
fix(frontend): prevent API key from resetting after modal change (#2329)
tobitegea8c6fd0d420a
diff --git a/frontend/src/components/chat/ChatInput.test.tsx b/frontend/src/components/chat/ChatInput.test.tsxindex 16cef141bb..199fe81180 100644--- a/frontend/src/components/chat/ChatInput.test.tsx+++ b/frontend/src/components/chat/ChatInput.test.tsx@@ -3,11 +3,11 @@ import userEvent from "@testing-library/user-event";import { act, render, fireEvent } from "@testing-library/react";import ChatInput from "./ChatInput";-afterEach(() => {- vi.clearAllMocks();-});-describe("ChatInput", () => {+ afterEach(() => {+ vi.clearAllMocks();+ });+const onSendMessage = vi.fn();it("should render a textarea", () => {diff --git a/frontend/src/components/modals/settings/SettingsModal.test.tsx b/frontend/src/components/modals/settings/SettingsModal.test.tsxindex a740acf8c6..323a5471e3 100644--- a/frontend/src/components/modals/settings/SettingsModal.test.tsx+++ b/frontend/src/components/modals/settings/SettingsModal.test.tsx@@ -26,6 +26,7 @@ vi.mock("#/services/settings", async (importOriginal) => ({LLM_MODEL: "gpt-4o",AGENT: "MonologueAgent",LANGUAGE: "en",+ LLM_API_KEY: "sk-...",}),getDefaultSettings: vi.fn().mockReturnValue({LLM_MODEL: "gpt-4o",@@ -139,7 +140,6 @@ describe("SettingsModal", () => {expect(saveSettings).toHaveBeenCalledWith({...initialSettings,LLM_MODEL: "model3",- LLM_API_KEY: "", // reset after model change});});@@ -196,7 +196,7 @@ describe("SettingsModal", () => {await userEvent.click(saveButton);});- expect(toastSpy).toHaveBeenCalledTimes(2);+ expect(toastSpy).toHaveBeenCalledTimes(3);});it("should change the language", async () => {diff --git a/frontend/src/components/modals/settings/SettingsModal.tsx b/frontend/src/components/modals/settings/SettingsModal.tsxindex 38bca6454b..92f2be82fc 100644--- a/frontend/src/components/modals/settings/SettingsModal.tsx+++ b/frontend/src/components/modals/settings/SettingsModal.tsx@@ -66,12 +66,9 @@ function SettingsModal({ isOpen, onOpenChange }: SettingsProps) {}, []);const handleModelChange = (model: string) => {- // Needs to also reset the API key.- const key = localStorage.getItem(`API_KEY_${model}`);setSettings((prev) => ({...prev,LLM_MODEL: model,- LLM_API_KEY: key || "",}));};