Skip to content

Conversation

@hassoncs
Copy link
Contributor

@hassoncs hassoncs commented May 7, 2025

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).

213-fix-wrong-model-after-login

  • 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.)

@changeset-bot
Copy link

changeset-bot bot commented May 7, 2025

🦋 Changeset detected

Latest commit: 2ae86d1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
kilo-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@hassoncs hassoncs force-pushed the fix-wrong-model-after-login-213 branch from 4d22dac to 8be91f3 Compare May 7, 2025 23:57
@hassoncs hassoncs marked this pull request as ready for review May 7, 2025 23:57
@hassoncs hassoncs changed the title Fix wrong model after login [#213] Fix wrong model after login (#213) May 7, 2025
@hassoncs hassoncs force-pushed the fix-wrong-model-after-login-213 branch from 8be91f3 to 990ece9 Compare May 8, 2025 00:04
Copy link
Contributor

@drakonen drakonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, unsure about the .changeset file if that should be included,

@kevinvandijk should this PR have a .changeset file?

Copy link
Collaborator

@kevinvandijk kevinvandijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a regression of a previous bug. Now when changing a setting and then clicking on 'Done', then clicking on 'Discard changes'. It will freeze. See screen shot
image

@kevinvandijk
Copy link
Collaborator

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 agree. This is a bit of a weird flow but we accepted it for now because usually people will only log in on the welcome flow and logging out here and logging back in is not a common use case. Once we start on customizing it to be our own settingsview we should work on improving that. Eventually we like to add token support as well in #240 but this also requires backend changes.

@hassoncs hassoncs force-pushed the fix-wrong-model-after-login-213 branch from 990ece9 to 88b25ae Compare May 13, 2025 01:45
@hassoncs
Copy link
Contributor Author

good catch, @kevinvandijk! It took me a second to figure out, but it seems the bug you found was already on the main branch. I went back to main and I was able to reproduce it. It seemed to be caused by the setTimeout in the dialog code. I added a new commit to fix it with an explanation. I tested it pretty well, but it wouldn't hurt to confirm that I didn't miss anything!

Copy link
Collaborator

@kevinvandijk kevinvandijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find @hassoncs! I was not aware it was in main as well. Seems to work well now here indeed!

hassoncs added 2 commits May 13, 2025 07:44
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
…tingsView

- remove setTimeout wrapping confirmDialogHandler call for immediate execution

I've fixed the bug in the settings view that was causing the "Discard unsaved changes" dialog to appear twice and freeze when changing the diffEnabled setting.

The issue was a race condition in the onConfirmDialogResult function. When using setTimeout to delay the callback execution, React would re-render the component before the callback ran. During this re-render, the effect comparing cachedState and extensionState would detect a difference again specifically with the diffEnabled setting, causing isChangeDetected to be set back to true and triggering an infinite loop.

The fix removes the setTimeout and calls the callback directly after setting the state, ensuring it runs before any effects can set isChangeDetected back to true.

Test plan:
- Logged in / out confirmed unsaved settings do not change
- update a setting, discard, confirm no freeze
- update setting, save, confirm saved
@hassoncs hassoncs force-pushed the fix-wrong-model-after-login-213 branch from 88b25ae to 2ae86d1 Compare May 13, 2025 14:58
@hassoncs hassoncs merged commit 106b722 into main May 13, 2025
9 checks passed
@hassoncs hassoncs deleted the fix-wrong-model-after-login-213 branch May 13, 2025 15:13
RSO added a commit that referenced this pull request May 21, 2025
I've been going down a rabbit hole, trying to figure out why some users were seeing unsaved changes upon rendering the SettingsView for the first time.

We've been dealing with this issue multiple times in the past, most recently in #354.

I'm of the opinion that at some point we should rework the SettingsView and especially how state is being managed inside of it. There's simply too many opportunity to run into these situations because individual components are in charge of defaults and fallbacks, which will always keep triggering unsaved changes upon first render. With this workaround I simply make sure that we get users out of the state that poisoned their settings state.
kevinvandijk pushed a commit that referenced this pull request May 21, 2025
…455)

* Fix: Workaround for detected changes in SettingsView upon rendering

I've been going down a rabbit hole, trying to figure out why some users were seeing unsaved changes upon rendering the SettingsView for the first time.

We've been dealing with this issue multiple times in the past, most recently in #354.

I'm of the opinion that at some point we should rework the SettingsView and especially how state is being managed inside of it. There's simply too many opportunity to run into these situations because individual components are in charge of defaults and fallbacks, which will always keep triggering unsaved changes upon first render. With this workaround I simply make sure that we get users out of the state that poisoned their settings state.

* Don't run in test env because tests are too fast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong model after login

3 participants