From d5ef69b612bfdd0716ba6ca160fc7f9c0c5444a9 Mon Sep 17 00:00:00 2001 From: Gauvain Date: Wed, 24 Jun 2026 22:53:48 +0200 Subject: [PATCH] fix(settings): apply the plugin (admin) default when a setting is unlocked A setting that was always locked then unlocked showed the app's hardcoded default instead of the plugin's configured default: the unlocked branch treated the persisted app default as a meaningful user value, so the plugin value was effectively dead code for any key with a non-empty app default. Keep the user's value only when it diverges from the app default; otherwise the plugin (admin) default wins over the hardcoded app default. Shared via useSettings, so mobile and TV are both fixed. --- utils/atoms/settings.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/utils/atoms/settings.ts b/utils/atoms/settings.ts index 2b8c7aca..a5752ba2 100644 --- a/utils/atoms/settings.ts +++ b/utils/atoms/settings.ts @@ -443,11 +443,6 @@ export const pluginSettingsAtom = atom( const hasMeaningfulSettingValue = (value: unknown) => value !== undefined && value !== null && value !== ""; -const getEffectiveSettingValue = ( - settings: Partial | null | undefined, - settingsKey: K, -) => settings?.[settingsKey] ?? defaultValues[settingsKey]; - export const useSettings = () => { const api = useAtomValue(apiAtom); const [_settings, setSettings] = useAtom(settingsAtom); @@ -546,13 +541,24 @@ export const useSettings = () => { // Normalize object-typed settings from plugin (plain primitive → { key, value }) value = normalizePluginValue(settingsKey, value); - const effectiveValue = getEffectiveSettingValue(_settings, settingsKey); + // When unlocked, keep the user's value only if they explicitly diverged + // from the app default. Otherwise the plugin value is the admin's + // default and must win over the hardcoded app default — e.g. a toggle + // that was always locked then unlocked should reflect the plugin + // default, not the app's `false`. Object-typed settings compare by + // reference, so their behaviour is unchanged. + const userValue = _settings?.[settingsKey]; + const userDiverged = + hasMeaningfulSettingValue(userValue) && + userValue !== defaultValues[settingsKey]; (acc as any)[settingsKey] = locked ? value - : hasMeaningfulSettingValue(effectiveValue) - ? effectiveValue - : value; + : userDiverged + ? userValue + : hasMeaningfulSettingValue(value) + ? value + : defaultValues[settingsKey]; } return acc; }, {});