Skip to content

Commit

Permalink
Merge branch 'canary' into swc-up-11
Browse files Browse the repository at this point in the history
  • Loading branch information
padmaia committed Feb 3, 2022
2 parents f547618 + b772513 commit 0676bbe
Show file tree
Hide file tree
Showing 225 changed files with 4,385 additions and 1,139 deletions.
20 changes: 20 additions & 0 deletions docs/advanced-features/compiler.md
Expand Up @@ -94,6 +94,26 @@ const customJestConfig = {
module.exports = createJestConfig(customJestConfig)
```

### Relay

To enable [Relay](https://relay.dev/) support:

```js
// next.config.js
module.exports = {
experimental: {
relay: {
// This should match relay.config.js
src: './',
artifactDirectory: './__generated__'
language: 'typescript',
},
},
}
```

NOTE: In Next.js all JavaScript files in `pages` directory are considered routes. So, for `relay-compiler` you'll need to specify `artifactDirectory` configuration settings outside of the `pages`, otherwise `relay-compiler` will generate files next to the source file in the `__generated__` directory, and this file will be considered a route, which will break production builds.

### Remove React Properties

Allows to remove JSX properties. This is often used for testing. Similar to `babel-plugin-react-remove-properties`.
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced-features/custom-app.md
Expand Up @@ -38,14 +38,14 @@ export default MyApp

The `Component` prop is the active `page`, so whenever you navigate between routes, `Component` will change to the new `page`. Therefore, any props you send to `Component` will be received by the `page`.

`pageProps` is an object with the initial props that were preloaded for your page by one of our [data fetching methods](/docs/basic-features/data-fetching/index.md), otherwise it's an empty object.
`pageProps` is an object with the initial props that were preloaded for your page by one of our [data fetching methods](/docs/basic-features/data-fetching/overview.md), otherwise it's an empty object.

### Caveats

- If your app is running and you added a custom `App`, you'll need to restart the development server. Only required if `pages/_app.js` didn't exist before.
- Adding a custom [`getInitialProps`](/docs/api-reference/data-fetching/get-initial-props.md) in your `App` will disable [Automatic Static Optimization](/docs/advanced-features/automatic-static-optimization.md) in pages without [Static Generation](/docs/basic-features/data-fetching/get-static-props.md).
- When you add `getInitialProps` in your custom app, you must `import App from "next/app"`, call `App.getInitialProps(appContext)` inside `getInitialProps` and merge the returned object into the return value.
- `App` currently does not support Next.js [Data Fetching methods](/docs/basic-features/data-fetching/index.md) like [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md) or [`getServerSideProps`](/docs/basic-features/data-fetching/get-server-side-props.md).
- `App` currently does not support Next.js [Data Fetching methods](/docs/basic-features/data-fetching/overview.md) like [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md) or [`getServerSideProps`](/docs/basic-features/data-fetching/get-server-side-props.md).

### TypeScript

Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-features/custom-document.md
Expand Up @@ -54,7 +54,7 @@ The `ctx` object is equivalent to the one received in [`getInitialProps`](/docs/
- `Document` is only rendered in the server, event handlers like `onClick` won't work.
- React components outside of `<Main />` will not be initialized by the browser. Do _not_ add application logic here or custom CSS (like `styled-jsx`). If you need shared components in all your pages (like a menu or a toolbar), take a look at the [`App`](/docs/advanced-features/custom-app.md) component instead.
- `Document`'s `getInitialProps` function is not called during client-side transitions, nor when a page is [statically optimized](/docs/advanced-features/automatic-static-optimization.md).
- `Document` currently does not support Next.js [Data Fetching methods](/docs/basic-features/data-fetching/index.md) like [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md) or [`getServerSideProps`](/docs/basic-features/data-fetching/get-server-side-props.md).
- `Document` currently does not support Next.js [Data Fetching methods](/docs/basic-features/data-fetching/overview.md) like [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md) or [`getServerSideProps`](/docs/basic-features/data-fetching/get-server-side-props.md).

## Customizing `renderPage`

Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-features/custom-error-page.md
Expand Up @@ -97,4 +97,4 @@ If you have a custom `Error` component be sure to import that one instead. `next

### Caveats

- `Error` currently does not support Next.js [Data Fetching methods](/docs/basic-features/data-fetching.md) like [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) or [`getServerSideProps`](/docs/basic-features/data-fetching.md#getserversideprops-server-side-rendering).
- `Error` does not currently support Next.js [Data Fetching methods](/docs/basic-features/data-fetching.md) like [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md) or [`getServerSideProps`](/docs/basic-features/data-fetching/get-server-side-props.md).
9 changes: 6 additions & 3 deletions docs/advanced-features/custom-server.md
Expand Up @@ -29,7 +29,10 @@ const { parse } = require('url')
const next = require('next')

const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const hostname = 'localhost'
const port = 3000
// when using middleware `hostname` and `port` must be provided below
const app = next({ dev, hostname, port })
const handle = app.getRequestHandler()

app.prepare().then(() => {
Expand All @@ -46,9 +49,9 @@ app.prepare().then(() => {
} else {
handle(req, res, parsedUrl)
}
}).listen(3000, (err) => {
}).listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://${hostname}:${port}`)
})
})
```
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced-features/preview-mode.md
Expand Up @@ -27,7 +27,7 @@ description: Next.js has the preview mode for statically generated pages. You ca
</ul>
</details>

In the [Pages documentation](/docs/basic-features/pages.md) and the [Data Fetching documentation](/docs/basic-features/data-fetching/index.md), we talked about how to pre-render a page at build time (**Static Generation**) using `getStaticProps` and `getStaticPaths`.
In the [Pages documentation](/docs/basic-features/pages.md) and the [Data Fetching documentation](/docs/basic-features/data-fetching/overview.md), we talked about how to pre-render a page at build time (**Static Generation**) using `getStaticProps` and `getStaticPaths`.

Static Generation is useful when your pages fetch data from a headless CMS. However, it’s not ideal when you’re writing a draft on your headless CMS and want to **preview** the draft immediately on your page. You’d want Next.js to render these pages at **request time** instead of build time and fetch the draft content instead of the published content. You’d want Next.js to bypass Static Generation only for this specific case.

Expand Down Expand Up @@ -230,7 +230,7 @@ This ensures that the bypass cookie can’t be guessed.
The following pages might also be useful.

<div class="card">
<a href="/docs/basic-features/data-fetching/index.md">
<a href="/docs/basic-features/data-fetching/overview.md">
<b>Data Fetching:</b>
<small>Learn more about data fetching in Next.js.</small>
</a>
Expand Down
21 changes: 20 additions & 1 deletion docs/advanced-features/security-headers.md
Expand Up @@ -113,10 +113,29 @@ This header helps prevent cross-site scripting (XSS), clickjacking and other cod

You can read about the many different CSP options [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP).

You can add Content Security Policy directives using a template string.

```jsx
// Before defining your Security Headers
// add Content Security Policy directives using a template string.

