From e16d29e91640735b54caf98d239b84d934e94fd5 Mon Sep 17 00:00:00 2001 From: Jeroen Reumkens Date: Mon, 28 Nov 2022 17:54:14 +0100 Subject: [PATCH] Added optional chaining to embed iframe using window object, where objects were potentially undefined. (#5727) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/embeds/embed-core/src/embed-iframe.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/embeds/embed-core/src/embed-iframe.ts b/packages/embeds/embed-core/src/embed-iframe.ts index 555926336e..5c8964bfc7 100644 --- a/packages/embeds/embed-core/src/embed-iframe.ts +++ b/packages/embeds/embed-core/src/embed-iframe.ts @@ -47,7 +47,7 @@ let isSafariBrowser = false; const isBrowser = typeof window !== "undefined"; if (isBrowser) { - window.CalEmbed = window.CalEmbed || {}; + window.CalEmbed = window?.CalEmbed || {}; window.CalEmbed.embedStore = embedStore; const ua = navigator.userAgent.toLowerCase(); isSafariBrowser = ua.includes("safari") && !ua.includes("chrome"); @@ -201,7 +201,7 @@ function getNamespace() { return embedStore.namespace; } if (isBrowser) { - const namespace = window.getEmbedNamespace(); + const namespace = window?.getEmbedNamespace?.() || null; embedStore.namespace = namespace; return namespace; } @@ -228,7 +228,7 @@ export const useIsEmbed = (embedSsr?: boolean) => { "Looks like you have iframed cal.com but not using Embed Snippet. Directly using an iframe isn't recommended." ); } - setIsEmbed(window.isEmbed()); + setIsEmbed(window?.isEmbed?.() || false); }, []); return isEmbed; }; @@ -254,7 +254,7 @@ export const methods = { // In case where parent gives instructions before CalComPlan is set. // This is easily possible as React takes time to initialize and render components where this variable is set. - if (!window.CalComPlan) { + if (!window?.CalComPlan) { return requestAnimationFrame(() => { style(uiConfig); }); @@ -364,10 +364,10 @@ function keepParentInformedAboutDimensionChanges() { } if (isBrowser) { - log("Embed SDK loaded", { isEmbed: window.isEmbed() }); + log("Embed SDK loaded", { isEmbed: window?.isEmbed?.() || false }); const url = new URL(document.URL); - embedStore.theme = (window.getEmbedTheme() || "auto") as UiConfig["theme"]; - if (url.searchParams.get("prerender") !== "true" && window.isEmbed()) { + embedStore.theme = (window?.getEmbedTheme?.() || "auto") as UiConfig["theme"]; + if (url.searchParams.get("prerender") !== "true" && window?.isEmbed?.()) { log("Initializing embed-iframe"); // HACK const pageStatus = window.CalComPageStatus;