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

chore: upgrade React; use new JSX transform; sort imports #1129

Merged
merged 9 commits into from
May 10, 2021

Conversation

zwliew
Copy link
Contributor

@zwliew zwliew commented Apr 13, 2021

Problem

Let's upgrade to the new JSX transform to stay modern.

React has introduced the new JSX transform to enable improvements in future React releases. Although it does nothing significant as of now, it might be a good idea to upgrade anyway to stay up-to-date.

Reference on transitioning to the new JSX transform: https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html

Solution

Improvements:

  • Upgrade React to v16.14.0, which adds support for the new JSX transform
  • Use the new JSX transform
  • Uninstall TypeScript from the root directory as it causes VSCode/CoC's tsserver to use it for static analysis instead of the one in the frontend directory
  • Convert all default React import statements to destructured imports (import React from 'react' -> import { ... } from 'react')

Before & After Screenshots

No visual changes.

Tests

These tests have been verified locally but not on Amplify staging yet.

  1. Deploy the change on Amplify.
  2. Conduct smoke tests:
  • Create and send SMS campaign
  • Create and send Telegram campaign
  • Create and send email campaign
  • Create and send protected email campaign
  1. All pages and components should work fine without errors.

Deploy Notes

Upgraded dependencies:

  • react, react-dom: 16.31.1 -> 16.14.0
  • @types/react: 16.9.29 -> 16.14.5
  • @types/react-dom: 16.9.5 -> 16.9.12

package.json Show resolved Hide resolved
Copy link
Contributor

@miazima miazima left a comment

Choose a reason for hiding this comment

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

Lgtm, just need to shift the modules import order

import cx from 'classnames'

import styles from './ActionButton.module.scss'

import type { MouseEvent as ReactMouseEvent } from 'react'
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move this up top together with the react import, combine them if possible?

import cx from 'classnames'

import styles from './BodyWrapper.module.scss'

import type { FunctionComponent } from 'react'

Copy link
Contributor

Choose a reason for hiding this comment

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

To follow the import order convention, external module imports should be at the top. We could also look into if we want to use this plugin to sort import order
https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md#importorder-enforce-a-convention-in-module-import-order

Copy link
Contributor Author

@zwliew zwliew Apr 28, 2021

Choose a reason for hiding this comment

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

Thanks! I agree about sorting the import order with a plugin. I've looked into both eslint-plugin-import and eslint-plugin-simple-import-sort and settled on the eslint-plugin-import since it better supports module aliasing.

@zwliew zwliew changed the title chore: upgrade React and use the new JSX transform chore: upgrade React; use new JSX transform; use import-sort plugin Apr 28, 2021
@zwliew zwliew changed the title chore: upgrade React; use new JSX transform; use import-sort plugin chore: upgrade React; use new JSX transform; sort imports Apr 28, 2021
@zwliew
Copy link
Contributor Author

zwliew commented May 3, 2021

I've just rebased the branch atop develop.

Just to clarify, eslint-plugin-import sorts imports into the following groups, with newlines between each group:

  1. builtin modules (e.g. Node.js modules)
  2. external modules (e.g. react)
  3. parent relative models (e.g. ../xyz)
  4. sibling modules (e.g. ./abc)
  5. index file (e.g. ./index.ts)
  6. import-mapped modules (e.g. classes, components)

@miazima
Copy link
Contributor

miazima commented May 4, 2021

@lamkeewei I had suggested using an eslint plugin to auto sort import order for our frontend, wanted to get your go ahead too

@lamkeewei
Copy link
Contributor

@lamkeewei I had suggested using an eslint plugin to auto sort import order for our frontend, wanted to get your go ahead too

Sure! Will make our imports neater. Might also be useful to think about what is a good sort order for our imports, beyond the default rules (e.g. assets should be first/last, etc). Can refer to what vaccine ops did for their sorting.

zwliew added 9 commits May 7, 2021 11:59
We don't need this in the root directory.
Also, use `import type` where it makes sense.

Note: React's ``MouseEvent` type conflicts with the global `MouseEvent`
type, so rename it to `ReactMouseEvent` as well.
The group order is:
1. builtin modules (e.g. Node)
2. external modules (e.g. react)
3. parent relative models (e.g. ../xyz)
4. sibling modules (e.g. ./abc)
5. index file (e.g. ./index.ts)
6. import-mapped modules (e.g. classes, components)
@zwliew
Copy link
Contributor Author

zwliew commented May 7, 2021

Rebased the branch.

Todo:
look into making assets a group and moving them to the end of the imports list. This doesn't seem possible with eslint-plugin-import/order, so we will likely need to use eslint-plugin-simple-import-sort for this. vaccine ops uses it as well.

However, I don't feel like this is a big deal. The existing import order seems good to me.

Copy link
Contributor

@miazima miazima left a comment

Choose a reason for hiding this comment

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

The sorted import order is sufficient for now, improvising it has been delegated to a separate issue

@miazima miazima merged commit cedad15 into develop May 10, 2021
@miazima miazima deleted the feat-jsx-transform branch May 10, 2021 02:57
lamkeewei added a commit that referenced this pull request May 10, 2021
* develop:
  fix: fix error when updating Telegram ID for an existing phone number (#1178)
  chore: upgrade React; use new JSX transform; sort imports (#1129)
  fix(backend): docker build and tsc output directory structure (#1177)
  feat: refactor msg template components; add telegram character limit (#1148)
  refactor: use shared function to initialize models (#1172)
  chore: setup scaffolding for backend tests (#940)
  1.23.0
  fix(frontend): fix frontend test flakiness (#1162)
  fix: update successful delivery status only if error does not exist (#1150)
  chore: upgrade dependencies (#1153)
lamkeewei added a commit that referenced this pull request May 18, 2021
* develop:
  chore: upgrade dependencies (#1180)
  Backend tests - updating template for channels (#1175)
  feat(rich-text): support image as links (#1158)
  fix: fix error when updating Telegram ID for an existing phone number (#1178)
  chore: upgrade React; use new JSX transform; sort imports (#1129)
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.

3 participants