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

Refactor, move from react-scripts to vite #333

Open
wants to merge 28 commits into
base: dev
Choose a base branch
from
Open

Conversation

mihirsamdarshi
Copy link
Collaborator

@mihirsamdarshi mihirsamdarshi commented May 3, 2024

This PR introduces a number of changes.

React no longer maintains create-react-app, and a number of the packages that the frontend were using have long been deprecated

Here are all the changes introduced by this PR:

react-scripts -> vite refactor

  • Replaced react-scripts with vite
    • react-scripts has long been deprecated in favor of full-stack frameworks like Gatsby, NextJS, or Remix
    • Vite is the clear replacement, being among the top downloaded non-framework bundlers
    • Vite brought build time of this project down from 120s to 5s on my machine (without vite-plugin-image-optimizer)
    • HMR is even faster
    • These changes position us well for future Server-sider rendering (SSR) efforts, especially when combined with the React Router changes below. Transitioning from react-router v6 to Remix with Vite is extremely easy, and immediately provides us SSR capabilities
  • Replaced react-scripts package.json scripts with vite commands
  • Environment variable changes:
  • Added vite.config.js, using react-swc React compiler plugin.
  • Added bundle visualizer in order to see how much space various packages take
  • Added vite-plugin-image-optimizer for optimizing images

react-router v5 to v6 upgrade

Replace jest with vitest

  • The removal of react-scripts necessitates the introduction of a test framework
  • vitest is a drop-in replacement for jest that works for the vite framework

Code Split CSS

  • Use Vite-native PostCSS integration for SCSS compilation
  • Removed page styles from main.scss SCSS
    • Added SCSS imports to individual pages
    • Separate variables/base layers, and replace @import with @use or @forward, ahead of deprecation of @import

Misc changes

  • Updated storybook to latest
  • Updated ESlint to v8

Regressions

  • CircleCI will continue to fail until the REACT_APP_-styled env vars are replaced by VITE_ style env vars

@mihirsamdarshi mihirsamdarshi force-pushed the refactor/vite branch 5 times, most recently from e7ad0d7 to f45d520 Compare May 4, 2024 00:45
@mihirsamdarshi mihirsamdarshi marked this pull request as ready for review May 4, 2024 00:59
@mihirsamdarshi mihirsamdarshi changed the title refactor/vite Refactor, move from react-scripts to vit4e May 4, 2024
@mihirsamdarshi mihirsamdarshi changed the title Refactor, move from react-scripts to vit4e Refactor, move from react-scripts to vite May 4, 2024
@mihirsamdarshi mihirsamdarshi requested a review from jimmyzhen May 4, 2024 01:23
@mihirsamdarshi mihirsamdarshi force-pushed the refactor/vite branch 2 times, most recently from 906ede8 to f1c9f89 Compare May 9, 2024 08:12
- vis-network-react is distributed as CommonJS instead of ESM
@mihirsamdarshi mihirsamdarshi force-pushed the refactor/vite branch 4 times, most recently from 8afa38f to a59fca5 Compare May 10, 2024 06:11
@mihirsamdarshi mihirsamdarshi force-pushed the refactor/vite branch 2 times, most recently from 3584582 to 8476ff2 Compare July 1, 2024 18:01
@mihirsamdarshi
Copy link
Collaborator Author

Hey @jimmyzhen this PR is ready for a review

# Conflicts:
#	src/AnalysisPage/pass1b06PhenotypeAnimal.jsx
#	src/AnnouncementsPage/announcementsPage.jsx
#	src/DataAccess/dataAccessPage.jsx
#	src/DataStatusPage/dataStatusPage.jsx
#	src/DataSummaryPage/dataSummaryPage.jsx
#	src/LandingPage/landingPage.jsx
#	src/LinkoutPage/linkoutPage.jsx
#	src/MainStudy/mainStudy.jsx
#	src/ReleasePage/releasePage.jsx
#	src/sass/landingPage.scss
@mihirsamdarshi
Copy link
Collaborator Author

I deployed this PR to our Kubernetes testing website. You can verify that there are no regressions on this website.

This PR significantly improves Lighthouse scores, and since Lighthouse is one aspect used by Google to determine search rankings, this should help with SEO as well.

Lighthouse Before Screenshot 2024-07-08 at 6 04 54 PM
Lighthouse With Refactor Screenshot 2024-07-08 at 6 04 56 PM

Additionally, notice the DOMContentLoaded time and amount of data transferred when throttling to 4G speeds. Mobile users on cellular networks will have better experiences.

Loading Time Before Screenshot 2024-07-08 at 6 12 22 PM
Loading Time With Refactor Screenshot 2024-07-08 at 6 12 24 PM

# Conflicts:
#	src/LandingPage/landingPage.jsx
#	src/LandingPage/openOfficeHour.jsx
#	src/sass/landingPage.scss
#	src/sass/main.scss
#	yarn.lock
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