Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/canary' into with-mongodb-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Aug 25, 2021
2 parents d70a26a + 877f982 commit 26fbb3c
Show file tree
Hide file tree
Showing 222 changed files with 79,105 additions and 75,338 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ examples/with-typescript-eslint-jest/**
examples/with-kea/**
examples/with-custom-babel-config/**
examples/with-flow/**
examples/with-jest/**
examples/with-mobx-state-tree/**
examples/with-mobx/**
packages/next/bundles/webpack/packages/*.runtime.js
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ jobs:
./packages/next/native/next-swc.linux-x64-gnu.node
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
- run: ./scripts/check-pre-compiled.sh
env:
NODE_OPTIONS: '--max_old_space_size=4096'
if: ${{needs.build.outputs.docsChange != 'docs only change'}}

testUnit:
Expand All @@ -106,7 +104,7 @@ jobs:
path: ./*
key: ${{ github.sha }}

- run: node run-tests.js --timings --type unit -g 1/1
- run: node run-tests.js --type unit
if: ${{needs.build.outputs.docsChange != 'docs only change'}}

testIntegration:
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ stages:
path: $(System.DefaultWorkingDirectory)
displayName: Cache Build
- script: |
node run-tests.js -g 1/1 --timings --azure --type unit
node run-tests.js --type unit
displayName: 'Run tests'
# TODO: investigate re-enabling when stability matches running in
# tests in ubuntu environment
Expand Down
Empty file removed data.sqlite
Empty file.
43 changes: 26 additions & 17 deletions docs/advanced-features/i18n-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,30 @@ Next.js doesn't know about variants of a page so it's up to you to add the `href

> Note that Internationalized Routing does not integrate with [`next export`](/docs/advanced-features/static-html-export.md) as `next export` does not leverage the Next.js routing layer. Hybrid Next.js applications that do not use `next export` are fully supported.
### Dynamic Routes and `getStaticProps` Pages

For pages using `getStaticProps` with [Dynamic Routes](/docs/routing/dynamic-routes.md), all locale variants of the page desired to be prerendered need to be returned from [`getStaticPaths`](/docs/basic-features/data-fetching.md#getstaticpaths-static-generation). Along with the `params` object returned for `paths`, you can also return a `locale` field specifying which locale you want to render. For example:

```js
// pages/blog/[slug].js
export const getStaticPaths = ({ locales }) => {
return {
paths: [
// if no `locale` is provided only the defaultLocale will be generated
{ params: { slug: 'post-1' }, locale: 'en-US' },
{ params: { slug: 'post-1' }, locale: 'fr' },
],
fallback: true,
}
}
```

For [Automatically Statically Optimized](/docs/advanced-features/automatic-static-optimization.md) and non-dynamic `getStaticProps` pages, **a version of the page will be generated for each locale**. This is important to consider because it can increase build times depending on how many locales are configured inside `getStaticProps`.

For example, if you have 50 locales configured with 10 non-dynamic pages using `getStaticProps`, this means `getStaticProps` will be called 500 times. 50 versions of the 10 pages will be generated during each build.

To decrease the build time of dynamic pages with `getStaticProps`, use a [`fallback` mode](https://nextjs.org/docs/basic-features/data-fetching#fallback-true). This allows you to return only the most popular paths and locales from `getStaticPaths` for prerendering during the build. Then, Next.js will build the remaining pages at runtime as they are requested.

### Automatically Statically Optimized Pages

For pages that are [automatically statically optimized](/docs/advanced-features/automatic-static-optimization.md), a version of the page will be generated for each locale.
Expand Down Expand Up @@ -265,24 +289,9 @@ export async function getStaticProps({ locale }) {
}
```

### Dynamic getStaticProps Pages

For dynamic `getStaticProps` pages, any locale variants of the page that is desired to be prerendered needs to be returned from [`getStaticPaths`](/docs/basic-features/data-fetching.md#getstaticpaths-static-generation). Along with the `params` object that can be returned for the `paths`, you can also return a `locale` field specifying which locale you want to render. For example:

```js
// pages/blog/[slug].js
export const getStaticPaths = ({ locales }) => {
return {
paths: [
{ params: { slug: 'post-1' }, locale: 'en-US' },
{ params: { slug: 'post-1' }, locale: 'fr' },
],
fallback: true,
}
}
```

## Limits for the i18n config

- `locales`: 100 total locales
- `domains`: 100 total locale domain items

> **Note:** These limits have been added initially to prevent potential [performance issues at build time](#dynamic-routes-and-getStaticProps-pages). We are continuing to evaluate if these limits are sufficient.
33 changes: 15 additions & 18 deletions docs/api-reference/next/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,26 @@ The `<Image />` component optionally accepts the following properties.

### layout

The layout behavior of the image as the viewport changes size. Defaults to
`intrinsic`.
The layout behavior of the image as the viewport changes size.

When `fixed`, the image dimensions will not change as the viewport changes (no
responsiveness) similar to the native `img` element.

When `intrinsic`, the image will scale the dimensions down for smaller viewports
but maintain the original dimensions for larger viewports.

When `responsive`, the image will scale the dimensions down for smaller
viewports and scale up for larger viewports.
Note: the responsive layout may not work correctly if the parent element uses a display value other than `block` such as `display: flex` or `display: grid`.

When `fill`, the image will stretch both width and height to the dimensions of
the parent element, provided the parent element is relative. This is usually paired with the [`objectFit`](#objectFit) property.
Ensure the parent element has `position: relative` in their stylesheet.

Try it out:
| `layout` | Behavior | `srcSet` | `sizes` |
| --------------------- | -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `intrinsic` (default) | Scale *down* to fit width of container, up to image size | `1x``2x` (based on [imageSizes](/docs/basic-features/image-optimization.md#image-sizes)) | N/A |
| `fixed` | Sized to `width` and `height` exactly | `1x``2x` (based on [imageSizes](/docs/basic-features/image-optimization.md#image-sizes)) | N/A |
| `responsive` | Scale to fit width of container | `640w``750w`, ... `2048w``3840w` (based on [imageSizes](/docs/basic-features/image-optimization.md#image-sizes) and [deviceSizes](/docs/basic-features/image-optimization.md#device-sizes)) | `100vw` |
| `fill` | Grow in X and Y axes to fill container | `640w``750w`, ... `2048w``3840w` (based on [imageSizes](/docs/basic-features/image-optimization.md#image-sizes) and [deviceSizes](/docs/basic-features/image-optimization.md#device-sizes)) | `100vw` |

- [Demo the `intrinsic` layout (default)](https://image-component.nextjs.gallery/layout-intrinsic)
- When `intrinsic`, the image will scale the dimensions down for smaller viewports, but maintain the original dimensions for larger viewports.
- [Demo the `fixed` layout](https://image-component.nextjs.gallery/layout-fixed)
- [Demo the `intrinsic` layout](https://image-component.nextjs.gallery/layout-intrinsic)
- When `fixed`, the image dimensions will not change as the viewport changes (no responsiveness) similar to the native `img` element.
- [Demo the `responsive` layout](https://image-component.nextjs.gallery/layout-responsive)
- When `responsive`, the image will scale the dimensions down for smaller viewports and scale up for larger viewports.
- Ensure the parent element uses `display: block` in their stylesheet.
- [Demo the `fill` layout](https://image-component.nextjs.gallery/layout-fill)
- When `fill`, the image will stretch both width and height to the dimensions of the parent element, provided the parent element is relative.
- This is usually paired with the [`objectFit`](#objectFit) property.
- Ensure the parent element has `position: relative` in their stylesheet.
- [Demo background image](https://image-component.nextjs.gallery/background)

### loader
Expand Down
2 changes: 1 addition & 1 deletion docs/api-routes/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ For new projects, you can build your entire API with API Routes. If you have an

## Caveats

- API Routes [do not specify CORS headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS), meaning they are **same-origin only** by default. You can customize such behavior by wrapping the request handler with the [cors middleware](/docs/api-routes/api-middlewares.md#connectexpress-middleware-support).
- API Routes [do not specify CORS headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS), meaning they are **same-origin only** by default. You can customize such behavior by wrapping the request handler with the [CORS middleware](/docs/api-routes/api-middlewares.md#connectexpress-middleware-support).
- API Routes can't be used with [`next export`](/docs/advanced-features/static-html-export.md)

## Related
Expand Down
8 changes: 8 additions & 0 deletions docs/basic-features/eslint.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ Similarly, the `--dir` flag can be used for `next lint`:
next lint --dir pages --dir utils
```

## Caching

To improve performance, information of files processed by ESLint are cached by default. This is stored in `.next/cache` or in your defined [build directory](/docs/api-reference/next.config.js/setting-a-custom-build-directory). If you include any ESLint rules that depend on more than the contents of a single source file and need to disable the cache, use the `--no-cache` flag with `next lint`.

```bash
next lint --no-cache
```

## Disabling Rules

If you would like to modify or disable any rules provided by the supported plugins (`react`, `react-hooks`, `next`), you can directly change them using the `rules` property in your `.eslintrc`:
Expand Down
6 changes: 4 additions & 2 deletions docs/basic-features/font-optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function IndexPage() {
<div>
<Head>
<link
href="https://fonts.googleapis.com/css2?family=Inter"
href="https://fonts.googleapis.com/css2?family=Inter&display=optional"
rel="stylesheet"
/>
</Head>
Expand All @@ -58,7 +58,7 @@ class MyDocument extends Document {
<Html>
<Head>
<link
href="https://fonts.googleapis.com/css2?family=Inter"
href="https://fonts.googleapis.com/css2?family=Inter&display=optional"
rel="stylesheet"
/>
</Head>
Expand All @@ -76,6 +76,8 @@ export default MyDocument
Automatic Webfont Optimization currently supports Google Fonts and Typekit with support for other font providers coming soon. We're also planning to add control over [loading strategies](https://github.com/vercel/next.js/issues/21555) and `font-display` values.
See [Google Font Display](https://nextjs.org/docs/messages/google-font-display) for more information.
## 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/image-optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ If you need a different provider, you can use the [`loader`](/docs/api-reference

> The `next/image` component's default loader is not supported when using [`next export`](/docs/advanced-features/static-html-export.md). However, other loader options will work.
> The `next/image` component's default loader uses the ['squoosh'](https://www.npmjs.com/package/@squoosh/lib) library for image resizing and optimization. This library is quick to install and suitable for a dev server environment. For a production environment, it is strongly recommended that you install the optional [`sharp`](https://www.npmjs.com/package/sharp) library by running `yarn add sharp` in your project directory. If sharp is already installed but can't be resolved you can manually pass the path to it via the `NEXT_SHARP_PATH` environment variable e.g. `NEXT_SHARP_PATH=/tmp/node_modules/sharp`
> The `next/image` component's default loader uses [`squoosh`](https://www.npmjs.com/package/@squoosh/lib) because it is quick to install and suitable for a development environment. When using `next start` in your production environment, it is strongly recommended that you install [`sharp`](https://www.npmjs.com/package/sharp) by running `yarn add sharp` in your project directory. This is not necessary for Vercel deployments, as `sharp` is installed automatically.
## Caching

Expand Down
13 changes: 7 additions & 6 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ module.exports = {
'^.+\\.(jpg|jpeg|png|gif|webp|svg)$': '<rootDir>/__mocks__/fileMock.js',
},
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'],
testEnvironment: 'jsdom',
transform: {
// Use babel-jest to transpile tests with the next/babel preset
// https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object
Expand Down Expand Up @@ -276,16 +277,16 @@ Your project is now ready to run tests. Follow Jests convention by adding tests
For example, we can add a test to check if the `<Index />` component successfully renders a heading:

```jsx
// __tests__/testing-library.js
// __tests__/index.test.jsx
import React from 'react'
import { render } from '@testing-library/react'
import Index from '../pages/index'
import { render, screen } from '@testing-library/react'
import Home from '../pages/index'

describe('App', () => {
describe('Home', () => {
it('renders a heading', () => {
const { getByRole } = render(<Index />)
render(<Home />)

const heading = getByRole('heading', {
const heading = screen.getByRole('heading', {
name: /welcome to next\.js!/i,
})

Expand Down
32 changes: 32 additions & 0 deletions errors/invalid-api-status-body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Invalid API Route Status/Body Response

#### Why This Error Occurred

In one of your API routes a 204 or 304 status code was used as well as sending a response body.

This is invalid as a 204 or 304 status code dictates no response body should be present.

#### Possible Ways to Fix It

Send an empty body when using a 204 or 304 status code or use a different status code while sending a response body.

Before

```js
export default function handler(req, res) {
res.status(204).send('invalid body')
}
```

After

```js
export default function handler(req, res) {
res.status(204).send()
}
```

### Useful Links

- [204 status code documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204)
- [304 status code documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/304)
4 changes: 4 additions & 0 deletions errors/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@
{
"title": "next-config-error",
"path": "/errors/next-config-error.md"
},
{
"title": "invalid-api-status-body",
"path": "/errors/invalid-api-status-body.md"
}
]
}
Expand Down
9 changes: 7 additions & 2 deletions errors/sharp-missing-in-production.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

#### Why This Error Occurred

The `next/image` component's default loader uses the ['squoosh'](https://www.npmjs.com/package/@squoosh/lib) library for image resizing and optimization. This library is quick to install and suitable for a dev server environment. For a production environment, it is strongly recommended that you install the optional [`sharp`](https://www.npmjs.com/package/sharp). This package was not detected when leveraging the Image Optimization in production mode (`next start`).
The `next/image` component's default loader uses [`squoosh`](https://www.npmjs.com/package/@squoosh/lib) because it is quick to install and suitable for a development environment. For a production environment using `next start`, it is strongly recommended you install [`sharp`](https://www.npmjs.com/package/sharp) by running `yarn add sharp` in your project directory.

You are seeing this error because Image Optimization in production mode (`next start`) was detected.

#### Possible Ways to Fix It

Install `sharp` by running `yarn add sharp` in your project directory.
- Install `sharp` by running `yarn add sharp` in your project directory and then reboot the server by running `next start` again
- If `sharp` is already installed but can't be resolved, set the `NEXT_SHARP_PATH` environment variable such as `NEXT_SHARP_PATH=/tmp/node_modules/sharp next start`

> Note: This is not necessary for Vercel deployments, since `sharp` is installed automatically for you.
### Useful Links

Expand Down
3 changes: 2 additions & 1 deletion examples/active-class-name/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dependencies": {
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react-dom": "^17.0.2",
"prop-types": "^15.7.2"
}
}
5 changes: 5 additions & 0 deletions examples/with-couchbase/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
COUCHBASE_USER=
COUCHBASE_PASSWORD=
COUCHBASE_ENDPOINT=
COUCHBASE_BUCKET=
IS_CLOUD_INSTANCE=
33 changes: 33 additions & 0 deletions examples/with-couchbase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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

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

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

# IDE Files
.idea/
Loading

0 comments on commit 26fbb3c

Please sign in to comment.