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

🪟 🔧 Migrate from react-scripts to Vite #21421

Merged
merged 26 commits into from
Jan 23, 2023
Merged

🪟 🔧 Migrate from react-scripts to Vite #21421

merged 26 commits into from
Jan 23, 2023

Conversation

timroes
Copy link
Collaborator

@timroes timroes commented Jan 13, 2023

What

Removed react-scripts (Create React App) as a build system and instead use Vite.

Why?

Because it's ⚡ faster, ⚙️ more configurable and way better 👷 maintained.

How

I've tried to document most files inline to give context why changes have happened. Some general remarks:

🔐 HTTPS required

Since Vite loads modules as individual files during development, we want to make sure to use HTTP2 to not run into parallel file loading limits of HTTP1. Thus HTTPS is required now also during development, i.e. the development page will now be available via https://localhost:3000 or https://127.0.0.1:3000. Since this will use self-signed certificates you need to ignore an "unsecure" warning in your browser. Due to the way Vite does caching it's also not necessary to disable HTTP caching during development and will be faster if this setting is off in your Dev Tools.

No code changes and further work

There has been no code change on actual source code for this. The only difference would be that Vite used import.meta.env instead of process.env. Since we still run tests via babel and Storybook via Webpack, I made sure process.env continues to work. That allows us to migrate Storybook and Jest in separate PRs, since both of them are quiet a bit of work to convert (and for Storybook we likely want to wait for the 7.0 release).

🔍 Code quality scans

Stylelint, ESLint and TypeScript runs in Vite (via the checker plugin) async in different workers. That means you might see warnings/errors coming from those in the UI with a bit of a delay, because the actual code already is delivered immediately, while the checks are still running. The new error overlay also doesn't pop up by default, but can be opened via a button on the bottom (Errors will still be printed to the terminal as well):

screenshot-20230117-120844

Testing

I've validated that ESLint (warnings as well as errors), Stylelint and TypeScript will fail the build with a non zero status code, to make sure they won't pass CI. Also tested Cloud mode and local development working, as well as OSS mode building proper docker images.

<ReactQueryDevtools
initialIsOpen={false}
position="bottom-right"
toggleButtonProps={{ style: { transform: "translateX(-75px)" } }}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ℹ️ Running on HTTPS we'll now also get the intercom banner in development, so I moved the react query devtool widget over to not overlap it.

@@ -1,3 +1,5 @@
/// <reference types="@types/segment-analytics" />
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ℹ️ Without types in the tsconfig.json (which was the case beforehand) all @types/... packages get automatically imported. That's not the case anymore now, so we'll reference the only missing one in this file explicitally.

Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to use triple-slash syntax over adding "@types/segment-analytics" to tsconfig.json? Seems like tsconfig.json might be a more centralized place to introduce this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My main reason was just, that this way it's closer to "where it's used", i.e. if we were to remove Segment I feel it's clearer that we include the reference here. Technically it should work the same if we add it to the tsconfig.json. I don't have strong opinions either way though, so happy to have you make the call on this.

@@ -106,16 +106,8 @@ task copyNginx(type: Copy) {
into "build/docker/bin/nginx"
}

task stylelint(type: NpmTask) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ℹ️ Stylelint now runs as part of the Vite (via the checker plugin). So it doesn't need a separate Gradle task anymore.

Comment on lines +144 to +146
"meow": "^9.0.0",
"node-fetch": "^2.6.7",
"optionator": "^0.9.1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ℹ️ Peer dependencies required by the styellint and eslint plugin for vite checker.

"orval": "^6.11.0-alpha.10",
"prettier": "^2.6.2",
"react-scripts": "^5.0.1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👋 bye, bye, you will for sure not be missed.

@timroes
Copy link
Collaborator Author

timroes commented Jan 17, 2023

@timroes timroes marked this pull request as ready for review January 17, 2023 13:08
@timroes timroes requested a review from a team as a code owner January 17, 2023 13:08
@timroes
Copy link
Collaborator Author

timroes commented Jan 17, 2023

Currently blocked on #20887 . End to end tests are failing due to change in class names, which should be solved by that PR (and not requiring classNames for testing).

@dizel852
Copy link
Contributor

Unblocked - just merged #20887 🎉

@flash1293
Copy link
Contributor

flash1293 commented Jan 20, 2023

I'm probably doing something wrong, but if that's the case it's easy to run into it. This is what I did:

  • Check out this branch
  • Run npm install
  • Run npm start
  • Go to https://localhost:3000/ (need to allow unsafe connection)
  • Fails like this:

Screenshot 2023-01-20 at 13 59 53

@timroes
Copy link
Collaborator Author

timroes commented Jan 20, 2023

Thanks for catching this. This is actually a valid thing I need to fix. Currently we set apiUrl to the same procotol in the defaultConfig, which we shouldn't since the local backend server does only listen to http. Will address that.

@josephkmh
Copy link
Contributor

CORS issue is fixed in #21668, merged that in locally while I'm testing and request from https://localhost:3000 are working well again 👍

@timroes
Copy link
Collaborator Author

timroes commented Jan 23, 2023

@flash1293 This should be solved now. You'll need to rebuild the server though (:airbyte-server:assemble) and restart your docker-compose to get it solved.

Copy link
Contributor

@josephkmh josephkmh left a comment

Choose a reason for hiding this comment

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

Looks good to me! I tested locally in dev mode on https://localhost:3000 and everything worked smoothly. Same with a fresh build served via docker on http://localhost:8000

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

LGTM; tested and seems to work fine.

I have one complaint, but I'm pretty sure that happened before, so no need to fix it on this PR: When defining a class in the scss module which is never referenced, it shows the expected error:

 ERROR(ESLint)  Unused classes found in BuilderField.module.scss: errorXXX, abc (css-modules/no-unused-class)
 FILE  /Users/joereuter/Clones/airbyte/airbyte-webapp/src/components/connectorBuilder/Builder/StreamReferenceField.tsx:10:8

     8 |
     9 | import { BuilderStream } from "../types";
  > 10 | import styles from "./BuilderField.module.scss";

However, when fixing the problem, this error doesn't go away - it sticks around until I restart the dev server.

@timroes
Copy link
Collaborator Author

timroes commented Jan 23, 2023

However, when fixing the problem, this error doesn't go away - it sticks around until I restart the dev server.

This is more related to eslint and indeed currently present. You should though not need to actually kill the dev server, but you'll need to save the TS file that includes that SASS again. Since this rule is part of ESLint, it won't rerun if something in the SASS file changes, only when the TS file actually has a change.

@timroes
Copy link
Collaborator Author

timroes commented Jan 23, 2023

The only check that failed, was tearing down the CI runner in the end, so treating this CI run as successful for merging.

@timroes timroes merged commit 828b32a into master Jan 23, 2023
@timroes timroes deleted the tim/migrate-vite branch January 23, 2023 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/frontend Related to the Airbyte webapp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants