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 5 #249

Merged
merged 12 commits into from
Feb 2, 2022
Merged

Upgrade to react-scripts 5 #249

merged 12 commits into from
Feb 2, 2022

Conversation

dylnclrk
Copy link
Contributor

@dylnclrk dylnclrk commented Jan 15, 2022

Problem

The CRA team released react-scripts 5.0.0 recently. Depfu opened #242 to address this, however, react-scripts is responsible for generating many of the files in this repo, so PR does the upgrade manually to capture those changes.

Solution

Create a new project using react-scrips 5.0.0, audit the differences in the generated files from those currently on main (which were generated by an older version of react-scripts). Copy over those changes and try to get rid of some of the cruft in this template (there wasn't much).

Change summary

  • Run create-react-app (with react-scripts 5.0.0) to generate a new, clean app-prototype
  • Copy over our changes like SCSS, linter configs, docker config, CCI config, etc.
  • Upgrade a handful of other packages that were lagging behind.

TODO

  • Fix docker build ($ docker build . -t spraygun-react-ts:latest, see comment)

Things to manually verify:

  • yarn lint
  • yarn build, serve
  • yarn test
  • yarn start
  • husky pre-commit hook
  • prettier (eslint works as expected)
  • Spraygun can use this template as expected (I generated this repo: https://github.com/dylnclrk/test-blog)
  • Circle CI configuration (tests pass on this branch)
  • Docker configuration (can run docker build . -t spraygun-react-ts:latest && docker run -p 3000:3000 spraygun-react-ts:latest)
  • Deploy to heroku (https://test-blog-tessssst.herokuapp.com)

Steps to Verify

  1. Create a spraygun project with this version of the TS template (by using spraygun's -p path/to/this/template flag)
  2. See that it functions as expected (yarn test, lint, start, build, yarn serve -s build etc.)
  3. Check that deploys to Heroku and runs on CCI as expected

New Dependencies

Additions:

  • web-vitals - comes with new CRA-generated apps, left it in.

🙈 See the package.json diff for all of the upgraded dependencies.

Screenshots

Appears to work locally:
console with 'yarn lint' results, no warnings
console with 'yarn test' results, no failures

app running successfully in browser

@dylnclrk dylnclrk requested a review from a team January 15, 2022 01:06
@dylnclrk
Copy link
Contributor Author

Still working on verifying that everything still works… Please let me know if you have suggestions of things to test.

package.json Outdated
@@ -3,43 +3,41 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/node": "^16.11.11",
"@types/react": "^17.0.37",
"@types/node": "^17.0.8",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I think this might need to track the current version of Node (16). I think the index.d.ts for @types/node should specify the Nodejs version.

package.json Outdated
"serve": "^13.0.2",
"typescript": "^4.5.4"
"typescript": "^4.5.4",
"web-vitals": "^2.1.3"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒️ this is a new package, create-react-app adds it (and the required boilerplate) by default. With it you can report metrics like "first input delay", "time to first byte", etc from real users. I would use it on my next project, so I left it in. But maybe this warrants a separate PR? More info here: GooggleChrome/web-vitals

},
"resolutions": {
"@typescript-eslint/typescript-estree": "^5.6.0",
Copy link
Contributor Author

@dylnclrk dylnclrk Jan 15, 2022

Choose a reason for hiding this comment

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

🗒️ I dropped this resolution @typescript-eslint/typescript-estree because I wasn't sure why it was in there, and getting rid of it didn't seem to have an effect.

},
"resolutions": {
"@typescript-eslint/typescript-estree": "^5.6.0",
"caniuse-lite": "^1.0.30001272"
"caniuse-lite": "^1.0.30001299",
Copy link
Contributor Author

@dylnclrk dylnclrk Jan 15, 2022

Choose a reason for hiding this comment

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

🗒️ Updated the caniuse-lite def to match what was installed from scratch

"@typescript-eslint/typescript-estree": "^5.6.0",
"caniuse-lite": "^1.0.30001272"
"caniuse-lite": "^1.0.30001299",
"mini-css-extract-plugin": "2.4.7"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦 This is a temporary workaround for this issue: facebook/create-react-app#11930

Comment on lines 8 to 11
<meta
name="description"
content="Web site created using create-react-app"
/>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

❔ Should we remove this? Leave it in? change it to

Suggested change
<meta
name="description"
content="Web site created using create-react-app"
/>
<meta
name="description"
content="Web site created using spraygun"
/>

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should take it out. It would be weird for that to go into production accidentally, and then you find out when someone shares your app on social and that description pop up 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 Not sure if this was intentionally omitted before, but it was generated by create-react-app

@@ -34,7 +34,7 @@
color: colors.$blue;
}

@keyframes App-logo-spin {
@keyframes app-logo-spin {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒️ New stylelint rule wants keyframes to be lower-kebab-case.

src/index.scss Outdated
@@ -1,6 +1,5 @@
// index.scss is for CSS declarations that aren't specific to a component.
// In practice, that means this file is used for two things:
//
Copy link
Contributor Author

@dylnclrk dylnclrk Jan 15, 2022

Choose a reason for hiding this comment

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

❔ New stylelint rule doesn't want blank comments like this, I sorta disagree, but followed the rule to keep things as vanilla as possible. Should we disable this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, this rule seems a bit much. I vote to disable the rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ disabled!

Comment on lines +13 to +17

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
Copy link
Contributor Author

@dylnclrk dylnclrk Jan 15, 2022

Choose a reason for hiding this comment

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

🗒️ Here's the boilerplate for web-vitals. More info on the linked page.

@@ -0,0 +1,15 @@
import { ReportHandler } from "web-vitals";

const reportWebVitals = (onPerfEntry?: ReportHandler) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤣 Would be funny if this code affected these metrics.

@@ -2,4 +2,4 @@
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom/extend-expect";
import "@testing-library/jest-dom";
Copy link
Contributor Author

@dylnclrk dylnclrk Jan 15, 2022

Choose a reason for hiding this comment

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

🗒️ CRA generates this file with the shorter import (which matches the docs)

Comment on lines +1 to +4
@use "sass:color";
$blue: #61dafb;
$blue-darker: darken($blue, 30%);
$blue-lighter: lighten($blue, 5%);
$blue-darker: color.adjust($blue, $lightness: -30%);
$blue-lighter: color.adjust($blue, $lightness: 5%);
Copy link
Contributor Author

@dylnclrk dylnclrk Jan 15, 2022

Choose a reason for hiding this comment

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

🗒️ stylelint doesn't want you to use darken/lighten any more.

@@ -23,6 +23,7 @@ module.exports = {
},
extends: [
"react-app",
"react-app/jest",
Copy link
Contributor Author

@dylnclrk dylnclrk Jan 15, 2022

Choose a reason for hiding this comment

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

🗒️ CRA includes this extend now. I wonder if that includes plugin:jest/recommended, which makes the below extend a dupe.

@dylnclrk
Copy link
Contributor Author

Oof, looks like the docker build needs to be fixed, it appears to be building a test file.
image

@dylnclrk
Copy link
Contributor Author

Oof, looks like the docker build needs to be fixed, it appears to be building a test file.

Was having problems maintaining the dependencies/devDependencies split, facebook/create-react-app#11956, merging dependencies into one group (as is the default w/ CRA) for now.

@mattbrictson
Copy link
Contributor

Create a spraygun project with this version of the TS template (? not sure how to do this with a branch)

@dylnclrk You can use the -p (local path) option like this:

$ npx spraygun -p path/to/spraygun-react-ts APP_NAME

@dylnclrk
Copy link
Contributor Author

Create a spraygun project with this version of the TS template (? not sure how to do this with a branch)

@dylnclrk You can use the -p (local path) option like this:

$ npx spraygun -p path/to/spraygun-react-ts APP_NAME

Oh, sorry, I should have updated those instructions to get rid of that question. But yes, I tested it and even deployed the generated app to Heroku on Tuesday and everything seemed to work as expected.

Copy link
Contributor

@mattbrictson mattbrictson left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for testing the Heroku deploy as well.

I tested locally with npx spraygun -p ... and it worked great.

I noticed a deprecation warning when starting the dev server, but that seems to be a known CRA issue: facebook/create-react-app#11860. So I don't think that should block this PR.

🚀

src/index.scss Outdated
@@ -1,6 +1,5 @@
// index.scss is for CSS declarations that aren't specific to a component.
// In practice, that means this file is used for two things:
//
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, this rule seems a bit much. I vote to disable the rule.

@dylnclrk
Copy link
Contributor Author

dylnclrk commented Feb 2, 2022

I upgraded a couple dependencies to match main, checked everything again and this is good to go 🚀 merge at will…

Copy link
Contributor

@mattbrictson mattbrictson left a comment

Choose a reason for hiding this comment

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

💥

@mattbrictson mattbrictson merged commit 6749b78 into main Feb 2, 2022
@mattbrictson mattbrictson deleted the update-to-react-scripts-5 branch February 2, 2022 01:43
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.

2 participants