Recreate accent style tag if removed during page init
The <style id="umbra-accent"> tag injected by index.html gets removed during page initialization. useTheme now defensively recreates the tag if it's missing, ensuring color changes from the settings page work. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b202ee1a84
commit
f9359bd78a
@ -16,8 +16,8 @@ export function useTheme() {
|
|||||||
const { settings } = useSettings();
|
const { settings } = useSettings();
|
||||||
|
|
||||||
// Only apply accent color once settings have loaded from the API.
|
// Only apply accent color once settings have loaded from the API.
|
||||||
// Updates the <style id="umbra-accent"> tag injected by index.html.
|
// Creates or updates a <style id="umbra-accent"> tag with !important vars.
|
||||||
// Uses !important to beat @layer base defaults in the stylesheet.
|
// The tag may be removed during page init, so always recreate if missing.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!settings) return;
|
if (!settings) return;
|
||||||
|
|
||||||
@ -28,12 +28,15 @@ export function useTheme() {
|
|||||||
const h = preset.h.toString();
|
const h = preset.h.toString();
|
||||||
const s = `${preset.s}%`;
|
const s = `${preset.s}%`;
|
||||||
const l = `${preset.l}%`;
|
const l = `${preset.l}%`;
|
||||||
|
const css = `:root{--accent-h:${h} !important;--accent-s:${s} !important;--accent-l:${l} !important}`;
|
||||||
|
|
||||||
// Update the persistent <style> tag (inline style attr gets stripped)
|
let el = document.getElementById('umbra-accent');
|
||||||
const el = document.getElementById('umbra-accent');
|
if (!el) {
|
||||||
if (el) {
|
el = document.createElement('style');
|
||||||
el.textContent = `:root{--accent-h:${h} !important;--accent-s:${s} !important;--accent-l:${l} !important}`;
|
el.id = 'umbra-accent';
|
||||||
|
document.head.appendChild(el);
|
||||||
}
|
}
|
||||||
|
el.textContent = css;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
localStorage.setItem('umbra-accent-color', JSON.stringify({ h, s, l }));
|
localStorage.setItem('umbra-accent-color', JSON.stringify({ h, s, l }));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user