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

Perform front-end dependency update (#1312) #1363

Merged
merged 19 commits into from Apr 21, 2022

Conversation

ssciolla
Copy link
Contributor

@ssciolla ssciolla commented Mar 31, 2022

This PR updates, pares down, and otherwise tries to improve the usage of npm packages in the frontend. In the process, some changes were necessary around the use of @apollo/client (mostly updating imports, configuration), react-router-dom (adjusting Route usages), fontawesome (switching to a Python library for providing CSS styles), and @material-ui (getting rid of RootRef instances). A lot of different areas are touched here, but the number of non-dependency file changes is hopefully not too high. The PR aims to resolve #1312.

To Do

  • Bump Node to 16, convert package-lock.json to new lockfile format.
  • Remove jquery, node-sass (not used)
  • Update
    • React (and associated dependencies)
    • Update Webpack (resolving errors, warnings, etc.)
    • Apollo/graphql (and fix imports, course query)
    • rc-slider
    • jest, checking to make sure tests still run
    • other misc. imports (babel, js-cookie, loaders, etc.)
    • Material UI to last published release of version 4
      • Remove RootRef usage due to deprecation
    • react-router-dom to 5.3 (I pushed this forward a bit by adopting new version 5 patterns, but I am also waiting on updating to version 6, since they are recommending we wait until there is a backwards-compatible version. https://reactrouter.com/docs/en/v6/upgrading/v5#refactor-custom-routes).
  • Review un-updated dependencies
  • Replace django-npm with fontawesomefree
  • Create new issue regarding d3 updates (see Update d3 #1367).
  • Test with LTI launch
  • Run Cypress tests

@ssciolla ssciolla added dependencies Pull requests that update a dependency file Frontend labels Mar 31, 2022
assets/src/service/client.js Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
package.json Outdated
Comment on lines 90 to 112
"@babel/cli": "~7.17.6",
"@babel/core": "~7.17.8",
"@babel/preset-env": "~7.16.11",
"@babel/preset-react": "~7.16.7",
"@babel/register": "~7.17.7",
"@material-ui/core": "^4.12.3",
"@material-ui/icons": "^4.11.2",
"babel-loader": "~8.2.4",
"css-loader": "~6.7.1",
"eslint-plugin-react-hooks": "^4.4.0",
"jest": "~27.5.1",
"jest-resolve": "~27.5.1",
"js-cookie": "~3.0.1",
"mini-css-extract-plugin": "2.6.0",
"react-app-polyfill": "^3.0.0",
"react-test-renderer": "17.0.2",
"standard": "^16.0.4",
"style-loader": "~3.3.1",
"typeface-roboto": "1.1.13",
"url-loader": "4.1.1",
"webpack": "5.70.x",
"webpack-bundle-tracker": "^1.4.0",
"webpack-cli": "4.9.x"
Copy link
Contributor Author

@ssciolla ssciolla Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we could maybe optimize how node_modules is built. Some of the dependencies under devDependencies are more like dependencies (@material-ui, js-cookie, typeface-roboto?). Looking at the Docker artifacts, I see there is an effort to remove extraneous packages (npm prune --production), but I'm not sure if it's actually working. When I go to OpenShift and peak inside node_modules, I still see jest, webpack, -loader, etc. We should probably also make sure that the frontend unit test and related artifacts are left behind from the production images (currently, they are under assets/src/__tests__).

Copy link
Contributor Author

@ssciolla ssciolla Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to discuss with @jonespm but this is probably best tackled separately at a later date.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like @justin0022 originally added the npm prune afd74b5.

I've never checked to see if it's working either.

It looks like it might have to be combined with node-prune to really remove the node_modules. I saw that mentioned in this article here: https://itsopensource.com/how-to-reduce-node-docker-image-size-by-ten-times/

I think we can just address this in a separate issue but yeah having the appropriate things in devDependencies makes sense to me.

Comment on lines +11 to +12
<link rel="stylesheet" type="text/css" href="{% static 'fontawesomefree/css/all.min.css' %}">
<script src="{% static 'fontawesomefree/js/all.min.js' %}"></script>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fontawesome offers a Django/solution for using icons in templates called fontawesomefree: https://pypi.org/project/fontawesomefree/ This isn't strictly a replacement for django-npm, but after we removed jquery, fontawesome seemed to be the only thing we really needed django-npm for.

To explain a bit more, fontawesome CSS classes are being used for Resources Accessed and for screenreader-only content, and thus we needed a way to load the styling. Using a strictly React approach proved somewhat challenging because of 1) we currently use string classes for icons on the Resources Accessed D3 chart, where we can't really use JSX and 2) figuring out how to load the CSS file through webpack was a headache. If D3 is ever replaced, we could look into using this approach (https://fontawesome.com/docs/web/use-with/react/), or removing fontawesome all together in favor of Material UI icons. The latter though would require configuration changes, since we currently pass CSS class strings in env.json for each resource type.

@jonespm, let me know what you think of this solution for removing django-npm. Here's the commit:
eb3492d

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think originally pre-react we needed this for more. But that commit looks good to remove it. I'd rather have this supported package than the older unsupported one. Be great if we have time to eventually do something with D3.

@ssciolla
Copy link
Contributor Author

ssciolla commented Apr 8, 2022

I'm going to do more testing, so I can't guarantee this is completely stable yet, but I think we can get the review process started.

@pushyamig, I'm going to request your review since you're knowledgeable about the frontend, but I understand you have other priorities too.

@ssciolla ssciolla marked this pull request as ready for review April 8, 2022 19:49
@ssciolla ssciolla mentioned this pull request Apr 8, 2022
@pushyamig
Copy link
Contributor

@pushyamig, I'm going to request your review since you're knowledgeable about the frontend, but I understand you have other priorities too.

is there a time I should review this by? It's been a year since I ran Myla Locally.

@ssciolla
Copy link
Contributor Author

ssciolla commented Apr 8, 2022

@pushyamig, I'm going to request your review since you're knowledgeable about the frontend, but I understand you have other priorities too.

is there a time I should review this by? It's been a year since I ran Myla Locally.

Not sure, probably needs to be merged next week to have a chance of getting in the next release. I may be asked to scale it back if no one wants to or can review it soon.

@pushyamig
Copy link
Contributor

@ssciolla I will review it today, I was able to run this locally.

@pushyamig
Copy link
Contributor

Run Cypress tests

I am really not sure we need to support this. since the stuff we did back then was very basic and no further development after that. If it is too much work then I probably will skip the update. But it's upto @jonespm

Copy link
Contributor

@pushyamig pushyamig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Over all this change looks good and positive. I was able to test this with few courses both as a student and instructor view. I don't see any side effect from this change. I am approving this now, but I want fellow reviewers to test and approve as well since I am coming to project after a gap.

@pushyamig
Copy link
Contributor

I saw a notification today that Google analytics team is sunsetting current version Universal Analytics and it is replacing with Google analytics 4. I think we are using a react-ga library which is still support Universal analytics.

At some point i believe this library will update as well. I don't know what is difference between existing and new one. It looks like we need to configure this GA4 from our GA console as well. I think there may be some work from that in future

@jonespm
Copy link
Member

jonespm commented Apr 20, 2022

@pushyamig I saw that today too. I created #1371 to capture that work that we'll need to do. We'll have to look at this for our other projects that use GA too and will still be running.

I think just Student Explorer. GA in MWrite has been broken since the last switch to Google UA.

Copy link
Member

@jonespm jonespm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like everything has been addressed or created as a new issue.

@ssciolla ssciolla merged commit 458a13a into tl-its-umich-edu:master Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️ backend dependencies Pull requests that update a dependency file 📈 enhancement New feature or request Frontend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade frontend dependencies
3 participants