fix: theme flickering (#16903)

* fix: theme flickering

* finalise
This commit is contained in:
Benny Joo
2024-10-15 11:13:39 +01:00
committed by GitHub
parent 0b3b268eed
commit 4037367f8c
2 changed files with 38 additions and 1 deletions
@@ -202,6 +202,11 @@ const AppearanceView = ({
mutation.mutate({
appTheme: null,
});
if (values.appTheme === "light") {
document.body.classList.remove("dark");
} else if (values.appTheme === "dark") {
document.body.classList.remove("light");
}
}}>
<div className="border-subtle flex flex-col justify-between border-x px-6 py-8 sm:flex-row">
<ThemeLabel
+33 -1
View File
@@ -67,7 +67,39 @@ class MyDocument extends Document<Props> {
nonce={nonce}
id="newLocale"
dangerouslySetInnerHTML={{
__html: `window.calNewLocale = "${newLocale}";`,
__html: `
window.calNewLocale = "${newLocale}";
(function applyTheme() {
try {
const appTheme = localStorage.getItem('app-theme');
if (!appTheme) return;
let bookingTheme, username;
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key.startsWith('booking-theme:')) {
bookingTheme = localStorage.getItem(key);
username = key.split("booking-theme:")[1];
break;
}
}
const onReady = () => {
const isBookingPage = username && window.location.pathname.slice(1).startsWith(username);
if (document.body) {
document.body.classList.add(isBookingPage ? bookingTheme : appTheme);
} else {
requestAnimationFrame(onReady);
}
};
requestAnimationFrame(onReady);
} catch (e) {
console.error('Error applying theme:', e);
}
})();
`,
}}
/>
<link rel="apple-touch-icon" sizes="180x180" href="/api/logo?type=apple-touch-icon" />