const ContentSecurityPolicy = `
default-src 'self';
script-src 'self';
child-src example.com;
style-src 'self' example.com;
font-src 'self';
`
```

When a directive uses a keyword such as `self`, wrap it in single quotes `''`.

In the header's value, replace the new line with an empty string.

```jsx
{
key: 'Content-Security-Policy',
value: // Your CSP Policy
value: ContentSecurityPolicy.replace(/\s{2,}/g, ' ').trim()
}
```

Expand Down
4 changes: 3 additions & 1 deletion docs/advanced-features/using-mdx.md
Expand Up @@ -46,6 +46,8 @@ The following steps outline how to setup `@next/mdx` in your Next.js project:
options: {
remarkPlugins: [],
rehypePlugins: [],
// If you use `MDXProvider`, uncomment the following line.
// providerImportSource: "@mdx-js/react",
},
})
module.exports = withMDX({
Expand Down Expand Up @@ -153,7 +155,7 @@ The above generates the following `HTML`:
</ul>
```

When you want to style your own elements to give a custom feel to your website or application, you can pass in shortcodes. These are your own custom components that map to `HTML` elements. To do this you use the `MDXProvider` and pass a components object as a prop. Each object key in the components object maps to a `HTML` element name.
When you want to style your own elements to give a custom feel to your website or application, you can pass in shortcodes. These are your own custom components that map to `HTML` elements. To do this you use the `MDXProvider` and pass a components object as a prop. Each object key in the components object maps to a `HTML` element name. You also need to specify `providerImportSource: "@mdx-js/react"` in `next.config.js`.

