From b20084be43f9112d4f03cf6d7ef79122dfd80230 Mon Sep 17 00:00:00 2001 From: Northword <44738481+northword@users.noreply.github.com> Date: Wed, 17 Dec 2025 12:06:18 +0800 Subject: [PATCH] Fix(Plugins): Prevent user preferences from being lost on plugin disable (#5646) When a Zotero plugin is disabled, user-modified preferences can be inadvertently reset to their default values. This occurs under specific conditions where a parent preference has not been user-modified, but a child preference within that branch *has* been modified. The root cause lies in the `Zotero.Plugins.clearDefaultPrefs` function. For preferences that do not have a user-set value (`!branch.prefHasUserValue(pref)`), it incorrectly calls `Services.prefs.getDefaultBranch('').deleteBranch(pref)`. While intended to clear unmodified defaults, `deleteBranch(pref)` operates on the *entire preference branch* starting with `pref`, inadvertently removing any user-modified sub-preferences as well. This commit changes the problematic line from `branch.deleteBranch(pref)` to `branch.clearUserPref(pref)`. `clearUserPref(pref)` correctly removes only the user-set value for the *specific* preference `pref`, leaving default values and any user-modified sub-preferences intact. This ensures that only truly unmodified default preferences are cleared, preserving user data for related sub-preferences. This fix prevents unintended loss of user settings when plugins are disabled. --- chrome/content/zotero/xpcom/plugins.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/plugins.js b/chrome/content/zotero/xpcom/plugins.js index 1f6c847256..3c0e59e0e4 100644 --- a/chrome/content/zotero/xpcom/plugins.js +++ b/chrome/content/zotero/xpcom/plugins.js @@ -389,7 +389,7 @@ Zotero.Plugins = new function () { var obj = { pref(pref, _value) { if (!branch.prefHasUserValue(pref)) { - branch.deleteBranch(pref); + branch.clearUserPref(pref); } } };