Skip to content

Modern Docker Management, Designed for Everyone

fix: settings state only allows one setting to be updated

Kyle Mendell56ad326a3c7c
diff --git a/frontend/src/lib/hooks/use-settings-form.svelte.ts b/frontend/src/lib/hooks/use-settings-form.svelte.ts
index 72f3a4188..ad25f5bf0 100644
--- a/frontend/src/lib/hooks/use-settings-form.svelte.ts
+++ b/frontend/src/lib/hooks/use-settings-form.svelte.ts
@@ -18,9 +18,10 @@ type Options<T> = {
};
export class UseSettingsForm<T extends Record<string, { value: any; error: string | null }>> {
- #hasChanges = $state(false);
#isLoading = $state(false);
#formValues = $state<T | null>(null);
+ #saveFunction: (() => Promise<void> | void) | null = null;
+ #resetFunction: (() => void) | null = null;
private formState: SettingsFormState | undefined;
private getCurrentSettings: () => Record<string, any>;
@@ -39,32 +40,31 @@ export class UseSettingsForm<T extends Record<string, { value: any; error: strin
});
$effect(() => {
- // Access reactive state to trigger re-runs
- const currentFormValues = this.#formValues;
- if (!currentFormValues) {
- this.#hasChanges = false;
- return;
+ // Sync to external context (side effect)
+ if (this.formState) {
+ this.formState.hasChanges = this.hasChanges;
+ this.formState.isLoading = this.#isLoading;
+ if (this.#saveFunction) this.formState.saveFunction = this.#saveFunction;
+ if (this.#resetFunction) this.formState.resetFunction = this.#resetFunction;
}
+ });
+ }
- const settingsToCompare = this.getCurrentSettings();
- const keys = Object.keys(currentFormValues) as (keyof T)[];
-
- const hasChanges = keys.some((key) => {
- const input = currentFormValues[key];
- if (input && 'value' in input) {
- return input.value !== settingsToCompare[key as string];
- }
- return false;
- });
+ #hasChanges = $derived.by(() => {
+ const currentFormValues = this.#formValues;
+ if (!currentFormValues) return false;
- this.#hasChanges = hasChanges;
+ const settingsToCompare = this.getCurrentSettings();
+ const keys = Object.keys(currentFormValues) as (keyof T)[];
- if (this.formState) {
- this.formState.hasChanges = hasChanges;
- this.formState.isLoading = this.#isLoading;
+ return keys.some((key) => {
+ const input = currentFormValues[key];
+ if (input && 'value' in input) {
+ return input.value !== settingsToCompare[key as string];
}
+ return false;
});
- }
+ });
async updateSettings(updatedSettings: Partial<Settings>) {
const result = await tryCatch(settingsService.updateSettings(updatedSettings as any));
@@ -78,10 +78,8 @@ export class UseSettingsForm<T extends Record<string, { value: any; error: strin
}
registerFormActions(saveFunction: () => Promise<void> | void, resetFunction: () => void) {
- if (this.formState) {
- this.formState.saveFunction = saveFunction;
- this.formState.resetFunction = resetFunction;
- }
+ this.#saveFunction = saveFunction;
+ this.#resetFunction = resetFunction;
}
setLoading(loading: boolean) {
diff --git a/frontend/src/lib/utils/settings-form.util.ts b/frontend/src/lib/utils/settings-form.util.ts
index ea90a081b..b2e4cdb6a 100644
--- a/frontend/src/lib/utils/settings-form.util.ts
+++ b/frontend/src/lib/utils/settings-form.util.ts
@@ -76,6 +76,9 @@ export function createSettingsForm<T extends z.ZodType<any, any>>(config: Settin
onReset?.();
};
+ // Register actions immediately so they're available even if onMount doesn't run (e.g. during $derived recreation)
+ settingsForm.registerFormActions(onSubmit, resetForm);
+
const registerOnMount = () => {
settingsForm.registerFormActions(onSubmit, resetForm);
};
diff --git a/frontend/src/routes/(app)/settings/appearance/+page.svelte b/frontend/src/routes/(app)/settings/appearance/+page.svelte
index a24a9cda9..38a8ea8a0 100644
--- a/frontend/src/routes/(app)/settings/appearance/+page.svelte
+++ b/frontend/src/routes/(app)/settings/appearance/+page.svelte
@@ -1,6 +1,5 @@
<script lang="ts">
import { z } from 'zod/v4';
- import { onMount } from 'svelte';
import { toast } from 'svelte-sonner';
import NavigationSettingControl from '$lib/components/navigation-setting-control.svelte';
import NavigationModeSettingControl from '$lib/components/navigation-mode-setting-control.svelte';
@@ -41,7 +40,7 @@
// Sidebar context not available (mobile view)
}
- let { formInputs, registerOnMount } = $derived(
+ let { formInputs } = $derived(
createSettingsForm({
schema: formSchema,
currentSettings,
@@ -67,8 +66,6 @@
if (key === 'mode') resetNavigationVisibility();
toast.success(`Local override cleared for ${key.replace(/([A-Z])/g, ' $1').toLowerCase()}`);
}
-
- onMount(() => registerOnMount());
</script>
<SettingsPageLayout
diff --git a/frontend/src/routes/(app)/settings/docker/+page.svelte b/frontend/src/routes/(app)/settings/docker/+page.svelte
index 1547ded85..3d152703d 100644
--- a/frontend/src/routes/(app)/settings/docker/+page.svelte
+++ b/frontend/src/routes/(app)/settings/docker/+page.svelte
@@ -3,7 +3,6 @@
import * as Alert from '$lib/components/ui/alert';
import type { Settings } from '$lib/types/settings.type';
import { z } from 'zod/v4';
- import { onMount } from 'svelte';
import SelectWithLabel from '$lib/components/form/select-with-label.svelte';
import { m } from '$lib/paraglide/messages';
import TextInputWithLabel from '$lib/components/form/text-input-with-label.svelte';
@@ -72,7 +71,7 @@
let shellSelectValue = $state<string>(shellOptions.find((o) => o.value === currentSettings.defaultShell)?.value ?? 'custom');
- let { formInputs, registerOnMount } = $derived(
+ let { formInputs } = $derived(
createSettingsForm({
schema: formSchema,
currentSettings,
@@ -94,8 +93,6 @@
$formInputs.defaultShell.value = shellSelectValue;
}
});
-
- onMount(() => registerOnMount());
</script>
<SettingsPageLayout
diff --git a/frontend/src/routes/(app)/settings/general/+page.svelte b/frontend/src/routes/(app)/settings/general/+page.svelte
index 0f60ff408..cbda7c12e 100644
--- a/frontend/src/routes/(app)/settings/general/+page.svelte
+++ b/frontend/src/routes/(app)/settings/general/+page.svelte
@@ -1,6 +1,5 @@
<script lang="ts">
import { z } from 'zod/v4';
- import { onMount } from 'svelte';
import { m } from '$lib/paraglide/messages';
import TextInputWithLabel from '$lib/components/form/text-input-with-label.svelte';
import settingsStore from '$lib/stores/config-store';
@@ -21,7 +20,7 @@
environmentHealthInterval: z.number().int().min(1).max(60)
});
- let { formInputs, registerOnMount } = $derived(
+ let { formInputs } = $derived(
createSettingsForm({
schema: formSchema,
currentSettings,
@@ -29,8 +28,6 @@
successMessage: m.general_settings_saved()
})
);
-
- onMount(() => registerOnMount());
</script>
<SettingsPageLayout
diff --git a/frontend/src/routes/(app)/settings/notifications/+page.svelte b/frontend/src/routes/(app)/settings/notifications/+page.svelte
index 7a865701e..d576dbf54 100644
--- a/frontend/src/routes/(app)/settings/notifications/+page.svelte
+++ b/frontend/src/routes/(app)/settings/notifications/+page.svelte
@@ -4,7 +4,6 @@
import * as Tabs from '$lib/components/ui/tabs';
import * as Dialog from '$lib/components/ui/dialog';
import { ArcaneButton } from '$lib/components/arcane-button/index.js';
- import { Spinner } from '$lib/components/ui/spinner';
import { toast } from 'svelte-sonner';
import { getContext, onMount } from 'svelte';
import { z } from 'zod/v4';
@@ -43,7 +42,6 @@
}
let { data } = $props();
- let hasChanges = $state(false);
let isLoading = $state(false);
let isTesting = $state(false);
let showUnsavedDialog = $state(false);
@@ -175,9 +173,8 @@
let { inputs: formInputs, ...form } = $derived(createForm<typeof formSchema>(formSchema, currentSettings));
- const formHasChanges = $derived.by(
- () =>
- $formInputs.discordEnabled.value !== currentSettings.discordEnabled ||
+ const hasChanges = $derived(
+ $formInputs.discordEnabled.value !== currentSettings.discordEnabled ||
$formInputs.discordWebhookUrl.value !== currentSettings.discordWebhookUrl ||
$formInputs.discordUsername.value !== currentSettings.discordUsername ||
$formInputs.discordAvatarUrl.value !== currentSettings.discordAvatarUrl ||
@@ -200,10 +197,11 @@
);
$effect(() => {
- hasChanges = formHasChanges;
if (formState) {
formState.hasChanges = hasChanges;
formState.isLoading = isLoading;
+ formState.saveFunction = onSubmit;
+ formState.resetFunction = resetForm;
}
});
@@ -261,11 +259,6 @@
} catch (error) {
// Apprise not configured yet, keep defaults
}
-
- if (formState) {
- formState.saveFunction = onSubmit;
- formState.resetFunction = resetForm;
- }
});
async function onSubmit() {
@@ -381,7 +374,7 @@
}
async function testNotification(provider: 'discord' | 'email', testType: string = 'simple') {
- if (formHasChanges) {
+ if (hasChanges) {
pendingTestAction = () => executeTest(provider, testType);
showUnsavedDialog = true;
return;
@@ -402,7 +395,7 @@
}
}
async function testAppriseNotification() {
- if (formHasChanges) {
+ if (hasChanges) {
pendingTestAction = executeAppriseTest;
showUnsavedDialog = true;
return;
diff --git a/frontend/src/routes/(app)/settings/security/+page.svelte b/frontend/src/routes/(app)/settings/security/+page.svelte
index b9cbc76fb..ddad68799 100644
--- a/frontend/src/routes/(app)/settings/security/+page.svelte
+++ b/frontend/src/routes/(app)/settings/security/+page.svelte
@@ -1,7 +1,7 @@
<script lang="ts">
import * as AlertDialog from '$lib/components/ui/alert-dialog';
import { z } from 'zod/v4';
- import { onMount } from 'svelte';
+ import { getContext } from 'svelte';
import { ArcaneButton } from '$lib/components/arcane-button/index.js';
import { Input } from '$lib/components/ui/input';
import { Label } from '$lib/components/ui/label';
@@ -69,7 +69,7 @@
});
// Security page needs custom submit logic for OIDC client secret handling
- let { formInputs, form, settingsForm, registerOnMount } = $derived(
+ let { formInputs, form, settingsForm } = $derived(
createSettingsForm({
schema: formSchema,
currentSettings: formDefaults,
@@ -188,9 +188,14 @@
showMergeAccountsAlert = false;
}
- onMount(() => {
+ $effect(() => {
// Use custom submit/reset for security page
settingsForm.registerFormActions(customSubmit, customReset);
+ // Sync the custom hasSecurityChanges to the context
+ const formState = getContext('settingsFormState') as any;
+ if (formState) {
+ formState.hasChanges = hasSecurityChanges;
+ }
});
</script>