Ghost/core/server/services/themes/activation-bridge.js
Kevin Ansfield 1708f0c3a4 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
2021-10-21 15:02:52 +01:00

36 lines
1.7 KiB
JavaScript

const debug = require('@tryghost/debug')('themes');
const bridge = require('../../../bridge');
const labs = require('../../../shared/labs');
const customThemeSettings = require('../custom-theme-settings');
/**
* These helper methods mean that the bridge is only required in one place
* And also adds a little debug statement, which is very handy when debugging theme logic
*/
module.exports = {
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')) {
await customThemeSettings.api.activateTheme(themeName, checkedTheme);
}
bridge.activateTheme(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')) {
await customThemeSettings.api.activateTheme(themeName, checkedTheme);
}
bridge.activateTheme(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')) {
await customThemeSettings.api.activateTheme(themeName, checkedTheme);
}
bridge.activateTheme(theme, checkedTheme);
}
};