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 <noreply@anthropic.com>
This commit is contained in:
@@ -169,20 +169,6 @@ export function AdminSettingsForm({ config }: { config: Record<string, string> }
|
||||
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<string, string> }
|
||||
<CardTitle>{t('admin.security.title')}</CardTitle>
|
||||
<CardDescription>{t('admin.security.description')}</CardDescription>
|
||||
</CardHeader>
|
||||
<form action={handleSaveSecurity}>
|
||||
<form onSubmit={(e) => { e.preventDefault(); handleSaveSecurity(new FormData(e.currentTarget)) }}>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="flex items-center space-x-2">
|
||||
<Checkbox
|
||||
@@ -265,7 +251,7 @@ export function AdminSettingsForm({ config }: { config: Record<string, string> }
|
||||
<CardTitle>{t('admin.ai.title')}</CardTitle>
|
||||
<CardDescription>{t('admin.ai.description')}</CardDescription>
|
||||
</CardHeader>
|
||||
<form action={handleSaveAI}>
|
||||
<form onSubmit={(e) => { e.preventDefault(); handleSaveAI(new FormData(e.currentTarget)) }}>
|
||||
<CardContent className="space-y-6">
|
||||
<div className="space-y-4 p-4 border rounded-lg bg-primary/5 dark:bg-primary/10">
|
||||
<h3 className="text-base font-semibold flex items-center gap-2">
|
||||
@@ -561,7 +547,7 @@ export function AdminSettingsForm({ config }: { config: Record<string, string> }
|
||||
<CardTitle>{t('admin.smtp.title')}</CardTitle>
|
||||
<CardDescription>{t('admin.smtp.description')}</CardDescription>
|
||||
</CardHeader>
|
||||
<form action={handleSaveSMTP}>
|
||||
<form onSubmit={(e) => { e.preventDefault(); handleSaveSMTP(new FormData(e.currentTarget)) }}>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
|
||||
Reference in New Issue
Block a user