fix: apply wide layout state idempotently
This commit is contained in:
1 parent
1fad1cc8d4
commit
e475370a20
1 file changed
+10
-2
@@ -11,6 +11,14 @@ function loadInitialWide() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyWide(value) {
|
||||||
|
if (value) {
|
||||||
|
document.documentElement.setAttribute('data-wide-layout', 'true');
|
||||||
|
} else {
|
||||||
|
document.documentElement.removeAttribute('data-wide-layout');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let wide = $state(loadInitialWide());
|
let wide = $state(loadInitialWide());
|
||||||
|
|
||||||
export const layoutState = {
|
export const layoutState = {
|
||||||
@@ -21,7 +29,7 @@ export const layoutState = {
|
|||||||
wide = next;
|
wide = next;
|
||||||
if (!browser) return;
|
if (!browser) return;
|
||||||
|
|
||||||
document.documentElement.toggleAttribute('data-wide-layout', next);
|
applyWide(next);
|
||||||
try {
|
try {
|
||||||
localStorage.setItem(STORAGE_KEY, String(next));
|
localStorage.setItem(STORAGE_KEY, String(next));
|
||||||
} catch {
|
} catch {
|
||||||
@@ -33,4 +41,4 @@ export const layoutState = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (browser) document.documentElement.toggleAttribute('data-wide-layout', wide);
|
if (browser) applyWide(wide);
|
||||||
Reference in new issue
Block a user