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

Upgrade to react-scripts v5 #695

Merged
merged 14 commits into from
Jul 6, 2022
Merged

Upgrade to react-scripts v5 #695

merged 14 commits into from
Jul 6, 2022

Conversation

johnclary
Copy link
Member

@johnclary johnclary commented Jun 23, 2022

Associated issues

cityofaustin/atd-data-tech#9561

Steps I took (for reference):

  1. $ nvm use 😉
  2. delete /node_modules and package-lock.json
  3. edit package.json to remove react-map-gl-draw
  4. edit package.json to remove all devDependencies
  5. manually set react-scripts in package.json to ^5.0.0
  6. re-install node modules and rebuild package-lock.json: $ npm install
  7. install react-map-gl-draw again, forcibly: $ npm install react-map-gl-draw@^0.22.3 --force
  8. manually bump react/react-dom peerDependencies of react-map-gl-draw to ^17.x in package-lock.json
  9. install babel import plugin: $ npm install --save-dev babel-plugin-import
  10. remove eslintConfig in package.json and update .eslintrc.json
  11. code changes to get file upload and components map to compile
  12. code changes to stop exporting anonymous objects
  13. $ npm run test ⚙️
  14. $ npm run start

About our ESLint config

It's been hard for me to untangle the effects of this upgrade on linting. We're migrating from ESLint v6 to v8, as well as upgrading a number of related parsers and configs.

Also, as far as I can tell, the react-app ESLint config was previously being ignored, because it was defined in package.json, and it was being overwritten by our .eslintrc file (docs).

One issue I immediately encountered were errors with anonymous default exports. That rule has been in place for years, but was maybe only enabled by react-app? 🤔. Anyway, I addressed those errors in this PR.

The react-app ESLint config is Create React App's base lint configuration, and they recommend that we do not ignore it. It's now enabled. Besides a few anonymous default export problems, the app is (surprisingly?) compiling without errors.

Additionally, we had a number of ESLint plugins through eslint-config-airbnb. However, none of these configs were enabled in our .eslintrc file. I removed them:

 'eslint-plugin-import': '^2.25.3',
  'eslint-plugin-jsx-a11y': '^6.5.1',
  'eslint-plugin-react': '^7.28.0',
  'eslint-plugin-react-hooks': '^4.3.0'

And, lastly, i removed the prettier linting configs as well. I don't fully understand, but the latest version threw a lot of errors and clearly had different opinions than our previous setup.

In summary, we need to revisit all of our linting soon.

Other notes

  • npm install will fail without our package-lock.json. we are stuck dealing with force installing react-map-gl-draw for the near future.
  • we're getting an ugly compilation warning about DoubleScrollbar.js:
WARNING in ./node_modules/react-double-scrollbar/dist/DoubleScrollbar.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '/atd-moped/moped-editor/node_modules/react-double-scrollbar/dist/DoubleScrollbar.js.map' file: Error: ENOENT: no such file or directory, open '/atd-moped/moped-editor/node_modules/react-double-scrollbar/dist/DoubleScrollbar.js.map'

Seems harmless, and it's possible to suppress the warning. Discussed here.

Testing

URL to test: deploy preview and local

If testing locally

  1. Remember to switch Node environments with$ nvm use
  2. You will probably need to delete node_modules/ and then $ npm install, but who knows
  3. Follow usual steps to start Moped editor + database.
  4. Please make some code changes and test out the live-refresh.
  5. try out the Jest tests, too: $ npm run test

Things to test

  1. Make sure File uploads work correctly
  2. Make sure static images load correctly:
  • Component map fallback image (when no components have been mapped)
  • The Streets / aerials buttons on the component map

Ship list

  • Code reviewed
  • Product manager approved
  • Added to QA test script if applicable

@johnclary johnclary changed the base branch from main to jc-react-router-dom-upgrade June 23, 2022 21:03
@@ -1,4 +1,3 @@
{
"extends": ["plugin:prettier/recommended"],
"parser": "babel-eslint"
"extends": ["react-app"]
Copy link
Member Author

Choose a reason for hiding this comment

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

see my comment in the PR description

"eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "^2.5.1",
"prettier": "^1.19.1"
},
Copy link
Member Author

Choose a reason for hiding this comment

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

see my comment in the PR description about eslint

