diff --git a/web/core/components/pages/editor/editor-body.tsx b/web/core/components/pages/editor/editor-body.tsx index 99b261e79c6..c4efaac7bfe 100644 --- a/web/core/components/pages/editor/editor-body.tsx +++ b/web/core/components/pages/editor/editor-body.tsx @@ -18,7 +18,7 @@ import { IUserLite } from "@plane/types"; import { Row } from "@plane/ui"; import { PageContentBrowser, PageContentLoader, PageEditorTitle } from "@/components/pages"; // helpers -import { cn, LIVE_URL } from "@/helpers/common.helper"; +import { cn, LIVE_BASE_PATH, LIVE_BASE_URL } from "@/helpers/common.helper"; import { generateRandomColor } from "@/helpers/string.helper"; // hooks import { useMember, useMention, useUser, useWorkspace } from "@/hooks/store"; @@ -112,24 +112,30 @@ export const PageEditorBody: React.FC = observer((props) => { [] ); - const realtimeConfig: TRealtimeConfig = useMemo(() => { + const realtimeConfig: TRealtimeConfig | undefined = useMemo(() => { // Construct the WebSocket Collaboration URL - const WS_LIVE_URL = new URL(LIVE_URL); - const isSecureEnvironment = window.location.protocol === "https:"; - WS_LIVE_URL.protocol = isSecureEnvironment ? "wss" : "ws"; - WS_LIVE_URL.pathname = "collaboration"; - - return { - url: WS_LIVE_URL.toString(), - queryParams: { - workspaceSlug: workspaceSlug?.toString(), - projectId: projectId?.toString(), - documentType: "project_page", - }, - }; + try { + const LIVE_SERVER_BASE_URL = LIVE_BASE_URL ?? window.location.origin; + const WS_LIVE_URL = new URL(`${LIVE_SERVER_BASE_URL}${LIVE_BASE_PATH}`); + const isSecureEnvironment = window.location.protocol === "https:"; + WS_LIVE_URL.protocol = isSecureEnvironment ? "wss" : "ws"; + WS_LIVE_URL.pathname = "collaboration"; + // Construct realtime config + return { + url: WS_LIVE_URL.toString(), + queryParams: { + workspaceSlug: workspaceSlug?.toString(), + projectId: projectId?.toString(), + documentType: "project_page", + }, + }; + } catch (error) { + console.error("Error creating realtime config", error); + return undefined; + } }, [projectId, workspaceSlug]); - if (pageId === undefined) return ; + if (pageId === undefined || !realtimeConfig) return ; return (
diff --git a/web/helpers/common.helper.ts b/web/helpers/common.helper.ts index 5113322166e..144c8968325 100644 --- a/web/helpers/common.helper.ts +++ b/web/helpers/common.helper.ts @@ -9,7 +9,7 @@ export const ADMIN_BASE_PATH = process.env.NEXT_PUBLIC_ADMIN_BASE_PATH || ""; export const SPACE_BASE_URL = process.env.NEXT_PUBLIC_SPACE_BASE_URL || ""; export const SPACE_BASE_PATH = process.env.NEXT_PUBLIC_SPACE_BASE_PATH || ""; -const LIVE_BASE_URL = process.env.NEXT_PUBLIC_LIVE_BASE_URL || ""; +export const LIVE_BASE_URL = process.env.NEXT_PUBLIC_LIVE_BASE_URL || ""; export const LIVE_BASE_PATH = process.env.NEXT_PUBLIC_LIVE_BASE_PATH || ""; export const LIVE_URL = `${LIVE_BASE_URL}${LIVE_BASE_PATH}`;