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.
This commit is contained in:
Northword 2025-12-17 12:06:18 +08:00 • committed by GitHub
parent 60ece63df4
commit b20084be43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -389,7 +389,7 @@ Zotero.Plugins = new function () {
var obj = {
pref(pref, _value) {
if (!branch.prefHasUserValue(pref)) {
branch.deleteBranch(pref);
branch.clearUserPref(pref);
}
}
};