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

thuang-765-next-js #926

Merged
merged 9 commits into from
Mar 29, 2021
Merged

thuang-765-next-js #926

merged 9 commits into from
Mar 29, 2021

Conversation

tihuan
Copy link
Contributor

@tihuan tihuan commented Feb 22, 2021

#765

Live link: https://thuang-next-js-frontend.rdev.single-cell.czi.technology/

Reviewers

Functional:
@seve

Readability:
@MDunitz


Changes

  • add
  1. Add favicon support
  2. Add basic SSR for static layout
  3. Add _app.tsx and _document.tsx per Nextjs for adding global stylesheets and other global stuff
  4. Add next/head for modifying page.title instead of react-helmet
  • remove
  1. A few dead dependencies in package.json, on top of Gatsby ones
  2. Remove @reach/router and use Nextjs's own router for prefetching pages doc
  3. Remove theme-ui
  • modify
  1. Migrate from Gatsby to Next.js
  2. Change port from Gatsby's default 8000 to 3000. However, Jessica did say that rdev prod build still needs to run on :9000 for historical reasons 🙆‍♂️
  3. Minimally restructure the app to work with Next.js's file system based routing. Which means every route needs its own file in /pages
  4. Upgrade a few dependencies, since NPM was complaining about incompatible versions
  5. Use next/image for Image optimization

@tihuan tihuan force-pushed the thuang-765-next-js branch from 5b9a3ec to 13acc4a Compare February 22, 2021 22:51
@@ -1,61 +1,71 @@
# Local Development Environment
Copy link
Contributor Author

Choose a reason for hiding this comment

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

prettier change and changing Frontend app port from 8000 to 3000

@@ -1,4 +1,4 @@
version: '3.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.

prettier change and s/8000/3000

@@ -58,16 +58,16 @@ typings/
# configs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nextjs and Gatsby need different .gitignore config

@@ -0,0 +1,13 @@
module.exports = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Babel config is now needed, since Nextjs doesn't use the plugin paradigm that Gatsby uses. This setting works along side with https://github.com/styled-components/babel-plugin-styled-components#readme

else
npm run build
exec gatsby serve --host 0.0.0.0
exec npm run build-and-start-prod -p 9000
Copy link
Contributor Author

Choose a reason for hiding this comment

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

do prod build and serve


