keep AI settings editor in sync with the config it just saved (#10503)

* fix: keep AI settings editor in sync with the config it just saved

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: skip the post-save reload and record why the saved config is cloned

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-08-04 11:11:48 +00:00
committed by GitHub
parent c57045dbb3
commit 6f0aa70ae1
3 changed files with 14 additions and 3 deletions
@@ -145,5 +145,8 @@
link="https://www.windmill.dev/docs/core_concepts/ai_generation"
promptScope="instance"
customSave={handleCustomSave}
onSave={(savedConfig) => {
initialConfig = savedConfig
}}
/>
{/if}
@@ -57,7 +57,7 @@
usesInstanceAiConfig?: boolean
instanceAiSummary?: InstanceAISummary
customSave?: (config: AIConfig) => Promise<void>
onSave?: (info?: GetCopilotSettingsStateResponse) => void | Promise<void>
onSave?: (savedConfig: AIConfig, info?: GetCopilotSettingsStateResponse) => void | Promise<void>
title?: string
description?: string
link?: string
@@ -332,7 +332,14 @@
sendUserToast('AI settings updated')
}
storeInitialState()
await onSave?.(settingsState)
// Hand the parent what was persisted: it owns `initialConfig`, and this component is
// destroyed on a settings tab switch, so a stale prop returns as editor state on remount
// and is written back by the next save. Clone it, since `providers` aliases our `$state`
// and the `lastLoadedConfigKey` guard would then track our own edits; pre-arm that guard
// so the prop update does not re-apply the config over what the editor now shows.
const savedConfig = clone(config)
lastLoadedConfigKey = JSON.stringify(savedConfig)
await onSave?.(savedConfig, settingsState)
}
async function onAiProviderChange(provider: AIProvider) {
@@ -2029,7 +2029,8 @@ export async function main(
{hasInstanceAiConfig}
{usesInstanceAiConfig}
{instanceAiSummary}
onSave={(copilotSettingsState) => {
onSave={(savedConfig, copilotSettingsState) => {
aiInitialConfig = savedConfig
if (!copilotSettingsState) {
return
}