From 0903597759c5becbd89088c5f67bf9f7bffa86c0 Mon Sep 17 00:00:00 2001 From: Sepehr Ramezani Date: Sun, 29 Mar 2026 12:34:28 +0200 Subject: [PATCH] fix(admin): prevent model selection reset by using onSubmit instead of form action Using form action in Next.js triggers automatic router cache revalidation, causing the server component to re-render and remount the client component, which resets all useState values. Switching to onSubmit with e.preventDefault() prevents this behavior while preserving full functionality. Co-Authored-By: Claude Opus 4.5 --- .../admin/settings/admin-settings-form.tsx | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/keep-notes/app/(main)/admin/settings/admin-settings-form.tsx b/keep-notes/app/(main)/admin/settings/admin-settings-form.tsx index 6be3eba..a8e09c7 100644 --- a/keep-notes/app/(main)/admin/settings/admin-settings-form.tsx +++ b/keep-notes/app/(main)/admin/settings/admin-settings-form.tsx @@ -169,20 +169,6 @@ export function AdminSettingsForm({ config }: { config: Record } toast.error(t('admin.ai.updateFailed') + ': ' + result.error) } else { toast.success(t('admin.ai.updateSuccess')) - setTagsProvider(tagsProv) - setEmbeddingsProvider(embedProv) - if (tagsModel) setSelectedTagsModel(tagsModel) - if (embedModel) setSelectedEmbeddingModel(embedModel) - - // Refresh models after save if Ollama is selected - if (tagsProv === 'ollama') { - const url = data.OLLAMA_BASE_URL_TAGS || config.OLLAMA_BASE_URL || 'http://localhost:11434' - fetchOllamaModels('tags', url) - } - if (embedProv === 'ollama') { - const url = data.OLLAMA_BASE_URL_EMBEDDING || config.OLLAMA_BASE_URL || 'http://localhost:11434' - fetchOllamaModels('embeddings', url) - } } } catch (error: any) { setIsSaving(false) @@ -235,7 +221,7 @@ export function AdminSettingsForm({ config }: { config: Record } {t('admin.security.title')} {t('admin.security.description')} -
+ { e.preventDefault(); handleSaveSecurity(new FormData(e.currentTarget)) }}>
} {t('admin.ai.title')} {t('admin.ai.description')} - + { e.preventDefault(); handleSaveAI(new FormData(e.currentTarget)) }}>

@@ -561,7 +547,7 @@ export function AdminSettingsForm({ config }: { config: Record } {t('admin.smtp.title')} {t('admin.smtp.description')} - + { e.preventDefault(); handleSaveSMTP(new FormData(e.currentTarget)) }}>