Skip to content
This repository was archived by the owner on Sep 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
{
"presets": ["next/babel"],
"presets": [
"next/babel"
],
"plugins": [
[
"module-resolver",
{
"root": ["."],
"root": [
"."
],
"alias": {
"client": "./client",
"server": "./server"
"server": "./server",
"styles": "./styles"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

will styles/ ever be accessed from server/? if not, can we put it in client/?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I forsee this to be the place where we might (in the future) add some styles that need to be rendered on the server, which is why I left this as it's own folder (I had to do this for Bootstrap on my personal project just this week). Considering that styles are oftentimes implemented on both sides of the boundary, I would recommend we leave it here. Thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since next.js is taking care of SSR and our current setup has us grabbing components out of client/ from pages/ where the SSR magic happens, I think it makes sense for styles to also be in client/. I haven't toyed around with any advanced config around SSR though so I'm not sure if we'd need to import anything from styles/ to the server/ directory. Would you happen to know of any instances where it would be needed to do such an import?

@nik-john nik-john Oct 22, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@timmyichen Sorry - I've been swamped all day. I'm just seeing this. So the scenario I was talking about is when we need to inline critical above-the-fold CSS like mentioned here. Lighthouse throws warnings when moderate sized CSS files are loaded via link as CSS imports are render-blocking. An instance of this is if we are using a light enough Grid/Flex framework, it might make sense to inline it.

Here are some instances where we do inlining: 1, 2, 3

The way we are hooking up styled-components on this PR is also by inlining the styles although it isn't as straight forward as that.

}
}
],
[
"styled-components",
{
"ssr": true,
"displayName": true,
"preprocess": false
}
]
]
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
}

12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ We are planning to use the following tools:
* [Node.js](https://nodejs.org) / [Express](https://expressjs.com) for our backend using JavaScript/TypeScript
* [Postgres](https://www.postgresql.org) with [Sequelize ORM](https://sequelize.org)
* [Elasticsearch](https://www.elastic.co/what-is/elasticsearch)
* A [React](https://reactjs.org) frontend using:
* [JavaScript/TypeScript](https://www.typescriptlang.org/index.html#download-links)
* [CSS](https://www.w3.org/Style/CSS/) (not Sass)
* Functional Components with [Hooks](https://reactjs.org/docs/hooks-intro.html)
* [Next.js](https://nextjs.org/) for server-side rendering
* [Next.js](https://nextjs.org/) for both client and server-side rendering of the frontend (NextJS is based on [React](https://reactjs.org))
* [JavaScript/TypeScript](https://www.typescriptlang.org/index.html#download-links)
* [Styled Components](https://www.styled-components.com) for styling.
* Functional Components with [Hooks](https://reactjs.org/docs/hooks-intro.html)

A lot of people know these tools, and they're proven to work well at scale.

We are considering using a tool like [Next.js](https://nextjs.org) to get up and running faster.
A lot of people know these tools, and they're proven to work well at scale.

We will focus on building an open API first. Then developers can use the API to build their own mobile clients and voice interface clients.

Expand Down
115 changes: 109 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"homepage": "https://github.com/freeCodeCamp/chapter#readme",
"dependencies": {
"babel-plugin-module-resolver": "^3.2.0",
"babel-plugin-styled-components": "^1.10.6",
"express": "^4.17.1",
"express-async-handler": "^1.1.4",
"express-response-errors": "^1.0.4",
Expand All @@ -47,6 +48,7 @@
"next": "^9.1.1",
"react": "^16.10.2",
"react-dom": "^16.10.2",
"styled-components": "^4.4.0",
"ts-node": "^8.4.1",
"typescript": "^3.6.4"
},
Expand Down
15 changes: 15 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import App from 'next/app';
import React from 'react';
import { ThemeProvider } from 'styled-components';
import theme from 'styles/theme';

export default class MyApp extends App {
render() {
const { Component, pageProps } = this.props;
return (
<ThemeProvider theme={theme}>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

are we going to provide dark theme in the future?

@srprkr srprkr Oct 23, 2019 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If it makes sense with CSS in JS, I'd recommend with this media query prefers-color-scheme:dark {}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Browser coverage is very less for prefers-color-scheme:dark {}
image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's something we can look at - one of the advantages of using a global theme is that it's one source of truth for the entire application and whitelabelling and re-theming are a walk in the park

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Wow, in that case, I'd favor something with more adoption then; like css vars you could change with a toggle or something. I'm sure ThemeProvider is fine too.

<Component {...pageProps} />
</ThemeProvider>
);
}
}
29 changes: 29 additions & 0 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Document from 'next/document';
import { ServerStyleSheet } from 'styled-components';

export default class MyDocument extends Document {
static async getInitialProps(ctx) {
const sheet = new ServerStyleSheet();
const originalRenderPage = ctx.renderPage;

try {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: App => props => sheet.collectStyles(<App {...props} />),
});

const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
styles: (
<>
{initialProps.styles}
{sheet.getStyleElement()}
</>
),
};
} finally {
sheet.seal();
}
}
}
15 changes: 7 additions & 8 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import * as React from 'react';
import SomeComponent from 'client/components/SomeComponent';
import styled from 'styled-components';

const Title = styled.h1`
font-size: 50px;
color: ${({ theme }) => theme.colors.primary};
`;

const Index = () => {
return (
<div>
this is a page!
<Title>This is a page with a Styled Title!</Title>
<SomeComponent />
<style jsx>{`
div {
width: 100vw;
height: 100vh;
background: skyblue;
}
`}</style>
</div>
);
};
Expand Down
7 changes: 7 additions & 0 deletions styles/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const theme = {
colors: {
primary: '#0070f3',
},
};

export default theme;