Skip to content

Commit

Permalink
Merge branch 'canary' into feat/create-next-app-pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed Mar 3, 2022
2 parents 4a53801 + 81c50f4 commit 906494b
Show file tree
Hide file tree
Showing 91 changed files with 964 additions and 386 deletions.
5 changes: 3 additions & 2 deletions errors/react-hydration-error.md
Expand Up @@ -41,8 +41,9 @@ Common causes with css-in-js libraries:

- When using Styled Components / Emotion
- When css-in-js libraries are not set up for pre-rendering (SSR/SSG) it will often lead to a hydration mismatch. In general this means the application has to follow the Next.js example for the library. For example if `pages/_document` is missing and the Babel plugin is not added.
- Possible fix for Styled Components: https://github.com/vercel/next.js/tree/canary/examples/with-styled-components
- If you want to leverage Styled Components with the new Next.js Compiler in Next.js 12 there is an [experimental flag available](https://github.com/vercel/next.js/discussions/30174#discussion-3643870)
- Possible fix for Styled Components:
- If you want to leverage Styled Components with SWC in Next.js 12.1+ you need to [add it to your Next.js config under compiler options](https://nextjs.org/docs/advanced-features/compiler#styled-components): https://github.com/vercel/next.js/tree/canary/examples/with-styled-components
- If you want to use Styled Components with Babel, you need `pages/_document` and the Babel plugin: https://github.com/vercel/next.js/tree/canary/examples/with-styled-components-babel
- Possible fix for Emotion: https://github.com/vercel/next.js/tree/canary/examples/with-emotion
- When using other css-in-js libraries
- Similar to Styled Components / Emotion css-in-js libraries generally need configuration specified in their examples in the [examples directory](https://github.com/vercel/next.js/tree/canary/examples)
Expand Down
4 changes: 2 additions & 2 deletions examples/cms-wordpress/components/more-stories.js
Expand Up @@ -11,9 +11,9 @@ export default function MoreStories({ posts }) {
<PostPreview
key={node.slug}
title={node.title}
coverImage={node.featuredImage?.node}
coverImage={node.featuredImage}
date={node.date}
author={node.author?.node}
author={node.author}
slug={node.slug}
excerpt={node.excerpt}
/>
Expand Down
28 changes: 9 additions & 19 deletions examples/cms-wordpress/lib/api.js
Expand Up @@ -70,18 +70,14 @@ export async function getAllPostsForHome(preview) {
slug
date
featuredImage {
node {
sourceUrl
}
sourceUrl
}
author {
node {
name
firstName
lastName
avatar {
url
}
name
firstName
lastName
avatar {
url
}
}
}
Expand Down Expand Up @@ -125,14 +121,10 @@ export async function getPostAndMorePosts(slug, preview, previewData) {
slug
date
featuredImage {
node {
sourceUrl
}
sourceUrl
}
author {
node {
...AuthorFields
}
...AuthorFields
}
categories {
edges {
Expand Down Expand Up @@ -164,9 +156,7 @@ export async function getPostAndMorePosts(slug, preview, previewData) {
excerpt
content
author {
node {
...AuthorFields
}
...AuthorFields
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions examples/cms-wordpress/next.config.js
@@ -0,0 +1,8 @@
module.exports = {
images: {
domains: [
// "[yourapp].wpengine.com" (Update this to be your Wordpress application name in order to load images connected to your posts)
'secure.gravatar.com',
],
},
}
5 changes: 3 additions & 2 deletions examples/cms-wordpress/pages/index.js
Expand Up @@ -22,9 +22,9 @@ export default function Index({ allPosts: { edges }, preview }) {
{heroPost && (
<HeroPost
title={heroPost.title}
coverImage={heroPost.featuredImage?.node}
coverImage={heroPost.featuredImage}
date={heroPost.date}
author={heroPost.author?.node}
author={heroPost.author}
slug={heroPost.slug}
excerpt={heroPost.excerpt}
/>
Expand All @@ -38,6 +38,7 @@ export default function Index({ allPosts: { edges }, preview }) {

export async function getStaticProps({ preview = false }) {
const allPosts = await getAllPostsForHome(preview)

return {
props: { allPosts, preview },
}
Expand Down
6 changes: 3 additions & 3 deletions examples/cms-wordpress/pages/posts/[slug].js
Expand Up @@ -36,14 +36,14 @@ export default function Post({ post, posts, preview }) {
</title>
<meta
property="og:image"
content={post.featuredImage?.node?.sourceUrl}
content={post.featuredImage?.sourceUrl}
/>
</Head>
<PostHeader
title={post.title}
coverImage={post.featuredImage?.node}
coverImage={post.featuredImage}
date={post.date}
author={post.author?.node}
author={post.author}
categories={post.categories}
/>
<PostBody content={post.content} />
Expand Down
File renamed without changes.
34 changes: 34 additions & 0 deletions examples/with-styled-components-babel/.gitignore
@@ -0,0 +1,34 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
29 changes: 29 additions & 0 deletions examples/with-styled-components-babel/README.md
@@ -0,0 +1,29 @@
# Example app with styled-components using babel

This example features how you use a different styling solution than [styled-jsx](https://github.com/vercel/styled-jsx) that also supports universal styles. That means we can serve the required styles for the first render within the HTML and then load the rest in the client. In this case we are using [styled-components](https://github.com/styled-components/styled-components).

For this purpose we are extending the `<Document />` and injecting the server side rendered styles into the `<head>`, and also adding the `babel-plugin-styled-components` (which is required for server side rendering). Additionally we set up a global [theme](https://www.styled-components.com/docs/advanced#theming) for styled-components using NextJS custom [`<App>`](https://nextjs.org/docs/advanced-features/custom-app) component.

## Preview

Preview the example live on [StackBlitz](http://stackblitz.com/):

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-styled-components-babel)

## Deploy your own

Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-styled-components-babel&project-name=with-styled-components-babel&repository-name=with-styled-components-babel)

## How to use

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:

```bash
npx create-next-app --example with-styled-components-babel with-styled-components-babel-app
# or
yarn create next-app --example with-styled-components-babel with-styled-components-babel-app
```

Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
18 changes: 18 additions & 0 deletions examples/with-styled-components-babel/package.json
@@ -0,0 +1,18 @@
{
"private": true,
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-is": "^17.0.2",
"styled-components": "^5.2.3"
},
"devDependencies": {
"babel-plugin-styled-components": "^1.12.0"
}
}
26 changes: 26 additions & 0 deletions examples/with-styled-components-babel/pages/_app.js
@@ -0,0 +1,26 @@
import { createGlobalStyle, ThemeProvider } from 'styled-components'

const GlobalStyle = createGlobalStyle`
body {
margin: 0;
padding: 0;
box-sizing: border-box;
}
`

const theme = {
colors: {
primary: '#0070f3',
},
}

export default function App({ Component, pageProps }) {
return (
<>
<GlobalStyle />
<ThemeProvider theme={theme}>
<Component {...pageProps} />
</ThemeProvider>
</>
)
}
10 changes: 10 additions & 0 deletions examples/with-styled-components-babel/pages/index.js
@@ -0,0 +1,10 @@
import styled from 'styled-components'

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

export default function Home() {
return <Title>My page</Title>
}
4 changes: 3 additions & 1 deletion examples/with-styled-components/README.md
Expand Up @@ -2,7 +2,9 @@

This example features how you use a different styling solution than [styled-jsx](https://github.com/vercel/styled-jsx) that also supports universal styles. That means we can serve the required styles for the first render within the HTML and then load the rest in the client. In this case we are using [styled-components](https://github.com/styled-components/styled-components).

For this purpose we are extending the `<Document />` and injecting the server side rendered styles into the `<head>`, and also adding the `babel-plugin-styled-components` (which is required for server side rendering). Additionally we set up a global [theme](https://www.styled-components.com/docs/advanced#theming) for styled-components using NextJS custom [`<App>`](https://nextjs.org/docs/advanced-features/custom-app) component.
This example uses the Rust-based [SWC](https://nextjs.org/docs/advanced-features/compiler#styled-components) in Next.js for better performance than Babel.

Currently, only the `ssr` and `displayName` transforms have been implemented. These two transforms are the main requirement for using `styled-components` in Next.js.

## Preview

Expand Down
10 changes: 10 additions & 0 deletions examples/with-styled-components/next.config.js
@@ -0,0 +1,10 @@
/** @type {import('next').NextConfig} */

const nextConfig = {
reactStrictMode: true,
compiler: {
styledComponents: true,
},
}

module.exports = nextConfig
3 changes: 0 additions & 3 deletions examples/with-styled-components/package.json
Expand Up @@ -11,8 +11,5 @@
"react-dom": "^17.0.2",
"react-is": "^17.0.2",
"styled-components": "^5.2.3"
},
"devDependencies": {
"babel-plugin-styled-components": "^1.12.0"
}
}
4 changes: 0 additions & 4 deletions examples/with-typescript-styled-components/.babelrc

This file was deleted.

10 changes: 10 additions & 0 deletions examples/with-typescript-styled-components/next.config.js
@@ -0,0 +1,10 @@
/** @type {import('next').NextConfig} */

const nextConfig = {
reactStrictMode: true,
compiler: {
styledComponents: true,
},
}

module.exports = nextConfig
3 changes: 1 addition & 2 deletions examples/with-typescript-styled-components/package.json
Expand Up @@ -17,7 +17,6 @@
"@types/react": "17.0.4",
"@types/react-dom": "17.0.3",
"@types/styled-components": "5.1.9",
"babel-plugin-styled-components": "^1.12.0",
"typescript": "4.2.4"
"typescript": "^4.5.5"
}
}
30 changes: 0 additions & 30 deletions examples/with-typescript-styled-components/pages/_document.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "12.1.1-canary.5"
"version": "12.1.1-canary.6"
}
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -144,9 +144,9 @@
"pretty-ms": "7.0.0",
"random-seed": "0.3.0",
"react": "17.0.2",
"react-18": "npm:react@18.0.0-rc.0",
"react-18": "npm:react@18.0.0-rc.1",
"react-dom": "17.0.2",
"react-dom-18": "npm:react-dom@18.0.0-rc.0",
"react-dom-18": "npm:react-dom@18.0.0-rc.1",
"react-ssr-prepass": "1.0.8",
"relay-compiler": "13.0.2",
"relay-runtime": "13.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "12.1.1-canary.5",
"version": "12.1.1-canary.6",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "12.1.1-canary.5",
"version": "12.1.1-canary.6",
"description": "ESLint configuration used by NextJS.",
"main": "index.js",
"license": "MIT",
Expand All @@ -9,7 +9,7 @@
"directory": "packages/eslint-config-next"
},
"dependencies": {
"@next/eslint-plugin-next": "12.1.1-canary.5",
"@next/eslint-plugin-next": "12.1.1-canary.6",
"@rushstack/eslint-patch": "1.0.8",
"@typescript-eslint/parser": "5.0.0",
"eslint-import-resolver-node": "0.3.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "12.1.1-canary.5",
"version": "12.1.1-canary.6",
"description": "ESLint plugin for NextJS.",
"main": "lib/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "12.1.1-canary.5",
"version": "12.1.1-canary.6",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down

0 comments on commit 906494b

Please sign in to comment.