Skip to content

Commit a000030

Browse files
Check embed in a better way (#7221)
1 parent 44864a8 commit a000030

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

apps/web/pages/_document.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ class MyDocument extends Document<Props> {
1818
// If x-csp not set by gSSP, then it's initialPropsOnly
1919
ctx.res?.setHeader("x-csp", "initialPropsOnly");
2020
}
21-
const isEmbed = ctx.asPath?.includes("/embed") || ctx.asPath?.includes("embedType=");
21+
const asPath = ctx.asPath || "";
22+
// Use a dummy URL as default so that URL parsing works for relative URLs as well. We care about searchParams and pathname only
23+
const parsedUrl = new URL(asPath, "https://dummyurl");
24+
const isEmbed = parsedUrl.pathname.endsWith("/embed") || parsedUrl.searchParams.get("embedType") !== null;
2225
const initialProps = await Document.getInitialProps(ctx);
2326
return { isEmbed, nonce, ...initialProps };
2427
}

0 commit comments

Comments
 (0)