From 1708f0c3a4f370742ac88e31d44fc918c05710a3 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 21 Oct 2021 15:02:42 +0100 Subject: [PATCH] Fixed custom theme settings not being available when expected closes https://github.com/TryGhost/Team/issues/1172 Custom theme settings sync and cache population had been left to complete in the background as it wasn't essential for it to be complete for the front-end to start. However that was causing problems for the API where theme activation and custom theme settings list requests happen very close together, with the latter often not containing the theme settings data when it is expected to. - changed `activationBridge.*` methods to `async` so they can `await` the completion of custom theme settings sync before activating a theme --- core/server/services/themes/activate.js | 4 ++-- core/server/services/themes/activation-bridge.js | 12 ++++++------ core/server/services/themes/storage.js | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/server/services/themes/activate.js b/core/server/services/themes/activate.js index 5dc54a794c..5528a2fd46 100644 --- a/core/server/services/themes/activate.js +++ b/core/server/services/themes/activate.js @@ -30,7 +30,7 @@ module.exports.loadAndActivate = async (themeName) => { logging.warn(validate.getThemeValidationError('activeThemeHasErrors', themeName, checkedTheme)); } - activator.activateFromBoot(themeName, loadedTheme, checkedTheme); + await activator.activateFromBoot(themeName, loadedTheme, checkedTheme); } catch (err) { if (err instanceof errors.NotFoundError) { // CASE: active theme is missing, we don't want to exit because the admin panel will still work @@ -56,7 +56,7 @@ module.exports.activate = async (themeName) => { // Validate const checkedTheme = await validate.checkSafe(themeName, loadedTheme); // Activate - activator.activateFromAPI(themeName, loadedTheme, checkedTheme); + await activator.activateFromAPI(themeName, loadedTheme, checkedTheme); // Return the checked theme return checkedTheme; }; diff --git a/core/server/services/themes/activation-bridge.js b/core/server/services/themes/activation-bridge.js index 11ae73d185..d4d619885d 100644 --- a/core/server/services/themes/activation-bridge.js +++ b/core/server/services/themes/activation-bridge.js @@ -8,27 +8,27 @@ const customThemeSettings = require('../custom-theme-settings'); * And also adds a little debug statement, which is very handy when debugging theme logic */ module.exports = { - activateFromBoot: (themeName, theme, checkedTheme) => { + activateFromBoot: async (themeName, theme, checkedTheme) => { debug('Activating theme (method A on boot)', themeName); // TODO: probably a better place for this to happen - after successful activation / when reloading site? if (labs.isSet('customThemeSettings')) { - customThemeSettings.api.activateTheme(themeName, checkedTheme); + await customThemeSettings.api.activateTheme(themeName, checkedTheme); } bridge.activateTheme(theme, checkedTheme); }, - activateFromAPI: (themeName, theme, checkedTheme) => { + activateFromAPI: async (themeName, theme, checkedTheme) => { debug('Activating theme (method B on API "activate")', themeName); // TODO: probably a better place for this to happen - after successful activation / when reloading site? if (labs.isSet('customThemeSettings')) { - customThemeSettings.api.activateTheme(themeName, checkedTheme); + await customThemeSettings.api.activateTheme(themeName, checkedTheme); } bridge.activateTheme(theme, checkedTheme); }, - activateFromAPIOverride: (themeName, theme, checkedTheme) => { + activateFromAPIOverride: async (themeName, theme, checkedTheme) => { debug('Activating theme (method C on API "override")', themeName); // TODO: probably a better place for this to happen - after successful activation / when reloading site? if (labs.isSet('customThemeSettings')) { - customThemeSettings.api.activateTheme(themeName, checkedTheme); + await customThemeSettings.api.activateTheme(themeName, checkedTheme); } bridge.activateTheme(theme, checkedTheme); } diff --git a/core/server/services/themes/storage.js b/core/server/services/themes/storage.js index 909cdfa2b8..a190ad2edb 100644 --- a/core/server/services/themes/storage.js +++ b/core/server/services/themes/storage.js @@ -83,7 +83,7 @@ module.exports = { // CASE: if this is the active theme, we are overriding if (overrideTheme) { debug('setFromZip Theme is active already'); - activator.activateFromAPIOverride(themeName, loadedTheme, checkedTheme); + await activator.activateFromAPIOverride(themeName, loadedTheme, checkedTheme); } // @TODO: unify the name across gscan and Ghost!