@@ -33,29 +33,21 @@ interface PackageSidebarProps {
3333
3434const PackageSidebar = ( { data, loading, error } : PackageSidebarProps ) => {
3535 const router = useRouter ( ) ;
36- const [ docsRelativeUrl , setDocsRelativeUrl ] = React . useState < string > ( "" ) ;
37- const [ docsLinkLabel , setDocsLinkLabel ] = React . useState < string > ( "" ) ;
36+ const docsRelativeUrl =
37+ data ?. docsIpfsUrl && data . name && data . version
38+ ? `/docs/${ encodeURIComponent ( data . name ) } /${ encodeURIComponent ( data . version ) } `
39+ : "" ;
3840
39- React . useEffect ( ( ) => {
40- if ( ! data ?. docsIpfsUrl ) {
41- setDocsRelativeUrl ( "" ) ;
42- setDocsLinkLabel ( "" ) ;
43- return ;
44- }
41+ const docsOrigin =
42+ ( typeof window !== "undefined" && window . location ?. origin ) ||
43+ process . env . NEXT_PUBLIC_APP_ORIGIN ||
44+ "" ;
4545
46- const relativePath = `/docs/${ encodeURIComponent ( data . name ) } /${ encodeURIComponent ( data . version ) } ` ;
47- setDocsRelativeUrl ( relativePath ) ;
48-
49- const configuredOrigin = process . env . NEXT_PUBLIC_APP_ORIGIN ?? "" ;
50-
51- if ( typeof window !== "undefined" && window . location ?. origin ) {
52- setDocsLinkLabel ( `${ window . location . origin } ${ relativePath } ` ) ;
53- } else if ( configuredOrigin ) {
54- setDocsLinkLabel ( `${ configuredOrigin } ${ relativePath } ` ) ;
55- } else {
56- setDocsLinkLabel ( relativePath ) ;
57- }
58- } , [ data ?. docsIpfsUrl , data ?. name , data ?. version ] ) ;
46+ const docsLinkLabel = docsRelativeUrl
47+ ? docsOrigin
48+ ? `${ docsOrigin } ${ docsRelativeUrl } `
49+ : docsRelativeUrl
50+ : "" ;
5951
6052 if ( loading ) {
6153 return (
0 commit comments