From 25b06577847ca98689648d8eecf55bec547b2bb5 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Mon, 4 Oct 2021 10:58:20 +0100 Subject: [PATCH] Fixed inconsistent theme settings state after toggling customThemeSettings labs flag no issue If Ghost was booted or a theme activated with the `customThemeSettings` flag disabled but with a theme that has custom settings, enabling the flag later on wouldn't show the settings in Admin or make the settings available in the front-end. Similarly, disabling `customThemeSettings` when Ghost had been booted/or theme activated with it enabled meant that settings were still available on the front-end. - added an event listener for `settings.labs.edited` that fully re-activates a theme so that it's passed through gscan again and the custom theme settings passed back are included/excluded based on the flag value and any required settings sync with the database is performed --- core/server/services/themes/index.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/server/services/themes/index.js b/core/server/services/themes/index.js index 9f7d20ae3a..49462aa421 100644 --- a/core/server/services/themes/index.js +++ b/core/server/services/themes/index.js @@ -6,6 +6,12 @@ const installer = require('./installer'); const settingsCache = require('../../../shared/settings-cache'); +// Needed for theme re-activation after customThemeSettings flag is toggled +// @TODO: remove when customThemeSettings flag is removed +const labs = require('../../../shared/labs'); +const events = require('../../lib/common/events'); +let _lastLabsValue; + module.exports = { /* * Load the currently active theme @@ -13,6 +19,21 @@ module.exports = { init: async () => { const themeName = settingsCache.get('active_theme'); + /** + * When customThemeSettings labs flag is toggled we need to re-validate and activate + * the active theme so that it's settings are read and synced + * + * @TODO: remove when customThemeSettings labs flag is removed + */ + _lastLabsValue = labs.isSet('customThemeSettings'); + events.on('settings.labs.edited', () => { + if (labs.isSet('customThemeSettings') !== _lastLabsValue) { + _lastLabsValue = labs.isSet('customThemeSettings'); + + activate.activate(settingsCache.get('active_theme')); + } + }); + return activate.loadAndActivate(themeName); }, /**