From 6247aa4d8b94e867855eb5a199a1cd19301f78eb Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Tue, 23 Nov 2021 17:02:09 +0000 Subject: [PATCH] Added missing async/await calls - throughout the theme activation flow there are several missing awaits and necessary async keywords - we should be waiting on these processes, not letting them complete indeterministically --- core/bridge.js | 10 +++++----- core/server/services/themes/activation-bridge.js | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/bridge.js b/core/bridge.js index 442bcf2d5f..0fddd7b55b 100644 --- a/core/bridge.js +++ b/core/bridge.js @@ -50,7 +50,7 @@ class Bridge { return themeEngine.getActive(); } - activateTheme(loadedTheme, checkedTheme) { + async activateTheme(loadedTheme, checkedTheme) { let settings = { locale: settingsCache.get('lang') }; @@ -68,12 +68,12 @@ class Bridge { if (previousGhostAPI !== undefined && (previousGhostAPI !== currentGhostAPI)) { events.emit('services.themes.api.changed'); - this.reloadFrontend(); + await this.reloadFrontend(); } const cardAssetConfig = this.getCardAssetConfig(); debug('reload card assets config', cardAssetConfig); - cardAssetService.load(cardAssetConfig); + await cardAssetService.load(cardAssetConfig); } catch (err) { logging.error(new errors.InternalServerError({ message: tpl(messages.activateFailed, {theme: loadedTheme.name}), @@ -98,12 +98,12 @@ class Bridge { } } - reloadFrontend() { + async reloadFrontend() { const apiVersion = this.getFrontendApiVersion(); debug('reload frontend', apiVersion); const siteApp = require('./frontend/web/site'); - siteApp.reload({apiVersion}); + await siteApp.reload({apiVersion}); } } diff --git a/core/server/services/themes/activation-bridge.js b/core/server/services/themes/activation-bridge.js index d4d619885d..e67c5efd54 100644 --- a/core/server/services/themes/activation-bridge.js +++ b/core/server/services/themes/activation-bridge.js @@ -14,7 +14,7 @@ module.exports = { if (labs.isSet('customThemeSettings')) { await customThemeSettings.api.activateTheme(themeName, checkedTheme); } - bridge.activateTheme(theme, checkedTheme); + await bridge.activateTheme(theme, checkedTheme); }, activateFromAPI: async (themeName, theme, checkedTheme) => { debug('Activating theme (method B on API "activate")', themeName); @@ -22,7 +22,7 @@ module.exports = { if (labs.isSet('customThemeSettings')) { await customThemeSettings.api.activateTheme(themeName, checkedTheme); } - bridge.activateTheme(theme, checkedTheme); + await bridge.activateTheme(theme, checkedTheme); }, activateFromAPIOverride: async (themeName, theme, checkedTheme) => { debug('Activating theme (method C on API "override")', themeName); @@ -30,6 +30,6 @@ module.exports = { if (labs.isSet('customThemeSettings')) { await customThemeSettings.api.activateTheme(themeName, checkedTheme); } - bridge.activateTheme(theme, checkedTheme); + await bridge.activateTheme(theme, checkedTheme); } };