From 497f3b40ddb74731e07b1eb1445e220d10a17080 Mon Sep 17 00:00:00 2001 From: Michael Barrett Date: Wed, 27 Sep 2023 08:18:21 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20issue=20with=20settings?= =?UTF-8?q?=20being=20marked=20as=20dirty=20when=20visibility=20is=20chang?= =?UTF-8?q?ed=20(#18370)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs https://github.com/TryGhost/Product/issues/3924 Settings were being marked as dirty when visibility was changed causing the confirm dialog to show when navigating away from the settings page. This change manually computes the dirtiness of the setting to ensure the visibility change is ignored --- ghost/admin/app/services/custom-theme-settings.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ghost/admin/app/services/custom-theme-settings.js b/ghost/admin/app/services/custom-theme-settings.js index 5008dc75f6..a99295eb45 100644 --- a/ghost/admin/app/services/custom-theme-settings.js +++ b/ghost/admin/app/services/custom-theme-settings.js @@ -100,6 +100,16 @@ export default class CustomThemeSettingsServices extends Service { updateSettingsVisibility() { this.settings.forEach((setting) => { setting.visible = this._isSettingVisible(setting); + + // Updating the setting visibility will cause the setting to be marked as dirty so + // we need to compute whether the setting is actually dirty and set the flag manually + const changedProperties = Object.keys(setting.changedAttributes()).filter(key => key !== 'visible'); + + setting.hasDirtyAttributes = false; + + if (changedProperties.length > 0) { + setting.hasDirtyAttributes = true; + } }); }