Skip to content

Commit ef02e52

Browse files
Fix SSR
1 parent 41eee4c commit ef02e52

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed

src/shared/components/Header/index.jsx

+40-25
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@ import _ from 'lodash';
22
import React, { useState } from 'react';
33
import PT from 'prop-types';
44
import { config } from 'topcoder-react-utils';
5-
import { TopNav, LoginNav } from 'navigation-component';
65
import Logo from 'assets/images/tc-logo.svg';
76

7+
let TopNavRef;
8+
let LoginNavRef;
9+
10+
try {
11+
// eslint-disable-next-line global-require
12+
const { TopNav, LoginNav } = require('navigation-component');
13+
TopNavRef = TopNav;
14+
LoginNavRef = LoginNav;
15+
} catch (e) {
16+
// window is undefined
17+
}
18+
819
const Header = ({ profile }) => {
920
const [activeLevel1Id, setActiveLevel1Id] = useState();
1021

@@ -24,30 +35,34 @@ const Header = ({ profile }) => {
2435
normalizedProfile = null;
2536
}
2637

27-
return (
28-
<div>
29-
<TopNav
30-
menu={config.HEADER_MENU}
31-
rightMenu={(
32-
<LoginNav
33-
loggedIn={!_.isEmpty(profile)}
34-
notificationButtonState="none"
35-
notifications={[]}
36-
accountMenu={config.ACCOUNT_MENU}
37-
switchText={config.ACCOUNT_MENU_SWITCH_TEXT}
38-
onSwitch={handleSwitchMenu}
39-
showNotification={false}
40-
profile={normalizedProfile}
41-
authURLs={config.HEADER_AUTH_URLS}
42-
/>
43-
)}
44-
logo={<Logo />}
45-
theme={config.HEADER_MENU_THEME}
46-
currentLevel1Id={activeLevel1Id}
47-
onChangeLevel1Id={handleChangeLevel1Id}
48-
/>
49-
</div>
50-
);
38+
if (TopNavRef) {
39+
return (
40+
<div>
41+
<TopNavRef
42+
menu={config.HEADER_MENU}
43+
rightMenu={(
44+
<LoginNavRef
45+
loggedIn={!_.isEmpty(profile)}
46+
notificationButtonState="none"
47+
notifications={[]}
48+
accountMenu={config.ACCOUNT_MENU}
49+
switchText={config.ACCOUNT_MENU_SWITCH_TEXT}
50+
onSwitch={handleSwitchMenu}
51+
showNotification={false}
52+
profile={normalizedProfile}
53+
authURLs={config.HEADER_AUTH_URLS}
54+
/>
55+
)}
56+
logo={<Logo />}
57+
theme={config.HEADER_MENU_THEME}
58+
currentLevel1Id={activeLevel1Id}
59+
onChangeLevel1Id={handleChangeLevel1Id}
60+
/>
61+
</div>
62+
);
63+
}
64+
65+
return (<div />);
5166
};
5267

5368
Header.defaultProps = {

0 commit comments

Comments
 (0)