Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: apply react strict mode and upgrade to React 17 [DET-5325] #2279

Merged
merged 5 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 11 additions & 40 deletions webui/react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions webui/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"portable-fetch": "^3.0.0",
apizzini marked this conversation as resolved.
Show resolved Hide resolved
"pretty-bytes": "^5.4.1",
"query-string": "^6.13.5",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-helmet": "^6.1.0",
apizzini marked this conversation as resolved.
Show resolved Hide resolved
"react": "^17.0.2",
apizzini marked this conversation as resolved.
Show resolved Hide resolved
"react-dom": "^17.0.2",
apizzini marked this conversation as resolved.
Show resolved Hide resolved
"react-helmet-async": "^1.0.9",
"react-monaco-editor": "^0.37.0",
"react-router-dom": "^5.2.0",
"react-scripts": "^4.0.3",
Expand Down Expand Up @@ -82,7 +82,6 @@
"@types/plotly.js": "^1.50.21",
"@types/react": "^16.9.52",
"@types/react-dom": "^16.9.8",
"@types/react-helmet": "^6.1.0",
apizzini marked this conversation as resolved.
Show resolved Hide resolved
"@types/react-router-dom": "^5.1.6",
"@types/react-transition-group": "^4.4.0",
"@types/resize-observer-browser": "^0.1.4",
Expand Down
9 changes: 6 additions & 3 deletions webui/react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Button, notification } from 'antd';
import React, { useEffect, useLayoutEffect, useState } from 'react';
import { HelmetProvider } from 'react-helmet-async';

import { setupAnalytics } from 'Analytics';
import Link from 'components/Link';
Expand Down Expand Up @@ -74,9 +75,11 @@ const AppView: React.FC = () => {

const App: React.FC = () => {
return (
<StoreProvider>
<AppView />
</StoreProvider>
<HelmetProvider>
<StoreProvider>
<AppView />
</StoreProvider>
</HelmetProvider>
);
};

Expand Down
3 changes: 2 additions & 1 deletion webui/react/src/components/LogViewer.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, { useEffect, useRef } from 'react';

import HelmetDecorator from 'storybook/HelmetDecorator';
import StoreDecorator from 'storybook/StoreDecorator';
import { downloadText, simulateLogsDownload } from 'utils/browser';

import LogViewer, { LogViewerHandles } from './LogViewer';

export default {
component: LogViewer,
decorators: [ StoreDecorator ],
decorators: [ HelmetDecorator, StoreDecorator ],
parameters: { layout: 'fullscreen' },
title: 'LogViewer',
};
Expand Down
7 changes: 5 additions & 2 deletions webui/react/src/components/NavigationSideBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Menu, Tooltip } from 'antd';
import React, { useCallback, useEffect, useState } from 'react';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { useLocation } from 'react-router-dom';
import { CSSTransition } from 'react-transition-group';

Expand Down Expand Up @@ -49,6 +49,8 @@ const NavigationItem: React.FC<ItemProps> = ({ path, status, ...props }: ItemPro
const STORAGE_KEY = 'collapsed';

const NavigationSideBar: React.FC = () => {
// `nodeRef` padding is required for CSSTransition to work with React.StrictMode.
const nodeRef = useRef(null);
const { auth, cluster: overview, ui } = useStore();
const storeDispatch = useStoreDispatch();
const storage = useStorage('navigation');
Expand Down Expand Up @@ -95,8 +97,9 @@ const NavigationSideBar: React.FC = () => {
exitDone: css.collapsedExitDone,
}}
in={isCollapsed}
nodeRef={nodeRef}
timeout={200}>
<nav className={css.base}>
<nav className={css.base} ref={nodeRef}>
<header>
<div className={css.logo}>
<div className={css.logoIcon} />
Expand Down
2 changes: 1 addition & 1 deletion webui/react/src/components/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Helmet } from 'react-helmet';
import { Helmet } from 'react-helmet-async';

import PageHeader from 'components/PageHeader';
import { useStore } from 'contexts/Store';
Expand Down
9 changes: 8 additions & 1 deletion webui/react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ import * as serviceWorker from './serviceWorker';
import 'prototypes';
import 'dev';

ReactDOM.render(<Router history={history}><App /></Router>, document.getElementById('root'));
ReactDOM.render(
<React.StrictMode>
<Router history={history}>
<App />
</Router>
</React.StrictMode>,
document.getElementById('root'),
);

/*
* If you want your app to work offline and load faster, you can change
Expand Down
6 changes: 1 addition & 5 deletions webui/react/src/pages/SignIn.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { notification } from 'antd';
import queryString from 'query-string';
import React, { useEffect, useState } from 'react';
import { Helmet } from 'react-helmet';
import { useLocation } from 'react-router-dom';

import AuthToken from 'components/AuthToken';
Expand Down Expand Up @@ -75,11 +74,8 @@ const SignIn: React.FC = () => {
* accessing a page from the browser when the user is already verified.
*/
return auth.checked ? (
<Page>
<Page docTitle="Sign In">
<div className={css.base}>
<Helmet>
<title>Sign In - Determined</title>
</Helmet>
<div className={css.content}>
<Logo type={LogoTypes.OnLightVertical} />
<DeterminedAuth canceler={canceler} />
Expand Down
9 changes: 9 additions & 0 deletions webui/react/src/storybook/HelmetDecorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { DecoratorFunction } from '@storybook/addons';
import React from 'react';
import { HelmetProvider } from 'react-helmet-async';

const HelmetDecorator: DecoratorFunction<React.ReactNode> = storyFn => {
return React.createElement(HelmetProvider, null, storyFn());
};

export default HelmetDecorator;