From 9122f68dd44b4ac128a3bea5b26fb632b02aeb03 Mon Sep 17 00:00:00 2001 From: Tam Nhu Tran Date: Sat, 25 Apr 2026 11:45:51 -0400 Subject: [PATCH] fix(ui/profiles): preserve ANTHROPIC_EXTRA_MODELS on untouched edit-dialog save The edit dialog cannot pre-populate `extraModels` from the existing profile (the Profile type carries no env data), so the field always opens blank in edit mode. Forwarding that blank value unconditionally clobbered any saved ANTHROPIC_EXTRA_MODELS, since the PUT route treats an empty string as a delete signal. Track react-hook-form's `dirtyFields.extraModels` and only include the field in the update payload when the user actually touched it. Typing then clearing still marks the field dirty, so the explicit-clear UX keeps working. --- ui/src/components/profiles/profile-dialog.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ui/src/components/profiles/profile-dialog.tsx b/ui/src/components/profiles/profile-dialog.tsx index d16caf27..9331bda5 100644 --- a/ui/src/components/profiles/profile-dialog.tsx +++ b/ui/src/components/profiles/profile-dialog.tsx @@ -57,7 +57,7 @@ export function ProfileDialog({ open, onClose, profile }: ProfileDialogProps) { const { register, handleSubmit, - formState: { errors }, + formState: { errors, dirtyFields }, reset, control, } = useForm({ @@ -97,14 +97,20 @@ export function ProfileDialog({ open, onClose, profile }: ProfileDialogProps) { const onSubmit = async (data: FormData) => { try { if (profile) { - // Update mode + // Update mode. The dialog cannot pre-populate `extraModels` from the + // existing profile (Profile type carries no env data), so the field + // always starts blank in edit mode. Forwarding that blank value + // unconditionally would clobber any saved ANTHROPIC_EXTRA_MODELS via + // the route's "empty string deletes" semantics. Only forward the + // field if the user actually edited it — typing then clearing still + // marks it dirty, preserving the explicit-clear UX. await updateMutation.mutateAsync({ name: profile.name, data: { baseUrl: data.baseUrl, apiKey: data.apiKey, model: data.model, - extraModels: data.extraModels, + ...(dirtyFields.extraModels ? { extraModels: data.extraModels } : {}), opusModel: data.opusModel, sonnetModel: data.sonnetModel, haikuModel: data.haikuModel,