From 990ece9807bdbb8bb9221c7addec18a1e3c4a7a1 Mon Sep 17 00:00:00 2001 From: Chris Hasson Date: Wed, 7 May 2025 12:21:31 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix(settings):=20Fix=20Wrong=20m?= =?UTF-8?q?odel=20after=20login=20(#213)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously we were spreading the entire `prevCachedState.apiConfiguration` object when the keys changed, which would wipe out unsaved changes the user might have made to things like `prevCachedState.apiConfiguration.kiloModel`. Now we only set the keys that might be set via callback and don't trigger a save explicitly. The user will need to click 'save' in order to exit the SettingView like normal (same as changing any other setting). - update state with specific tokens/keys to avoid overwriting unsaved changes - simplify useEffect dependencies by using direct variables **Dev thoughts** This does make me think.. should "login" keys / tokens be a "setting"? seems like it should be in the Settings view UI, but possibly separate from the other settings state of the api. I feel like it's not intuitive to have to click a "save" button once you login to something for it to remain saved. **Test plan**: Verified that logging in / out no longer overwrites other non-saved changes in the Settings. Now users will have to click save for any changes they make, including login state. (This should be ok since we have that confirmation dialog if they don't.) **Closes** #123 --- .changeset/sharp-colts-add.md | 5 +++++ .../src/components/settings/SettingsView.tsx | 22 ++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 .changeset/sharp-colts-add.md diff --git a/.changeset/sharp-colts-add.md b/.changeset/sharp-colts-add.md new file mode 100644 index 0000000000..f424417967 --- /dev/null +++ b/.changeset/sharp-colts-add.md @@ -0,0 +1,5 @@ +--- +"kilo-code": patch +--- + +Fix wrong model after login (#213) diff --git a/webview-ui/src/components/settings/SettingsView.tsx b/webview-ui/src/components/settings/SettingsView.tsx index 088f90a8dd..481e2ebd3d 100644 --- a/webview-ui/src/components/settings/SettingsView.tsx +++ b/webview-ui/src/components/settings/SettingsView.tsx @@ -172,16 +172,22 @@ const SettingsView = forwardRef(({ onDone, o // kilocode_change start // Temporary way of making sure that the Settings view updates its local state properly when receiving // api keys from providers that support url callbacks. This whole Settings View needs proper with this local state thing later + const { kilocodeToken, openRouterApiKey, glamaApiKey, requestyApiKey } = extensionState.apiConfiguration ?? {} useEffect(() => { - setCachedState((prevCachedState) => ({ ...prevCachedState, ...extensionState })) - setChangeDetected(false) + setCachedState((prevCachedState) => ({ + ...prevCachedState, + apiConfiguration: { + ...prevCachedState.apiConfiguration, + // Only set specific tokens/keys instead of spreading the entire + // `prevCachedState.apiConfiguration` since it may contain unsaved changes + kilocodeToken, + openRouterApiKey, + glamaApiKey, + requestyApiKey, + }, + })) // eslint-disable-next-line react-hooks/exhaustive-deps - }, [ - extensionState.apiConfiguration?.kilocodeToken, - extensionState.apiConfiguration?.openRouterApiKey, - extensionState.apiConfiguration?.glamaApiKey, - extensionState.apiConfiguration?.requestyApiKey, - ]) + }, [kilocodeToken, openRouterApiKey, glamaApiKey, requestyApiKey]) useEffect(() => { // Only update if we're not already detecting changes