```jsx
// pages/index.js
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/data-fetching/get-initial-props.md
Expand Up @@ -119,7 +119,7 @@ export default class Page extends React.Component<Props> {
For more information on what to do next, we recommend the following sections:

<div class="card">
<a href="/docs/basic-features/data-fetching/index.md">
<a href="/docs/basic-features/data-fetching/overview.md">
<b>Data Fetching:</b>
<small>Learn more about data fetching in Next.js.</small>
</a>
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/data-fetching/get-server-side-props.md
Expand Up @@ -144,7 +144,7 @@ export default Page
For more information on what to do next, we recommend the following sections:

<div class="card">
<a href="/docs/basic-features/data-fetching/index.md">
<a href="/docs/basic-features/data-fetching/overview.md">
<b>Data Fetching:</b>
<small>Learn more about data fetching in Next.js.</small>
</a>
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/data-fetching/get-static-props.md
Expand Up @@ -237,7 +237,7 @@ export default Blog
For more information on what to do next, we recommend the following sections:

<div class="card">
<a href="/docs/basic-features/data-fetching/index.md">
<a href="/docs/basic-features/data-fetching/overview.md">
<b>Data Fetching:</b>
<small>Learn more about data fetching in Next.js.</small>
</a>
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/next.config.js/exportPathMap.md
Expand Up @@ -40,7 +40,7 @@ module.exports = {
}
```

Note: the `query` field in `exportPathMap` cannot be used with [automatically statically optimized pages](/docs/advanced-features/automatic-static-optimization) or [`getStaticProps` pages](https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation) as they are rendered to HTML files at build-time and additional query information cannot be provided during `next export`.
Note: the `query` field in `exportPathMap` cannot be used with [automatically statically optimized pages](/docs/advanced-features/automatic-static-optimization) or [`getStaticProps` pages](/docs/basic-features/data-fetching/get-static-props.md) as they are rendered to HTML files at build-time and additional query information cannot be provided during `next export`.