@@ -7,23 +7,27 @@
*
* @return {string} - Formatted string.
*/
export default (bytes, si=false, dp=1) => {
const thresh = si ? 1000 : 1024;
const humanReadableFileSize = (bytes, si = false, dp = 1) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Here is the change that fixed the ESLint warning - the rest is prettification

background-image: url(/moped/static/images/mapAerial.jpg) !important;
color: white;
}

Copy link
Member Author

@johnclary johnclary Jun 24, 2022

Choose a reason for hiding this comment

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

it's now impossible to reference files in /public directory in CSS that lives in /src. The workaround here was to use our existing styles that we build in ProjectComponentsBaseMap.js

@@ -5,38 +5,38 @@
* @default
*/
export const StaffListViewExportConf = {
Copy link
Member Author

Choose a reason for hiding this comment

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

linting

@@ -24,9 +24,6 @@
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
Copy link
Member Author

@johnclary johnclary Jun 24, 2022

Choose a reason for hiding this comment

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

The react-app ESLint config is Create React App's base lint configuration. As far as I can tell, this config was previously being ignored, because we're using an .eslintrc file which overrode the package.json config.

Docs:

If there are multiple configuration files in the same directory, ESLint will only use one. The priority order is as follows:

.eslintrc.js
.eslintrc.cjs
.eslintrc.yaml
.eslintrc.yml
.eslintrc.json
package.json

@johnclary johnclary changed the base branch from jc-react-router-dom-upgrade to main June 24, 2022 21:25
Copy link
Member

@frankhereford frankhereford left a comment

Choose a reason for hiding this comment

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

Thank you for this very detailed documentation via your opening PR comment. It's been exceptionally helpful both in terms of understanding the PR's contents itself, but also will serve as a useful reference for me going forward. 🙏

I've tested this both locally and on test, and I've found that everything you enumerated in your PR description works as expected:

  • Local
    • Deployment spins up
    • Live-refresh on code-change
    • Jest tests 💯
  • Test
    • File upload
    • Static images referenced via CSS

Thanks for the chance to review this. I've gone through the code changes, and everything makes sense to me, but take me with a grain of salt 🧂 - I'm eager to learn from our more seasoned JS devs' reviews too.

@johnclary
Copy link
Member Author

thanks @frankhereford!

btw, here's a diff of $ npm list against main and this branch, so that you can see all the packages that got bumped through this process.

@frankhereford
Copy link
Member

frankhereford commented Jun 27, 2022

@johnclary wrote:

btw, here's a diff of $ npm list against main and this branch, so that you can see all the packages that got bumped through this process.

Wow - It's a sisyphean task 🪨 and this is a huge step forward.

You got a lot of libraries (~40!!) updated or removed! You know that makes my day -- I realize this is a complex process to say the least, and I really am thankful for this PR!!

@@ -87,24 +84,15 @@
"react-quill": "^2.0.0-beta.4",
"react-router": "^6.3.0",
"react-router-dom": "^6.3.0",
"react-scripts": "^3.4.1",
"react-scripts": "^5.0.0",
Copy link
Member

Choose a reason for hiding this comment

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

🎊

Copy link
Member

@chiaberry chiaberry left a comment

Choose a reason for hiding this comment

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

Tested locally, runs as expected. I'm leaning towards suppressing the build warning, unless theres a different fix on the horizon for the DoubleScrollbar.js.map package. I can be convinced otherwise though.

Copy link
Collaborator

@mddilley mddilley left a comment

Choose a reason for hiding this comment

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

I tested this locally and in the deploy preview, and it works great. Thanks for pushing us forward here - the hot reload is so great! Such a nice DX enhancement.

Happy to see someone getting into the lint config and cut out some of the unneeded stuff too. It will make it easier to see how to move forward there. ✨

Comment on lines +8 to +10
import { FilePond, registerPlugin } from "react-filepond";
// `File` imported from filepond to workaround react-scripts 5 import error
import { File } from "filepond"
Copy link
Collaborator

Choose a reason for hiding this comment

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

File uploads still work great in the deploy preview 👍

Copy link
Contributor

@amenity amenity left a comment

Choose a reason for hiding this comment

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

Project files and static images are looking good on Netlify! 👍 🚢

@johnclary
Copy link
Member Author

thanks, y'all—here we go!

@johnclary johnclary merged commit de44fe3 into main Jul 6, 2022
Copy link
Contributor

@mateoclarke mateoclarke left a comment

Choose a reason for hiding this comment

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

👍

@mateoclarke mateoclarke deleted the 9561-jc-react-scripts-5 branch July 6, 2022 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants