Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

Fix flash of wrong theme on initial UI load (#485)

FjellOverflowa6b25f7a1c24
diff --git a/frontend/nuxt.config.ts b/frontend/nuxt.config.ts
index 656ced40..3eb3fbd7 100644
--- a/frontend/nuxt.config.ts
+++ b/frontend/nuxt.config.ts
@@ -20,6 +20,12 @@ export default defineNuxtConfig({
},
},
+ app: {
+ head: {
+ script: [{ src: "/set-theme.js" }],
+ },
+ },
+
css: ["@/assets/css/main.css"],
pwa: {
diff --git a/frontend/public/set-theme.js b/frontend/public/set-theme.js
new file mode 100644
index 00000000..7ea5ebbc
--- /dev/null
+++ b/frontend/public/set-theme.js
@@ -0,0 +1,9 @@
+try {
+ console.log('Setting theme');
+ const theme = JSON.parse(
+ localStorage.getItem('homebox/preferences/location')
+ ).theme;
+ if (theme) document.documentElement.setAttribute('data-theme', theme);
+} catch (e) {
+ console.error('Failed to set theme', e);
+}