const DatasetUploadToast = Toaster.create({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.create() actually queries and inserts a new element in the DOM, which doesn't work for SSR. So I changed this to only call .create() when .show() is called on the client side

let id = "";
let isPrivate = false;

if (Array.isArray(params)) {
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 logic handles frontend/src/pages/collections/[...params].tsx

uploadedFiles={uploadedFiles}
invalidateCollectionQuery={invalidateCollectionQuery}
onSelect={setSelected}
<>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only change here is adding a wrapper <></> and a <Head /> sibling to <ViewGrid />

@@ -5,19 +5,40 @@
"esModuleInterop": true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

prettier changes and Nextjs config added some more TS related settings

@@ -4,7 +4,7 @@ export AWS_DEFAULT_REGION=us-west-2
export AWS_ACCESS_KEY_ID=nonce
Copy link
Contributor Author

Choose a reason for hiding this comment

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

prettier change and s/8000/3000

@tihuan tihuan force-pushed the thuang-765-next-js branch 3 times, most recently from 895b589 to 8da4424 Compare February 22, 2021 23:26
},
"devDependencies": {
"@babel/preset-react": "^7.12.13",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these two babel plugins are needed for jest to work in frontend/jest/jest-preprocess.js

@tihuan tihuan force-pushed the thuang-765-next-js branch from 8da4424 to 7fda4a6 Compare February 22, 2021 23:50
@tihuan tihuan changed the title thuang-765-next-js [DRAFT until ECS clusters run on prod after March 13] thuang-765-next-js Feb 22, 2021
@tihuan
Copy link
Contributor Author

tihuan commented Feb 23, 2021

smoke-test is currently failing I think because of the temp local-docker.js config file temporarily setting API_URL to be: "http://backend:5000", which the DNS doesn't resolve properly 🤔

I'll ping Infra team tomorrow about this! Thank you!

@tihuan tihuan force-pushed the thuang-765-next-js branch 3 times, most recently from e93aa34 to 7b829be Compare March 1, 2021 20:04
});

await Promise.all([
page.waitForNavigation(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need to wait for navigation before asserting the URL. Otherwise this test will be flakey!

@tihuan tihuan force-pushed the thuang-765-next-js branch 4 times, most recently from 0be905b to b330db2 Compare March 25, 2021 23:57
@tihuan tihuan marked this pull request as ready for review March 26, 2021 17:36
@tihuan tihuan requested review from Bento007 and MDunitz March 26, 2021 17:36
@codecov
Copy link

codecov bot commented Mar 26, 2021

Codecov Report

Merging #926 (1ede997) into main (f023c56) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #926   +/-   ##
=======================================
  Coverage   94.28%   94.28%           
=======================================
  Files          73       73           
  Lines        4476     4476           
=======================================
  Hits         4220     4220           
  Misses        256      256           
Flag Coverage Δ
backend 94.28% <100.00%> (ø)
python 94.28% <100.00%> (ø)
unitTest 94.28% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...t/backend/chalice/api_server/test_v1_collection.py 97.08% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f023c56...1ede997. Read the comment docs.

@tihuan tihuan changed the title [DRAFT until ECS clusters run on prod after March 13] thuang-765-next-js thuang-765-next-js Mar 26, 2021
@tihuan tihuan mentioned this pull request Mar 26, 2021
@tihuan tihuan force-pushed the thuang-765-next-js branch from cdd2557 to 8e7b942 Compare March 26, 2021 20:17
@@ -1,3 +1,5 @@
# WARNING: PLEASE MAKE SURE TO KEEP THIS FILE IN SYNC WITH `.dockerignore`
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 warning is very important!! Otherwise RDEV might not work, because . dockerignore might be ignoring things we no longer ignore in .gitignore.

In our case, I updated .gitignore to stop ignoring public/ folder, because Next.js uses it to build the app, but Gatsby used to require us to ignore that folder. But I didn't update .dockerignore accordingly, which caused RDEV deploy to not work partially

# runs `npm run build && npm run serve` under the hood,
# so we need to pass `-- -p 9000` to `npm run serve`, which
# will then call `next start -p 9000` correctly
exec npm run build-and-start-prod -- -- -p 9000
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 basically tells Next.js to run on port 9000

@@ -45,7 +45,11 @@ async function fetchCollection(
_: unknown,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

small update to collection queries to be more resilient to unexpected input

@@ -1,6 +1,6 @@
import { Button, H6, Intent } from "@blueprintjs/core";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Start using next/router

return (
<LogoWrapper data-test-id="logo">
<StyledLogo size={small ? 100 : undefined} src={String(logo)} />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need StyledLogo anymore, since we only have one size for logo

@@ -1,5 +1,6 @@
const configs = {
API_URL: "https://api.cellxgene.dev.single-cell.czi.technology",
SENTRY_DEPLOYMENT_ENVIRONMENT: "development",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

setting up Sentry to capture CSP violation. However, this is not set up to capture build info like Explorer does at the moment

<link
rel="manifest"
href="/site.webmanifest"
crossOrigin="use-credentials"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need crossOrigin here in order to send cookies along with the request to prevent redev from blocking and redirecting the request to Okta. Thanks to @jgadling for finding this solution 🎉

https://chanzuckerbergteam.slack.com/archives/C01C310V70X/p1616795763052000?thread_ts=1616795713.051900&cid=C01C310V70X

@tihuan tihuan requested review from seve and removed request for Bento007 March 29, 2021 19:56
Copy link
Contributor

@seve seve left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -1,4 +1,4 @@
import { memoize } from "lodash-es";
import memoize from "lodash/memoize";
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥 🌲

>
{name}
</CollectionTitleText>
<Link href={`/collections/${id}${isPrivate ? "/private" : ""}`}>
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be useful so we don't need to have redudent hrefs jsx-eslint/eslint-plugin-jsx-a11y#402 (comment)

@tihuan tihuan force-pushed the thuang-765-next-js branch from 56932a4 to 16bcf03 Compare March 29, 2021 21:32
@tihuan tihuan merged commit d7bc0c2 into main Mar 29, 2021
@tihuan tihuan deleted the thuang-765-next-js branch March 29, 2021 23:48
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