Skip to content

Commit 01a0d43

Browse files
PeerRichdevin-ai-integration[bot]eunjae-lee
authored
feat: add conditional todesktop class to html element (#22985)
- Add applyToDesktopClass function to detect window.todesktop - Conditionally add 'todesktop' class to html element when ToDesktop environment is detected - Follow existing pattern used by applyTheme function for client-side script injection - Enable desktop-specific CSS styling that already exists in globals.css Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Eunjae Lee <hey@eunjae.dev>
1 parent 3133eb5 commit 01a0d43

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

apps/web/pages/_applyThemeForDocument.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,22 @@ export const applyTheme = function () {
5757
console.error("Error applying theme:", e);
5858
}
5959
};
60+
61+
// ToDesktop class application function - will be stringified and injected. So, it must not use anything from the closure
62+
export const applyToDesktopClass = function () {
63+
try {
64+
const onReady = () => {
65+
if (typeof window !== "undefined" && window.todesktop && document.documentElement) {
66+
document.documentElement.classList.add("todesktop");
67+
} else if (document.documentElement) {
68+
return;
69+
} else {
70+
requestAnimationFrame(onReady);
71+
}
72+
};
73+
74+
requestAnimationFrame(onReady);
75+
} catch (e) {
76+
console.error("Error applying todesktop class:", e);
77+
}
78+
};

apps/web/pages/_document.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Document, { Head, Html, Main, NextScript } from "next/document";
55

66
import { IS_PRODUCTION } from "@calcom/lib/constants";
77

8-
import { applyTheme } from "./_applyThemeForDocument";
8+
import { applyTheme, applyToDesktopClass } from "./_applyThemeForDocument";
99

1010
type Props = Record<string, unknown> & DocumentProps & { newLocale: string };
1111

@@ -50,6 +50,7 @@ class MyDocument extends Document<Props> {
5050
__html: `
5151
window.calNewLocale = "${newLocale}";
5252
(${applyTheme.toString()})();
53+
(${applyToDesktopClass.toString()})();
5354
`,
5455
}}
5556
/>

0 commit comments

Comments
 (0)