The pages will then be exported as HTML files, for example, `/about` will become `/about.html`.

Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/next.config.js/headers.md
Expand Up @@ -376,7 +376,7 @@ module.exports = {

### Cache-Control

Cache-Control headers set in next.config.js will be overwritten in production to ensure that static assets can be cached effectively. If you need to revalidate the cache of a page that has been [statically generated](https://nextjs.org/docs/basic-features/pages#static-generation-recommended), you can do so by setting `revalidate` in the page's [`getStaticProps`](https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation) function.
Cache-Control headers set in next.config.js will be overwritten in production to ensure that static assets can be cached effectively. If you need to revalidate the cache of a page that has been [statically generated](https://nextjs.org/docs/basic-features/pages#static-generation-recommended), you can do so by setting `revalidate` in the page's [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md) function.

## Related

Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/next/router.md
Expand Up @@ -42,7 +42,7 @@ export default ActiveLink
The following is the definition of the `router` object returned by both [`useRouter`](#useRouter) and [`withRouter`](#withRouter):

- `pathname`: `String` - Current route. That is the path of the page in `/pages`, the configured `basePath` or `locale` is not included.
- `query`: `Object` - The query string parsed to an object. It will be an empty object during prerendering if the page doesn't have [data fetching requirements](/docs/basic-features/data-fetching/index.md). Defaults to `{}`
- `query`: `Object` - The query string parsed to an object. It will be an empty object during prerendering if the page doesn't have [data fetching requirements](/docs/basic-features/data-fetching/overview.md). Defaults to `{}`
- `asPath`: `String` - The path (including the query) shown in the browser without the configured `basePath` or `locale`.
- `isFallback`: `boolean` - Whether the current page is in [fallback mode](/docs/api-reference/data-fetching/get-static-paths.md#fallback-pages).
- `basePath`: `String` - The active [basePath](/docs/api-reference/next.config.js/basepath.md) (if enabled).
Expand Down
4 changes: 3 additions & 1 deletion docs/api-routes/api-middlewares.md
Expand Up @@ -34,7 +34,9 @@ export const config = {

The `api` object includes all configs available for API routes.

`bodyParser` Enables body parsing, you can disable it if you want to consume it as a `Stream`:
`bodyParser` is automatically enabled. If you want to consume the body as a `Stream` or with [`raw-body`](https://www.npmjs.com/package/raw-body), you can set this to `false`.

One use case for disabling the automatic `bodyParsing` is to allow you to verify the raw body of a **webhook** request, for example [from GitHub](https://docs.github.com/en/developers/webhooks-and-events/webhooks/securing-your-webhooks#validating-payloads-from-github).

```js
export const config = {
Expand Down
4 changes: 2 additions & 2 deletions docs/authentication.md
Expand Up @@ -8,7 +8,7 @@ Authentication verifies who a user is, while authorization controls what a user

## Authentication Patterns

The first step to identifying which authentication pattern you need is understanding the [data-fetching strategy](/docs/basic-features/data-fetching/index.md) you want. We can then determine which authentication providers support this strategy. There are two main patterns:
The first step to identifying which authentication pattern you need is understanding the [data-fetching strategy](/docs/basic-features/data-fetching/overview.md) you want. We can then determine which authentication providers support this strategy. There are two main patterns:

- Use [static generation](/docs/basic-features/pages.md#static-generation-recommended) to server-render a loading state, followed by fetching user data client-side.
- Fetch user data [server-side](/docs/basic-features/pages.md#server-side-rendering) to eliminate a flash of unauthenticated content.
Expand Down Expand Up @@ -156,7 +156,7 @@ For more information on what to do next, we recommend the following sections:
</div>

<div class="card">
<a href="/docs/basic-features/data-fetching/index.md">
<a href="/docs/basic-features/data-fetching/overview.md">
<b>Data Fetching:</b>
<small>Learn more about data fetching in Next.js.</small>
</a>
Expand Down
@@ -1,5 +1,5 @@
---
description: 'Data fetching in Next.js allows you to render your content in different ways, depending on your applications use case. These include pre-rendering with server-side rendering or static-site generation, and incremental static regeneration. Learn how to manage your application data in Next.js.'
description: 'Next.js allows you to fetch data in multiple ways, with pre-rendering, server-side rendering or static-site generation, and incremental static regeneration. Learn how to manage your application data in Next.js.'
---

# Data Fetching Overview
Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/environment-variables.md
Expand Up @@ -30,7 +30,7 @@ DB_USER=myuser
DB_PASS=mypassword
```

This loads `process.env.DB_HOST`, `process.env.DB_USER`, and `process.env.DB_PASS` into the Node.js environment automatically allowing you to use them in [Next.js data fetching methods](/docs/basic-features/data-fetching/index.md) and [API routes](/docs/api-routes/introduction.md).
This loads `process.env.DB_HOST`, `process.env.DB_USER`, and `process.env.DB_PASS` into the Node.js environment automatically allowing you to use them in [Next.js data fetching methods](/docs/basic-features/data-fetching/overview.md) and [API routes](/docs/api-routes/introduction.md).

For example, using [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md):

Expand Down
2 changes: 2 additions & 0 deletions docs/basic-features/font-optimization.md
Expand Up @@ -78,6 +78,8 @@ Automatic Webfont Optimization currently supports Google Fonts and Typekit with
See [Google Font Display](https://nextjs.org/docs/messages/google-font-display) for more information.
> **Note**: Font Optimization does not currently support self-hosted fonts.
## Disabling Optimization
If you do not want Next.js to optimize your fonts, you can opt-out.
Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/pages.md
Expand Up @@ -263,7 +263,7 @@ We've discussed two forms of pre-rendering for Next.js.
We recommend you to read the following sections next:

<div class="card">
<a href="/docs/basic-features/data-fetching/index.md">
<a href="/docs/basic-features/data-fetching/overview.md">
<b>Data Fetching:</b>
<small>Learn more about data fetching in Next.js.</small>
</a>
Expand Down
4 changes: 3 additions & 1 deletion docs/basic-features/typescript.md
Expand Up @@ -37,7 +37,9 @@ Next.js will automatically configure this file with default values. Providing yo

You can also provide a relative path to a tsconfig.json file by setting `typescript.tsconfigPath` prop inside your `next.config.js` file.

> Next.js uses Babel to handle TypeScript, which has some [caveats](https://babeljs.io/docs/en/babel-plugin-transform-typescript#caveats), and some [compiler options are handled differently](https://babeljs.io/docs/en/babel-plugin-transform-typescript#typescript-compiler-options).
Starting in `v12.0.0`, Next.js uses [SWC](https://nextjs.org/docs/advanced-features/compiler) by default to compile TypeScript and TSX for faster builds.

> Next.js will use Babel to handle TypeScript if `.babelrc` is present. This has some [caveats](https://babeljs.io/docs/en/babel-plugin-transform-typescript#caveats) and some [compiler options are handled differently](https://babeljs.io/docs/en/babel-plugin-transform-typescript#typescript-compiler-options).
Then, run `next` (normally `npm run dev` or `yarn dev`) and Next.js will guide you through the installation of the required packages to finish the setup:

Expand Down

0 comments on commit 0676bbe

Please sign in to comment.