Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

πŸ› Fixes theme stylesheet leaking between pages

Alicia Sykes54a62df44b52
diff --git a/src/App.vue b/src/App.vue
index a3f409a2..f6b8f203 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -61,10 +61,13 @@ export default {
immediate: true,
handler(t) { applyTheme(t, this.appConfig); },
},
- /* Apply custom CSS and stylesheets, and re-apply on page change for sub-pages */
+ /* Apply custom CSS, stylesheets and theme, and re-apply on page change for sub-pages */
'$store.state.currentConfigInfo.confId': {
immediate: true,
- handler() { applyPageStyles(this.appConfig); },
+ handler() {
+ applyPageStyles(this.appConfig);
+ applyTheme(this.effectiveTheme, this.appConfig);
+ },
},
/* Keep i18n in sync with the active page's language (incl. sub-page overrides) */
'appConfig.language': {
diff --git a/src/utils/Theming.js b/src/utils/Theming.js
index 71dae912..ee9d62c0 100644
--- a/src/utils/Theming.js
+++ b/src/utils/Theming.js
@@ -82,6 +82,7 @@ const resetDom = () => {
};
const applyRemote = (href) => {
+ if (document.getElementById(EXTERNAL_STYLE_ID)?.getAttribute('href') === href) return;
resetDom();
const link = document.createElement('link');
link.rel = 'stylesheet';
diff --git a/tests/unit/theming.test.js b/tests/unit/theming.test.js
index 95f30a00..55efd320 100644
--- a/tests/unit/theming.test.js
+++ b/tests/unit/theming.test.js
@@ -1,7 +1,9 @@
import {
describe, it, expect, beforeAll, beforeEach, vi,
} from 'vitest';
-import { applyCustomCss, applyPageStyles, loadExternalStyleSheets } from '@/utils/Theming';
+import {
+ applyCustomCss, applyPageStyles, applyTheme, loadExternalStyleSheets,
+} from '@/utils/Theming';
import ErrorHandler from '@/utils/logging/ErrorHandler';
vi.mock('@/utils/logging/ErrorHandler', () => ({ default: vi.fn() }));
@@ -112,3 +114,17 @@ describe('Theming - applyPageStyles', () => {
expect(hrefs()).toEqual([]);
});
});
+
+describe('Theming - applyTheme', () => {
+ const themeLink = () => document.getElementById('user-defined-stylesheet');
+
+ it('keeps the external theme link when its URL is unchanged, and swaps it when it changes', () => {
+ applyTheme('External Stylesheet', { externalStyleSheet: '/a.css' });
+ const first = themeLink();
+ applyTheme('External Stylesheet', { externalStyleSheet: '/a.css' });
+ expect(themeLink()).toBe(first);
+ applyTheme('External Stylesheet', { externalStyleSheet: '/b.css' });
+ expect(themeLink().getAttribute('href')).toBe('/b.css');
+ expect(document.querySelectorAll('#user-defined-stylesheet')).toHaveLength(1);
+ });
+});