File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed
Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments