From feaa8dd8a9cffdde5c867e3e759e67919b1f77d3 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Mon, 1 Apr 2024 08:43:06 +0100 Subject: [PATCH] Theming API: Add `unstyled` check to decide whether theme can be loaded or not --- components/lib/basecomponent/BaseComponent.vue | 5 +++++ components/lib/basedirective/BaseDirective.js | 3 +++ 2 files changed, 8 insertions(+) diff --git a/components/lib/basecomponent/BaseComponent.vue b/components/lib/basecomponent/BaseComponent.vue index 4f3e01603..366346eb8 100644 --- a/components/lib/basecomponent/BaseComponent.vue +++ b/components/lib/basecomponent/BaseComponent.vue @@ -33,6 +33,9 @@ export default { if (!newValue) { BaseComponentStyle.loadStyle(this.$styleOptions); this.$options.style && this.$style.loadStyle(this.$styleOptions); + } else { + // load theme + this._loadThemeStyles(); } } } @@ -108,6 +111,8 @@ export default { ObjectUtils.isNotEmpty(globalCSS) && BaseStyle.loadStyle(globalCSS, { name: 'global', ...this.$styleOptions }); }, _loadThemeStyles() { + if (this.isUnstyled) return; + // common if (!Theme.isStyleNameLoaded('common')) { const { primitive, semantic, global } = this.$style?.getCommonThemeCSS?.() || {}; diff --git a/components/lib/basedirective/BaseDirective.js b/components/lib/basedirective/BaseDirective.js index 0c019d596..2de2d7a1f 100644 --- a/components/lib/basedirective/BaseDirective.js +++ b/components/lib/basedirective/BaseDirective.js @@ -84,6 +84,8 @@ const BaseDirective = { ThemeService.on('theme:change', () => BaseDirective._loadThemeStyles(el.$instance, { nonce: config?.csp?.nonce })); }, _loadThemeStyles: (instance = {}, useStyleOptions) => { + if (instance?.isUnstyled()) return; + // common if (!Theme.isStyleNameLoaded('common')) { const { primitive, semantic, global } = instance.$style?.getCommonThemeCSS?.() || {}; @@ -181,6 +183,7 @@ const BaseDirective = { handleHook('beforeUpdate', el, binding, vnode, prevVnode); }, updated: (el, binding, vnode, prevVnode) => { + BaseDirective._loadStyles(el, binding, vnode); handleHook('updated', el, binding, vnode, prevVnode); }, beforeUnmount: (el, binding, vnode, prevVnode) => {