feat: replace window.todesktop with official @todesktop/client-core package (#23354)
* feat: replace window.todesktop with official @todesktop/client-core package - Import platform from @todesktop/client-core in _document.tsx - Pass isDesktopApp result via window.calIsDesktopApp to stringified function - Update applyToDesktopClass to use passed-in value instead of window.todesktop - Maintains existing architecture while using official package API Co-Authored-By: [email protected] <[email protected]> * fix: move ToDesktop detection to client-side to resolve SSR issue - Remove server-side call to platform.todesktop.isDesktopApp() which always returns false - Move detection logic to client-side stringified script using same logic as official package - Maintain client-side detection while ensuring proper functionality in ToDesktop environment Co-Authored-By: [email protected] <[email protected]> * feat: use official platform.todesktop.isDesktopApp() function - Import platform from @todesktop/client-core in _document.tsx - Call platform.todesktop.isDesktopApp() directly in stringified script - Replace duplicated logic with official package function call - Maintain client-side detection while using official API Co-Authored-By: [email protected] <[email protected]> * feat: properly use official platform.todesktop.isDesktopApp() function - Call platform.todesktop.isDesktopApp() outside stringified context - Pass result as template variable to avoid SSR issues - Now actually uses the official @todesktop/client-core package - Eliminates duplicated detection logic as requested Co-Authored-By: [email protected] <[email protected]> * fix: add SSR safety guards around platform.todesktop.isDesktopApp() call - Wrap platform.todesktop.isDesktopApp() in try/catch to prevent SSR crashes - Return false as fallback if library touches browser globals during SSR - Addresses keithwillcode's comment about SSR safety concerns Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
4 files changed
+75
-1
No files matched your search
@@ -76,6 +76,7 @@
|
||||
"@stripe/stripe-js": "^1.35.0",
|
||||
"@tanstack/react-query": "^5.17.15",
|
||||
"@team-plain/typescript-sdk": "^5.9.0",
|
||||
"@todesktop/client-core": "^1.20.0",
|
||||
"@types/turndown": "^5.0.1",
|
||||
"@upstash/redis": "^1.35.2",
|
||||
"@vercel/edge-config": "^0.1.1",
|
||||
|
||||
@@ -62,7 +62,7 @@ export const applyTheme = function () {
|
||||
export const applyToDesktopClass = function () {
|
||||
try {
|
||||
const onReady = () => {
|
||||
if (typeof window !== "undefined" && window.todesktop && document.documentElement) {
|
||||
if (typeof window !== "undefined" && window.calIsDesktopApp && document.documentElement) {
|
||||
document.documentElement.classList.add("todesktop");
|
||||
} else if (document.documentElement) {
|
||||
return;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { platform } from "@todesktop/client-core";
|
||||
import type { IncomingMessage } from "http";
|
||||
import { dir } from "i18next";
|
||||
import type { DocumentContext, DocumentProps } from "next/document";
|
||||
@@ -37,6 +38,14 @@ class MyDocument extends Document<Props> {
|
||||
const newLocale = this.props.newLocale || "en";
|
||||
const newDir = dir(newLocale);
|
||||
|
||||
const isDesktopApp = (() => {
|
||||
try {
|
||||
return platform.todesktop.isDesktopApp();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
|
||||
return (
|
||||
<Html
|
||||
lang={newLocale}
|
||||
@@ -49,6 +58,7 @@ class MyDocument extends Document<Props> {
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
window.calNewLocale = "${newLocale}";
|
||||
window.calIsDesktopApp = ${isDesktopApp};
|
||||
(${applyTheme.toString()})();
|
||||
(${applyToDesktopClass.toString()})();
|
||||
`,
|
||||
|
||||
Reference in new issue
Block a user