Skip to content

Commit

Permalink
Merge branch 'canary' into update-treeview
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Mar 25, 2022
2 parents 9622388 + 4f6bb5e commit f2336f8
Show file tree
Hide file tree
Showing 137 changed files with 3,012 additions and 974 deletions.
9 changes: 8 additions & 1 deletion .eslintrc.json
Expand Up @@ -203,7 +203,14 @@
"no-octal-escape": "warn",
"no-redeclare": ["warn", { "builtinGlobals": false }],
"no-regex-spaces": "warn",
"no-restricted-syntax": ["warn", "WithStatement"],
"no-restricted-syntax": [
"warn",
"WithStatement",
{
"message": "substr() is deprecated, use slice() or substring() instead",
"selector": "MemberExpression > Identifier[name='substr']"
}
],
"no-script-url": "warn",
"no-self-assign": "warn",
"no-self-compare": "warn",
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/next-stats-action/src/add-comment.js
Expand Up @@ -20,7 +20,7 @@ const round = (num, places) => {

const shortenLabel = (itemKey) =>
itemKey.length > 24
? `${itemKey.substr(0, 12)}..${itemKey.substr(itemKey.length - 12, 12)}`
? `${itemKey.slice(0, 12)}..${itemKey.slice(-12)}`
: itemKey

const twoMB = 2 * 1024 * 1024
Expand Down
3 changes: 1 addition & 2 deletions .github/actions/next-stats-action/src/run/collect-stats.js
Expand Up @@ -74,8 +74,7 @@ module.exports = async function collectStats(
const responseText = (await res.text()).trim()

let fileName = pathname === '/' ? '/index' : pathname
if (fileName.endsWith('/'))
fileName = fileName.substr(0, fileName.length - 1)
if (fileName.endsWith('/')) fileName = fileName.slice(0, -1)
logger(
`Writing file to ${path.join(fetchedPagesDir, `${fileName}.html`)}`
)
Expand Down
24 changes: 20 additions & 4 deletions .github/workflows/build_test_deploy.yml
Expand Up @@ -208,12 +208,16 @@ jobs:
env:
NEXT_TELEMETRY_DISABLED: 1
NEXT_TEST_JOB: 1
strategy:
fail-fast: false
matrix:
node: [16, 17]
steps:
- name: Setup node
uses: actions/setup-node@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
with:
node-version: 14
node-version: ${{ matrix.node }}

- run: echo ${{needs.build.outputs.docsChange}}

Expand Down Expand Up @@ -258,12 +262,16 @@ jobs:
env:
NEXT_TELEMETRY_DISABLED: 1
NEXT_TEST_JOB: 1
strategy:
fail-fast: false
matrix:
node: [16, 17]
steps:
- name: Setup node
uses: actions/setup-node@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
with:
node-version: 14
node-version: ${{ matrix.node }}

- run: echo ${{needs.build.outputs.docsChange}}

Expand Down Expand Up @@ -308,12 +316,16 @@ jobs:
env:
NEXT_TELEMETRY_DISABLED: 1
NEXT_TEST_JOB: 1
strategy:
fail-fast: false
matrix:
node: [16, 17]
steps:
- name: Setup node
uses: actions/setup-node@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
with:
node-version: 14
node-version: ${{ matrix.node }}

- run: echo ${{needs.build.outputs.docsChange}}

Expand Down Expand Up @@ -348,12 +360,16 @@ jobs:
env:
NEXT_TELEMETRY_DISABLED: 1
NEXT_TEST_JOB: 1
strategy:
fail-fast: false
matrix:
node: [16, 17]
steps:
- name: Setup node
uses: actions/setup-node@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
with:
node-version: 14
node-version: ${{ matrix.node }}

- run: echo ${{needs.build.outputs.docsChange}}

Expand Down
83 changes: 83 additions & 0 deletions docs/advanced-features/compiler.md
Expand Up @@ -233,6 +233,89 @@ module.exports = {

If you have feedback about `swcMinify`, please share it on the [feedback discussion](https://github.com/vercel/next.js/discussions/30237).

### Modularize Imports

Allows to modularize imports, similar to [babel-plugin-transform-imports](https://www.npmjs.com/package/babel-plugin-transform-imports).

Transforms member style imports:

```js
import { Row, Grid as MyGrid } from 'react-bootstrap'
import { merge } from 'lodash'
```

...into default style imports:

```js
import Row from 'react-bootstrap/lib/Row'
import MyGrid from 'react-bootstrap/lib/Grid'
import merge from 'lodash/merge'
```

Config for the above transform:

```js
// next.config.js
module.exports = {
experimental: {
modularizeImports: {
'react-bootstrap': {
transform: 'react-bootstrap/lib/{{member}}',
},
lodash: {
transform: 'lodash/{{member}}',
},
},
},
}
```

Advanced transformations:

- Using regular expressions

Similar to `babel-plugin-transform-imports`, but the transform is templated with [handlebars](https://docs.rs/handlebars) and regular expressions are in Rust [regex](https://docs.rs/regex/latest/regex/) crate's syntax.

The config:

```js
// next.config.js
module.exports = {
experimental: {
modularizeImports: {
'my-library/?(((\\w*)?/?)*)': {
transform: 'my-library/{{ matches.[1] }}/{{member}}',
},
},
},
}
```

Cause this code:

```js
import { MyModule } from 'my-library'
import { App } from 'my-library/components'
import { Header, Footer } from 'my-library/components/App'
```

To become:

```js
import MyModule from 'my-library/MyModule'
import App from 'my-library/components/App'
import Header from 'my-library/components/App/Header'
import Footer from 'my-library/components/App/Footer'
```

- Handlebars templating

This transform uses [handlebars](https://docs.rs/handlebars) to template the replacement import path in the `transform` field. These variables and helper functions are available:

1. `matches`: Has type `string[]`. All groups matched by the regular expression. `matches.[0]` is the full match.
2. `member`: Has type `string`. The name of the member import.
3. `lowerCase`, `upperCase`, `camelCase`: Helper functions to convert a string to lower, upper or camel cases.

## Unsupported Features

When your application has a `.babelrc` file, Next.js will automatically fall back to using Babel for transforming individual files. This ensures backwards compatibility with existing applications that leverage custom Babel plugins.
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-features/react-18/server-components.md
Expand Up @@ -7,7 +7,7 @@ Server Components allow us to render React components on the server. This is fun
To use React Server Components, ensure you have React 18 installed:

```jsx
npm install next@latest react@rc react-dom@rc
npm install next@canary react@rc react-dom@rc
```

Then, update your `next.config.js`:
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/data-fetching/get-static-props.md
Expand Up @@ -85,7 +85,7 @@ Learn more about [Incremental Static Regeneration](/docs/basic-features/data-fet

### `notFound`

The `notFound` boolean allows the page to return a `404` status and [404 Page](/docs/advanced-features/custom-error-page.md#404-page). With `notFound: true`, the page will return a `404` even if there was a successfully generated page before. This is meant to support use cases like user-generated content getting removed by its author.
The `notFound` boolean allows the page to return a `404` status and [404 Page](/docs/advanced-features/custom-error-page.md#404-page). With `notFound: true`, the page will return a `404` even if there was a successfully generated page before. This is meant to support use cases like user-generated content getting removed by its author. Note, `notFound` follows the same `revalidate` behavior [described here](/docs/api-reference/data-fetching/get-static-props.md#revalidate)

```js
export async function getStaticProps(context) {
Expand Down
3 changes: 3 additions & 0 deletions docs/api-reference/next.config.js/redirects.md
Expand Up @@ -44,6 +44,9 @@ module.exports = {
- `source` is the incoming request path pattern.
- `destination` is the path you want to route to.
- `permanent` `true` or `false` - if `true` will use the 308 status code which instructs clients/search engines to cache the redirect forever, if `false` will use the 307 status code which is temporary and is not cached.

> **Why does Next.js use 307 and 308?** Traditionally a 302 was used for a temporary redirect, and a 301 for a permanent redirect, but many browsers changed the request method of the redirect to `GET`, regardless of the original method. For example, if the browser made a request to `POST /v1/users` which returned status code `302` with location `/v2/users`, the subsequent request might be `GET /v2/users` instead of the expected `POST /v2/users`. Next.js uses the 307 temporary redirect, and 308 permanent redirect status codes to explicitly preserve the request method used.
- `basePath`: `false` or `undefined` - if false the basePath won't be included when matching, can be used for external rewrites only.
- `locale`: `false` or `undefined` - whether the locale should not be included when matching.
- `has` is an array of [has objects](#header-cookie-and-query-matching) with the `type`, `key` and `value` properties.
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/next.config.js/rewrites.md
Expand Up @@ -323,7 +323,7 @@ module.exports = {
}
```

If you're using `trailingSlash: true`, you also need to insert a trailing slash in the `source` paramater. If the destination server is also expecting a trailing slash it should be included in the `destination` parameter as well.
If you're using `trailingSlash: true`, you also need to insert a trailing slash in the `source` parameter. If the destination server is also expecting a trailing slash it should be included in the `destination` parameter as well.

```js
module.exports = {
Expand Down
16 changes: 12 additions & 4 deletions docs/api-reference/next/image.md
Expand Up @@ -48,15 +48,23 @@ When using an external URL, you must add it to

### width

The width of the image, in pixels. Must be an integer without a unit.
The `width` property can represent either the _rendered_ width or _original_ width in pixels, depending on the [`layout`](#layout) and [`sizes`](#sizes) properties.

Required, except for statically imported images, or those with [`layout="fill"`](#layout).
When using `layout="intrinsic"`, `layout="fixed"`, or `layout="raw"` without `sizes`, the `width` property represents the _rendered_ width in pixels, so it will affect how large the image appears.

When using `layout="responsive"`, `layout="fill"`, or `layout="raw"` with `sizes`, the `width` property represents the _original_ width in pixels, so it will only affect the aspect ratio.

The `width` property is required, except for [statically imported images](#local-images), or those with `layout="fill"`.

### height

The height of the image, in pixels. Must be an integer without a unit.
The `height` property can represent either the _rendered_ height or _original_ height in pixels, depending on the [`layout`](#layout) and [`sizes`](#sizes) properties.

When using `layout="intrinsic"`, `layout="fixed"`, or `layout="raw"` without `sizes`, the `height` property represents the _rendered_ height in pixels, so it will affect how large the image appears.

When using `layout="responsive"`, `layout="fill"`, or `layout="raw"` with `sizes`, the `height` property represents the _original_ height in pixels, so it will only affect the aspect ratio.

Required, except for statically imported images, or those with [`layout="fill"`](#layout).
The `height` property is required, except for [statically imported images](#local-images), or those with `layout="fill"`.

## Optional Props

Expand Down
2 changes: 2 additions & 0 deletions docs/api-reference/next/streaming.md
Expand Up @@ -88,6 +88,8 @@ export default function Search() {
<SearchUI
onChange={() => {
refresh()
// Or refresh with updated props:
// refresh(nextProps)
}}
/>
)
Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/data-fetching/get-server-side-props.md
Expand Up @@ -21,7 +21,7 @@ export async function getServerSideProps(context) {
- When you request this page directly, `getServerSideProps` runs at request time, and this page will be pre-rendered with the returned props
- When you request this page on client-side page transitions through [`next/link`](/docs/api-reference/next/link.md) or [`next/router`](/docs/api-reference/next/router.md), Next.js sends an API request to the server, which runs `getServerSideProps`

It then returns `JSON` that contains the result of running `getServerSideProps`, that `JSON` will be used to render the page. All this work will be handled automatically by Next.js, so you don’t need to do anything extra as long as you have `getServerSideProps` defined.
`getServerSideProps` returns JSON which will be used to render the page. All this work will be handled automatically by Next.js, so you don’t need to do anything extra as long as you have `getServerSideProps` defined.

You can use the [next-code-elimination tool](https://next-code-elimination.vercel.app/) to verify what Next.js eliminates from the client-side bundle.

Expand Down
4 changes: 2 additions & 2 deletions docs/basic-features/image-optimization.md
Expand Up @@ -150,8 +150,8 @@ One of the ways that images most commonly hurt performance is through _layout sh
Because `next/image` is designed to guarantee good performance results, it cannot be used in a way that will contribute to layout shift, and **must** be sized in one of three ways:

1. Automatically, using a [static import](#local-images)
2. Explicitly, by including a `height` **and** `width` property
3. Implicitly, by using `layout="fill"` which causes the image to expand to fill its parent element.
2. Explicitly, by including a [`width`](/docs/api-reference/next/image.md#width) and [`height`](/docs/api-reference/next/image.md#height) property
3. Implicitly, by using [`layout="fill"`](/docs/api-reference/next/image.md#layout) which causes the image to expand to fill its parent element.

> ### What if I don't know the size of my images?
>
Expand Down
4 changes: 2 additions & 2 deletions docs/basic-features/script.md
Expand Up @@ -25,7 +25,7 @@ description: Next.js helps you optimize loading third-party scripts with the bui

</details>

The Next.js Script component, [`next/script`](/docs/api-reference/next/script.md), is an extension of the HTML `<script>` element. It enables developers to set the loading priority of third-party scripts anywhere in their application without needing to append directly to `next/head`, saving developer time while improving loading performance.
The Next.js Script component, [`next/script`](/docs/api-reference/next/script.md), is an extension of the HTML `<script>` element. It enables developers to set the loading priority of third-party scripts anywhere in their application, outside `next/head`, saving developer time while improving loading performance.

```jsx
import Script from 'next/script'
Expand Down Expand Up @@ -166,7 +166,7 @@ There are a number of trade-offs that need to be considered when loading a third

Although the `worker` strategy does not require any additional configuration to work, Partytown supports the use of a config object to modify some of its settings, including enabling `debug` mode and forwarding events and triggers.

If you would like to add additonal configuration options, you can include it within the `<Head />` component used in a [custom `_document.js`](/docs/advanced-features/custom-document.md):
If you would like to add additional configuration options, you can include it within the `<Head />` component used in a [custom `_document.js`](/docs/advanced-features/custom-document.md):

```jsx
import { Html, Head, Main, NextScript } from 'next/document'
Expand Down
35 changes: 35 additions & 0 deletions errors/link-no-children.md
@@ -0,0 +1,35 @@
# No children were passed to <Link>

#### Why This Error Occurred

In your application code `next/link` was used without passing a child:

For example:

```js
import Link from 'next/link'

export default function Home() {
return (
<Link href="/about"></Link>
// or
<Link href='/about' />
)
}
```

#### Possible Ways to Fix It

Make sure one child is used when using `<Link>`:

```js
import Link from 'next/link'

export default function Home() {
return (
<Link href="/about">
<a>To About</a>
</Link>
)
}
```
4 changes: 4 additions & 0 deletions errors/manifest.json
Expand Up @@ -514,6 +514,10 @@
"title": "future-webpack5-moved-to-webpack5",
"path": "/errors/future-webpack5-moved-to-webpack5.md"
},
{
"title": "link-no-children",
"path": "/errors/link-no-children.md"
},
{
"title": "link-multiple-children",
"path": "/errors/link-multiple-children.md"
Expand Down
34 changes: 34 additions & 0 deletions examples/modularize-imports/.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

0 comments on commit f2336f8

Please sign in to comment.