0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

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
This commit is contained in:
Kevin Ansfield 2021-10-21 15:02:42 +01:00
parent 39160fc794
commit 1708f0c3a4
3 changed files with 9 additions and 9 deletions

View file

@ -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;
};

View file

@ -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);
}

View file

@ -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!