Skip to content

Commit 037cba1

Browse files
authored
Merge branch 'canary' into add-route-events-types
2 parents 1d76bdf + dcb69ee commit 037cba1

File tree

155 files changed

+3142
-800
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+3142
-800
lines changed

.github/workflows/build_test_deploy.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ jobs:
7878
- run: exit 0
7979

8080
testMacOS:
81-
name: macOS ( Basic, Production, Acceptance )
81+
name: macOS (Basic, Production, Acceptance)
8282
runs-on: macos-latest
83-
needs: build
8483
env:
8584
NEXT_TELEMETRY_DISABLED: 1
8685
NEXT_TEST_JOB: 1
@@ -90,7 +89,24 @@ jobs:
9089
- uses: actions/checkout@v2
9190
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
9291
# Installing dependencies again since OS changed
93-
- run: yarn install --frozen-lockfile --check-files
92+
- run: yarn install --frozen-lockfile --check-files || yarn install --frozen-lockfile --check-files
93+
- run: node run-tests.js test/integration/production/test/index.test.js
94+
- run: node run-tests.js test/integration/basic/test/index.test.js
95+
- run: node run-tests.js test/acceptance/*
96+
97+
testWebpack5:
98+
name: webpack 5 (Basic, Production, Acceptance)
99+
runs-on: ubuntu-latest
100+
env:
101+
NEXT_TELEMETRY_DISABLED: 1
102+
NEXT_TEST_JOB: 1
103+
HEADLESS: true
104+
105+
steps:
106+
- uses: actions/checkout@v2
107+
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
108+
- run: cat package.json | jq '.resolutions.webpack = "^5.0.0-beta.22"' > package.json.tmp && mv package.json.tmp package.json
109+
- run: yarn install --check-files
94110
- run: node run-tests.js test/integration/production/test/index.test.js
95111
- run: node run-tests.js test/integration/basic/test/index.test.js
96112
- run: node run-tests.js test/acceptance/*

docs/advanced-features/measuring-performance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ The `metric` object returned to the function consists of a number of properties:
3030

3131
- `id`: Unique identifier for the metric in the context of the current page load
3232
- `name`: Metric name
33-
- `startTime`: First recorded timestamp of the performance entry (if applicable)
34-
- `value`: Value, or duration, of performance entry
33+
- `startTime`: First recorded timestamp of the performance entry in [milliseconds](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp) (if applicable)
34+
- `value`: Value, or duration in [milliseconds](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp), of the performance entry
3535
- `label`: Type of metric (`web-vital` or `custom`)
3636

3737
There are two types of metrics that are tracked:

docs/advanced-features/multi-zones.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<details>
44
<summary><b>Examples</b></summary>
55
<ul>
6-
<li><a href="https://github.com/examples/with-zones">With Zones</a></li>
6+
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-zones">With Zones</a></li>
77
</ul>
88
</details>
99

docs/api-reference/next.config.js/custom-webpack-config.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ description: Extend the default webpack config added by Next.js.
44

55
# Custom Webpack Config
66

7+
Before continuing to add custom webpack configuration to your application make sure Next.js doesn't already support your use-case:
8+
9+
- [CSS imports](/docs/basic-features/built-in-css-support#adding-a-global-stylesheet)
10+
- [CSS modules](/docs/basic-features/built-in-css-support#adding-component-level-css)
11+
- [Sass/SCSS imports](/docs/basic-features/built-in-css-support#sass-support)
12+
- [Sass/SCSS modules](/docs/basic-features/built-in-css-support#sass-support)
13+
- [preact](https://github.com/vercel/next.js/tree/canary/examples/using-preact)
14+
- [Customizing babel configuration](/docs/advanced-features/customizing-babel-config)
15+
716
Some commonly asked for features are available as plugins:
817

9-
- [@zeit/next-sass](https://github.com/zeit/next-plugins/tree/master/packages/next-sass)
10-
- [@zeit/next-less](https://github.com/zeit/next-plugins/tree/master/packages/next-less)
11-
- [@zeit/next-stylus](https://github.com/zeit/next-plugins/tree/master/packages/next-stylus)
12-
- [@zeit/next-preact](https://github.com/zeit/next-plugins/tree/master/packages/next-preact)
18+
- [@zeit/next-less](https://github.com/vercel/next-plugins/tree/master/packages/next-less)
1319
- [@next/mdx](https://github.com/vercel/next.js/tree/canary/packages/next-mdx)
1420
- [@next/bundle-analyzer](https://github.com/vercel/next.js/tree/canary/packages/next-bundle-analyzer)
1521

@@ -20,12 +26,8 @@ module.exports = {
2026
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
2127
// Note: we provide webpack above so you should not `require` it
2228
// Perform customizations to webpack config
23-
// Important: return the modified config
2429
config.plugins.push(new webpack.IgnorePlugin(/\/__tests__\//))
25-
return config
26-
},
27-
webpackDevMiddleware: (config) => {
28-
// Perform customizations to webpack dev middleware config
30+
2931
// Important: return the modified config
3032
return config
3133
},

docs/api-reference/next.config.js/redirects.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,5 @@ module.exports = {
9292
},
9393
}
9494
```
95+
96+
In some rare cases, you might need to assign a custom status code for older HTTP Clients to properly redirect. In these cases, you can use the `statusCode` property instead of the `permanent` property, but not both. Note: to ensure IE11 compatibility a `Refresh` header is automatically added for the 308 status code.

docs/api-reference/next.config.js/rewrites.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Add rewrites to your Next.js app.
44

55
# Rewrites
66

7-
<details>
7+
<details open>
88
<summary><b>Examples</b></summary>
99
<ul>
1010
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/rewrites">Rewrites</a></li>

docs/basic-features/built-in-css-support.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ description: Next.js supports including CSS files as Global CSS or CSS Modules,
44

55
# Built-In CSS Support
66

7+
<details open>
8+
<summary><b>Examples</b></summary>
9+
<ul>
10+
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/basic-css">Basic CSS Example</a></li>
11+
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-tailwindcss">With Tailwind CSS</a></li>
12+
</ul>
13+
</details>
14+
715
Next.js allows you to import CSS files from a JavaScript file.
816
This is possible because Next.js extends the concept of [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) beyond JavaScript.
917

@@ -129,8 +137,8 @@ module.exports = {
129137

130138
To support importing `.less` or `.styl` files you can use the following plugins:
131139

132-
- [@zeit/next-less](https://github.com/zeit/next-plugins/tree/master/packages/next-less)
133-
- [@zeit/next-stylus](https://github.com/zeit/next-plugins/tree/master/packages/next-stylus)
140+
- [@zeit/next-less](https://github.com/vercel/next-plugins/tree/master/packages/next-less)
141+
- [@zeit/next-stylus](https://github.com/vercel/next-plugins/tree/master/packages/next-stylus)
134142

135143
If using the less plugin, don't forget to add a dependency on less as well, otherwise you'll see an error like:
136144

@@ -143,8 +151,10 @@ Error: Cannot find module 'less'
143151
<details>
144152
<summary><b>Examples</b></summary>
145153
<ul>
146-
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/basic-css">Styled JSX</a></li>
154+
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-styled-jsx">Styled JSX</a></li>
147155
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-styled-components">Styled Components</a></li>
156+
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-emotion">Emotion</a></li>
157+
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-tailwindcss-emotion">Tailwind CSS + Emotion</a></li>
148158
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-styletron">Styletron</a></li>
149159
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-glamor">Glamor</a></li>
150160
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-cxs">Cxs</a></li>
@@ -164,7 +174,7 @@ function HiThere() {
164174
export default HiThere
165175
```
166176

167-
We bundle [styled-jsx](https://github.com/zeit/styled-jsx) to provide support for isolated scoped CSS.
177+
We bundle [styled-jsx](https://github.com/vercel/styled-jsx) to provide support for isolated scoped CSS.
168178
The aim is to support "shadow CSS" similar to Web Components, which unfortunately [do not support server-rendering and are JS-only](https://github.com/w3c/webcomponents/issues/71).
169179

170180
See the above examples for other popular CSS-in-JS solutions (like Styled Components).
@@ -202,7 +212,7 @@ function HelloWorld() {
202212
export default HelloWorld
203213
```
204214

205-
Please see the [styled-jsx documentation](https://github.com/zeit/styled-jsx) for more examples.
215+
Please see the [styled-jsx documentation](https://github.com/vercel/styled-jsx) for more examples.
206216

207217
## FAQ
208218

docs/basic-features/data-fetching.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ The `context` parameter is an object containing the following keys:
5454
- `preview` is `true` if the page is in the preview mode and `false` otherwise. See the [Preview Mode documentation](/docs/advanced-features/preview-mode.md).
5555
- `previewData` contains the preview data set by `setPreviewData`. See the [Preview Mode documentation](/docs/advanced-features/preview-mode.md).
5656

57+
`getStaticProps` should return an object with:
58+
59+
- `props` - A **required** object with the props that will be received by the page component. It should be a [serializable object](https://en.wikipedia.org/wiki/Serialization)
60+
- `revalidate` - An **optional** amount in seconds after which a page re-generation can occur. More on [Incremental Static Regeneration](#incremental-static-regeneration)
61+
5762
> **Note**: You can import modules in top-level scope for use in `getStaticProps`.
5863
> Imports used in `getStaticProps` will not be bundled for the client-side, as [explained below](#write-server-side-code-directly).
5964
@@ -143,6 +148,67 @@ function Blog({ posts }: InferGetStaticPropsType<typeof getStaticProps>) {
143148
export default Blog
144149
```
145150

151+
### Incremental Static Regeneration
152+
153+
> This feature was introduced in [Next.js 9.5](https://nextjs.org/blog/next-9-5#stable-incremental-static-regeneration) and up. If you’re using older versions of Next.js, please upgrade before trying Incremental Static Regeneration.
154+
155+
<details open>
156+
<summary><b>Examples</b></summary>
157+
<ul>
158+
<li><a href="https://reactions-demo.now.sh/">Static Reactions Demo</a></li>
159+
</ul>
160+
</details>
161+
162+
With [`getStaticProps`](#getstaticprops-static-generation) you don't have to stop relying in dynamic content, as **static content can also be dynamic**. Incremental Static Regeneration allows you to update _existing_ pages by re-rendering them in the background as traffic comes in.
163+
164+
Inspired by [stale-while-revalidate](https://tools.ietf.org/html/rfc5861), background regeneration ensures traffic is served uninterruptedly, always from static storage, and the newly built page is pushed only after it's done generating.
165+
166+
Consider our previous [`getStaticProps` example](#simple-example), but now with regeneration enabled:
167+
168+
```jsx
169+
function Blog({ posts }) {
170+
return (
171+
<ul>
172+
{posts.map((post) => (
173+
<li>{post.title}</li>
174+
))}
175+
</ul>
176+
)
177+
}
178+
179+
// This function gets called at build time on server-side.
180+
// It may be called again, on a serverless function, if
181+
// revalidation is enabled and a new request comes in
182+
export async function getStaticProps() {
183+
const res = await fetch('https://.../posts')
184+
const posts = await res.json()
185+
186+
return {
187+
props: {
188+
posts,
189+
},
190+
// Next.js will attempt to re-generate the page:
191+
// - When a request comes in
192+
// - At most once every second
193+
revalidate: 1, // In seconds
194+
}
195+
}
196+
197+
export default Blog
198+
```
199+
200+
Now the list of blog posts will be revalidated once per second; if you add a new blog post it will be available almost immediately, without having to re-build your app or make a new deployment.
201+
202+
This works perfectly with [`fallback: true`](#fallback-true). Because now you can have a list of posts that's always up to date with the latest posts, and have a [blog post page](#fallback-pages) that generates blog posts on-demand, no matter how many posts you add or update.
203+
204+
#### Static content at scale
205+
206+
Unlike traditional SSR, [Incremental Static Regeneration](#incremental-static-regeneration) ensures you retain the benefits of static:
207+
208+
- No spikes in latency. Pages are served consistently fast
209+
- Pages never go offline. If the background page re-generation fails, the old page remains unaltered
210+
- Low database and backend load. Pages are re-computed at most once concurrently
211+
146212
### Reading files: Use `process.cwd()`
147213

148214
Files can be read directly from the filesystem in `getStaticProps`.
@@ -326,6 +392,13 @@ export default Post
326392

327393
#### `fallback: true`
328394

395+
<details>
396+
<summary><b>Examples</b></summary>
397+
<ul>
398+
<li><a href="https://static-tweet.now.sh">Static generation of a large number of pages</a></li>
399+
</ul>
400+
</details>
401+
329402
If `fallback` is `true`, then the behavior of `getStaticProps` changes:
330403

331404
- The paths returned from `getStaticPaths` will be rendered to HTML at build time.
@@ -380,7 +453,12 @@ export async function getStaticProps({ params }) {
380453
const post = await res.json()
381454

382455
// Pass post data to the page via props
383-
return { props: { post } }
456+
return {
457+
props: { post },
458+
// Re-generate the post at most once per second
459+
// if a request comes in
460+
revalidate: 1,
461+
}
384462
}
385463

386464
export default Post
@@ -394,6 +472,8 @@ Instead, you may statically generate a small subset of pages and use `fallback:
394472

395473
This ensures that users always have a fast experience while preserving fast builds and the benefits of Static Generation.
396474

475+
`fallback: true` will not _update_ generated pages, for that take a look at [Incremental Static Regeneration](#incremental-static-regeneration).
476+
397477
### When should I use `getStaticPaths`?
398478

399479
You should use `getStaticPaths` if you’re statically pre-rendering pages that use dynamic routes.

docs/routing/dynamic-routes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ The `query` objects are as follows:
9999
{ "slug": ["a", "b"] } // `GET /post/a/b` (multi-element array)
100100
```
101101

102-
> A good example of optional catch all routes is the Next.js docs, a single page called [pages/docs/[[...slug]].js](https://github.com/zeit/next-site/blob/master/pages/docs/%5B%5B...slug%5D%5D.js) takes care of all the docs you're currently looking at.
102+
> A good example of optional catch all routes is the Next.js docs, a single page called [pages/docs/[[...slug]].js](https://github.com/vercel/next-site/blob/master/pages/docs/%5B%5B...slug%5D%5D.js) takes care of all the docs you're currently looking at.
103103
104104
## Caveats
105105

docs/upgrading.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Next.js now has the concept of page-level configuration, so the `withAmp` higher
104104
This change can be **automatically migrated by running the following commands in the root of your Next.js project:**
105105

106106
```bash
107-
curl -L https://github.com/zeit/next-codemod/archive/master.tar.gz | tar -xz --strip=2 next-codemod-master/transforms/withamp-to-config.js npx jscodeshift -t ./withamp-to-config.js pages/**/*.js
107+
curl -L https://github.com/vercel/next-codemod/archive/master.tar.gz | tar -xz --strip=2 next-codemod-master/transforms/withamp-to-config.js npx jscodeshift -t ./withamp-to-config.js pages/**/*.js
108108
```
109109

110110
To perform this migration by hand, or view what the codemod will produce, see below:

0 commit comments

Comments
 (0)