From b72c48c69355b1c1badf70d8ea6ad1c7600a3b6c Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Mon, 8 Sep 2025 02:56:01 -0700 Subject: [PATCH] Mobile, Desktop: Fixes #13103: Fix error when saving in-editor rendering-related settings (#13105) --- packages/lib/models/Setting.test.ts | 7 +++++++ packages/lib/models/Setting.ts | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/lib/models/Setting.test.ts b/packages/lib/models/Setting.test.ts index 32c51cc0c2..e6aa9f03ab 100644 --- a/packages/lib/models/Setting.test.ts +++ b/packages/lib/models/Setting.test.ts @@ -522,6 +522,13 @@ describe('models/Setting', () => { expect(Setting.value('revisionService.ttlDays')).toBe(1); }); + test('should not fail to save settings that can conflict with uninstalled plugin settings', async () => { + Setting.setValue('editor.imageRendering', true); + expect(Setting.value('editor.imageRendering')).toBe(true); + Setting.setValue('editor.imageRendering', false); + expect(Setting.value('editor.imageRendering')).toBe(false); + }); + test('should adjust settings to avoid conflicts', async () => { const testSettingId = 'plugin-plugin.calebjohn.rich-markdown.inlineImages'; await Setting.registerSetting(testSettingId, { diff --git a/packages/lib/models/Setting.ts b/packages/lib/models/Setting.ts index 2ad2d0691d..df2a39e87a 100644 --- a/packages/lib/models/Setting.ts +++ b/packages/lib/models/Setting.ts @@ -808,15 +808,20 @@ class Setting extends BaseModel { this.scheduleChangeEvent(); }; + const setValueInternalIfExists = (key: Key, value: SettingValueType) => { + if (!this.keyExists(key)) return; + setValueInternal(key, value); + }; + setValueInternal(key, value); // Prevent conflicts. Use setValueInternal to avoid infinite recursion in the case // where conflictingSettings has invalid data. for (const conflict of conflictingSettings) { if (conflict.key1 === key && conflict.value1 === value) { - setValueInternal(conflict.key2, conflict.alternate2); + setValueInternalIfExists(conflict.key2, conflict.alternate2); } else if (conflict.key2 === key && conflict.value2 === value) { - setValueInternal(conflict.key1, conflict.alternate1); + setValueInternalIfExists(conflict.key1, conflict.alternate1); } } }