diff --git a/app.vue b/app.vue index a2f5c7296..ad2d11159 100644 --- a/app.vue +++ b/app.vue @@ -22,13 +22,11 @@ export default { }, mounted() { this.themeChangeListener = (event) => { - if (event.theme !== this.$appState.theme) { - this.$primevue.changeTheme(this.$appState.theme, event.theme, 'theme-link', () => { - this.$appState.theme = event.theme; - this.$appState.darkTheme = event.dark; - EventBus.emit('theme-change-complete', { theme: event.theme, dark: event.dark }); - }); - } + this.$primevue.changeTheme(this.$appState.theme, event.theme, 'theme-link', () => { + this.$appState.theme = event.theme; + this.$appState.darkTheme = event.dark; + EventBus.emit('theme-change-complete', { theme: event.theme, dark: event.dark }); + }); }; EventBus.on('theme-change', this.themeChangeListener); diff --git a/components/lib/config/PrimeVue.js b/components/lib/config/PrimeVue.js index 5ed983652..6d1f29504 100644 --- a/components/lib/config/PrimeVue.js +++ b/components/lib/config/PrimeVue.js @@ -157,21 +157,23 @@ export function usePrimeVue() { } function switchTheme(currentTheme, newTheme, linkElementId, callback) { - const linkElement = document.getElementById(linkElementId); - const cloneLinkElement = linkElement.cloneNode(true); - const newThemeUrl = linkElement.getAttribute('href').replace(currentTheme, newTheme); - - cloneLinkElement.setAttribute('id', linkElementId + '-clone'); - cloneLinkElement.setAttribute('href', newThemeUrl); - cloneLinkElement.addEventListener('load', () => { - linkElement.remove(); - cloneLinkElement.setAttribute('id', linkElementId); - - if (callback) { - callback(); - } - }); - linkElement.parentNode && linkElement.parentNode.insertBefore(cloneLinkElement, linkElement.nextSibling); + if (currentTheme !== newTheme) { + const linkElement = document.getElementById(linkElementId); + const cloneLinkElement = linkElement.cloneNode(true); + const newThemeUrl = linkElement.getAttribute('href').replace(currentTheme, newTheme); + + cloneLinkElement.setAttribute('id', linkElementId + '-clone'); + cloneLinkElement.setAttribute('href', newThemeUrl); + cloneLinkElement.addEventListener('load', () => { + linkElement.remove(); + cloneLinkElement.setAttribute('id', linkElementId); + + if (callback) { + callback(); + } + }); + linkElement.parentNode && linkElement.parentNode.insertBefore(cloneLinkElement, linkElement.nextSibling); + } } export default {