Skip to content

Scheduling infrastructure for absolutely everyone.

Check embed in a better way (#7221)

Hariom Balharaa00003004045
diff --git a/apps/web/pages/_document.tsx b/apps/web/pages/_document.tsx
index cd0201dc549..2d92e21ddb3 100644
--- a/apps/web/pages/_document.tsx
+++ b/apps/web/pages/_document.tsx
@@ -18,7 +18,10 @@ class MyDocument extends Document<Props> {
// If x-csp not set by gSSP, then it's initialPropsOnly
ctx.res?.setHeader("x-csp", "initialPropsOnly");
}
- const isEmbed = ctx.asPath?.includes("/embed") || ctx.asPath?.includes("embedType=");
+ const asPath = ctx.asPath || "";
+ // Use a dummy URL as default so that URL parsing works for relative URLs as well. We care about searchParams and pathname only
+ const parsedUrl = new URL(asPath, "https://dummyurl");
+ const isEmbed = parsedUrl.pathname.endsWith("/embed") || parsedUrl.searchParams.get("embedType") !== null;
const initialProps = await Document.getInitialProps(ctx);
return { isEmbed, nonce, ...initialProps };
}