Skip to content

Commit

Permalink
Merge branch 'canary' into examples/mobx-merge
Browse files Browse the repository at this point in the history
# Conflicts:
#	examples/with-mobx-state-tree/components/SampleComponent.js
  • Loading branch information
ijjk committed Sep 14, 2022
2 parents b86306e + eadaca7 commit 1b03ab2
Show file tree
Hide file tree
Showing 221 changed files with 3,543 additions and 1,617 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -4,6 +4,7 @@
* @timneutkens @ijjk @shuding @huozhi
/.github/ @timneutkens @ijjk @shuding @styfle @huozhi @padmaia @balazsorban44
/docs/ @timneutkens @ijjk @shuding @styfle @huozhi @padmaia @leerob @balazsorban44
/errors/ @balazsorban44
/examples/ @timneutkens @ijjk @shuding @leerob @steven-tey @balazsorban44

# SWC Build & Telemetry (@padmaia)
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/validate_issue.yml
Expand Up @@ -15,4 +15,3 @@ jobs:
run: node ./.github/actions/issue-validator/index.mjs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEBUG: 1
2 changes: 1 addition & 1 deletion contributing.md
Expand Up @@ -147,7 +147,7 @@ There are two options to develop with your local version of the codebase:
with:

```json
"next": "file:/path/to/next.js/packages/next",
"next": "link:/path/to/next.js/packages/next",
```

2. In your app's root directory, make sure to remove `next` from `node_modules` with:
Expand Down
5 changes: 3 additions & 2 deletions docs/advanced-features/compiler.md
Expand Up @@ -9,6 +9,7 @@ description: Learn about the Next.js Compiler, written in Rust, which transforms

| Version | Changes |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `v12.3.0` | SWC Minifier [stable](https://nextjs.org/blog/next-12-3#swc-minifier-stable). |
| `v12.2.0` | [SWC Plugins](#swc-plugins-Experimental) experimental support added. |
| `v12.1.0` | Added support for Styled Components, Jest, Relay, Remove React Properties, Legacy Decorators, Remove Console, and jsxImportSource. |
| `v12.0.0` | Next.js Compiler [introduced](https://nextjs.org/blog/next-12). |
Expand Down Expand Up @@ -238,8 +239,6 @@ module.exports = {

Only `importMap` in `@emotion/babel-plugin` is not supported for now.

## Experimental Features

### Minification

You can opt-in to using the Next.js compiler for minification. This is 7x faster than Terser.
Expand All @@ -254,6 +253,8 @@ module.exports = {

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

## Experimental Features

### Minifier debug options

While the minifier is experimental, we are making the following options available for debugging purposes. They will not be available once the minifier is made stable.
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-features/dynamic-import.md
Expand Up @@ -42,7 +42,7 @@ If you are not using React 18, you can use the `loading` attribute in place of t

```jsx
const DynamicHeader = dynamic(() => import('../components/header'), {
loading: () => <header />,
loading: () => <div>Loading...</div>,
})
```

Expand Down
20 changes: 17 additions & 3 deletions docs/advanced-features/middleware.md
Expand Up @@ -31,7 +31,7 @@ To begin using Middleware, follow the steps below:
npm install next@latest
```

2. Create a `middleware.ts` (or `.js`) file at the same level as your `pages` directory
2. Create a `middleware.ts` (or `.js`) file at the root or in the `src` directory (same level as your `pages`)
3. Export a middleware function from the `middleware.ts` file:

```typescript
Expand Down Expand Up @@ -88,6 +88,22 @@ export const config = {
}
```

The `matcher` config allows full regex so matching like negative lookaheads or character matching is supported. An example of a negative lookahead to match all except specific paths can be seen here:

```js
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - static (static files)
* - favicon.ico (favicon file)
*/
'/((?!api|static|favicon.ico).*)',
],
}
```

> **Note:** The `matcher` values need to be constants so they can be statically analyzed at build-time. Dynamic values such as variables will be ignored.
Configured matchers:
Expand All @@ -101,8 +117,6 @@ Read more details on [path-to-regexp](https://github.com/pillarjs/path-to-regexp

> **Note:** For backward compatibility, Next.js always considers `/public` as `/public/index`. Therefore, a matcher of `/public/:path` will match.
> **Note:** It is not possible to exclude middleware from matching static path starting with `_next/`. This allow enforcing security with middleware.
### Conditional Statements

```typescript
Expand Down
115 changes: 13 additions & 102 deletions docs/advanced-features/react-18/server-components.md
@@ -1,116 +1,27 @@
# React Server Components (RFC)

Server Components allow us to render React components on the server. This is fundamentally different from server-side rendering (SSR) where you're pre-generating HTML on the server. With Server Components, there's **zero client-side JavaScript needed,** making page rendering faster. This improves the user experience of your application, pairing the best parts of server-rendering with client-side interactivity.
React Server Components allow developers to build applications that span the server and client, combining the rich interactivity of client-side apps with the improved performance of traditional server rendering.

### Next Router and Layouts RFC
In an upcoming Next.js release, React and Next.js developers will be able to use Server Components inside the `app` directory as part of the changes outlined by the [Layouts RFC](https://nextjs.org/blog/layouts-rfc).

We are currently implementing the [Next.js Router and Layouts RFC](https://nextjs.org/blog/layouts-rfc).
## What are React Server Components?

The new Next.js router will be built on top of React 18 features, including React Server Components.
React Server Components improve the user experience of your application by pairing the best parts of server-rendering with client-side interactivity.

One of the biggest proposed changes is that, by default, files inside a new `app` directory will be rendered on the server as React Server Components.
With traditional React applications that are client-side only, developers often had to make tradeoffs between SEO and performance. Server Components enable developers to better leverage their server infrastructure and achieve great performance by default.

This will allow you to automatically adopt React Server Components when migrating from `pages` to `app`.
For example, large dependencies that previously would impact the JavaScript bundle size on the client can instead stay entirely on the server. By sending less JavaScript to the browser, the time to interactive for the page is decreased, leading to improved [Core Web Vitals](https://vercel.com/blog/core-web-vitals).

You can find more information on the [RFC](https://nextjs.org/blog/layouts-rfc) and we welcome your feedback on [Github Discussions](https://github.com/vercel/next.js/discussions/37136).
## React Server Components vs Server-Side Rendering

### Server Components Conventions
[Server-side Rendering](/docs/basic-features/pages.md#server-side-rendering) (SSR) dynamically builds your application into HTML on the server. This creates faster load times for users by offloading work from the user's device to the server, especially those with slower internet connections or older devices. However, developers still pay the cost to download, parse, and hydrate those components after the initial HTML loads.

To run a component on the server, append `.server.js` to the end of the filename. For example, `./pages/home.server.js` will be treated as a Server Component.
React Server Components, combined with Next.js server-side rendering, help eliminate the tradeoff of all-or-nothing data fetching. You can progressively show updates as your data comes in.

For client components, append `.client.js` to the filename. For example, `./components/avatar.client.js`.
## Using React Server Components with Next.js

Server components can import server components and client components.
The Next.js team at Vercel released the [Layouts RFC](https://nextjs.org/blog/layouts-rfc) a few months ago outlining the vision for the future of routing, layouts, and data fetching in the framework. These changes **aren't available yet**, but we can start learning about how they will be used.

Client components **cannot** import server components.
Pages and Layouts in `app` will be rendered as React Server Components by default. This improves performance by reducing the amount of JavaScript sent to the client for components that are not interactive. Client components will be able to be defined through either a file name extension or through a string literal in the file.

Components without a `server` or `client` extension will be treated as shared components and can be imported by server components and client components. For example:

```jsx
// pages/home.server.js

import { Suspense } from 'react'

import Profile from '../components/profile.server'
import Content from '../components/content.client'

export default function Home() {
return (
<div>
<h1>Welcome to React Server Components</h1>
<Suspense fallback={'Loading...'}>
<Profile />
</Suspense>
<Content />
</div>
)
}
```

The `<Home>` and `<Profile>` components will always be server-side rendered and streamed to the client, and will not be included by the client-side JavaScript. However, `<Content>` will still be hydrated on the client-side, like normal React components.

> Make sure you're using default imports and exports for server components (`.server.js`). The support of named exports are a work in progress!
To see a full example, check out the [vercel/next-react-server-components demo](https://github.com/vercel/next-react-server-components).

## Supported Next.js APIs

### `next/link` and `next/image`

You can use `next/link` and `next/image` like before and they will be treated as client components to keep the interaction on client side.

### `next/document`

If you have a custom `_document`, you have to change your `_document` to a functional component like below to use server components. If you don't have one, Next.js will use the default `_document` component for you.

```jsx
// pages/_document.js
import { Html, Head, Main, NextScript } from 'next/document'

export default function Document() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
```

### `next/app`

The usage of `_app.js` is the same as [Custom App](/docs/advanced-features/custom-app). Using custom app as server component such as `_app.server.js` is not recommended, to keep align with non server components apps for client specific things like global CSS imports.

### Routing

Both basic routes with path and queries and dynamic routes are supported. If you need to access the router in server components(`.server.js`), they will receive `router` instance as a prop so that you can directly access them without using the `useRouter()` hook.

```jsx
// pages/index.server.js

export default function Index({ router }) {
// You can access routing information by `router.pathname`, etc.
return 'hello'
}
```

### Unsupported Next.js APIs

While RSC and SSR streaming are still in the alpha stage, not all Next.js APIs are supported. The following Next.js APIs have limited functionality within Server Components. React 18 use without SSR streaming is not affected.

#### React internals

Most React hooks, such as `useContext`, `useState`, `useReducer`, `useEffect` and `useLayoutEffect`, are not supported as of today since server components are executed per request and aren't stateful.

#### Data Fetching & Styling

Like streaming SSR, styling and data fetching within `Suspense` on the server side are not well supported. We're still working on them.

Page level exported methods like `getInitialProps`, `getStaticProps` and `getStaticPaths` are not supported.

#### `next/head` and I18n

We are still working on support for these features.
We will be providing more updates about Server Components usage in Next.js soon.
2 changes: 1 addition & 1 deletion docs/advanced-features/using-mdx.md
Expand Up @@ -33,7 +33,7 @@ The following steps outline how to setup `@next/mdx` in your Next.js project:
1. Install the required packages:

```bash
npm install @next/mdx @mdx-js/loader
npm install @next/mdx @mdx-js/loader @mdx-js/react
```

2. Require the package and configure to support top level `.mdx` pages. The following adds the `options` object key allowing you to pass in any plugins:
Expand Down
19 changes: 19 additions & 0 deletions docs/api-reference/edge-runtime.md
Expand Up @@ -136,6 +136,25 @@ The following JavaScript language features are disabled, and **will not work:**

- `eval`: Evaluates JavaScript code represented as a string
- `new Function(evalString)`: Creates a new function with the code provided as an argument
- `WebAssembly.compile`
- `WebAssembly.instantiate` with [a buffer parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate#primary_overload_%E2%80%94_taking_wasm_binary_code)

In rare cases, your code could contain (or import) some dynamic code evaluation statements which _can not be reached at runtime_ and which can not be removed by treeshaking.
You can relax the check to allow specific files with your Middleware or Edge API Route exported configuration:

```javascript
export const config = {
runtime: 'experimental-edge', // for Edge API Routes only
unstable_allowDynamic: [
'/lib/utilities.js', // allows a single file
'/node_modules/function-bind/**', // use a glob to allow anything in the function-bind 3rd party module
],
}
```

`unstable_allowDynamic` is a [glob](https://github.com/micromatch/micromatch#matching-features), or an array of globs, ignoring dynamic code evaluation for specific files. The globs are relative to your application root folder.

Be warned that if these statements are executed on the Edge, _they will throw and cause a runtime error_.

## Related

Expand Down
20 changes: 10 additions & 10 deletions docs/api-reference/next/future/image.md
Expand Up @@ -7,11 +7,11 @@ description: Try the latest Image Optimization with the new `next/future/image`
<details>
<summary><b>Version History</b></summary>

| Version | Changes |
| --------- | --------------------------------------------------------------------------------------------------------------------------- |
| `v12.3.0` | `next/future/image` component stable. `remotePatterns` config stable. `unoptimized` config stable. `alt` property required. |
| `v12.2.4` | `fill` property added. |
| `v12.2.0` | Experimental `next/future/image` component introduced. |
| Version | Changes |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `v12.3.0` | `next/future/image` component stable. `remotePatterns` config stable. `unoptimized` config stable. `alt` property required. `onLoadingComplete` receives `<img>` |
| `v12.2.4` | `fill` property added. |
| `v12.2.0` | Experimental `next/future/image` component introduced. |

</details>

Expand All @@ -33,6 +33,7 @@ Compared to `next/image`, the new `next/future/image` component has the followin
- Removes `lazyRoot` prop since there is no native equivalent
- Removes `loader` config in favor of [`loader`](#loader) prop
- Changed `alt` prop from optional to required
- Changed `onLoadingComplete` callback to receive reference to `<img>` element

## Known Browser Bugs

Expand Down Expand Up @@ -151,7 +152,7 @@ Must be one of the following:
2. A path string. This can be either an absolute external URL,
or an internal path depending on the [loader](#loader) prop.

When using an external URL, you must add it to [domains](#domains) in `next.config.js`.
When using an external URL, you must add it to [remotePatterns](#remote-patterns) in `next.config.js`.

### width

Expand Down Expand Up @@ -306,10 +307,7 @@ Also keep in mind that the required `width` and `height` props can interact with

A callback function that is invoked once the image is completely loaded and the [placeholder](#placeholder) has been removed.

The callback function will be called with one argument, an object with the following properties:

- [`naturalWidth`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/naturalWidth)
- [`naturalHeight`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/naturalHeight)
The callback function will be called with one argument, a reference to the underlying `<img>` element.

### onLoad

Expand Down Expand Up @@ -430,6 +428,8 @@ The `**` syntax does not work in the middle of the pattern.

### Domains

> Note: We recommend using [`remotePatterns`](#remote-patterns) instead so you can restrict protocol and pathname.
Similar to [`remotePatterns`](#remote-patterns), the `domains` configuration can be used to provide a list of allowed hostnames for external images.

However, the `domains` configuration does not support wildcard pattern matching and it cannot restrict protocol, port, or pathname.
Expand Down
4 changes: 3 additions & 1 deletion docs/api-reference/next/image.md
Expand Up @@ -45,7 +45,7 @@ Must be one of the following:
or an internal path depending on the [loader](#loader) prop or [loader configuration](#loader-configuration).

When using an external URL, you must add it to
[domains](#domains) in
[remotePatterns](#remote-patterns) in
`next.config.js`.

### width
Expand Down Expand Up @@ -393,6 +393,8 @@ The `**` syntax does not work in the middle of the pattern.

### Domains

> Note: We recommend using [`remotePatterns`](#remote-patterns) instead so you can restrict protocol and pathname.
Similar to [`remotePatterns`](#remote-patterns), the `domains` configuration can be used to provide a list of allowed hostnames for external images.

However, the `domains` configuration does not support wildcard pattern matching and it cannot restrict protocol, port, or pathname.
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/next/server.md
Expand Up @@ -10,7 +10,7 @@ description: Learn about the server-only helpers for Middleware and Edge API Rou

The `NextRequest` object is an extension of the native [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) interface, with the following added methods and properties:

- `cookies` - A [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) with cookies from the `Request`. See [Using cookies in Edge Middleware](#using-cookies-in-edge-middleware)
- `cookies` - A [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) with cookies from the `Request`. See [Using cookies in Middleware](/docs/advanced-features/middleware#using-cookies)
- `nextUrl`: Includes an extended, parsed, URL object that gives you access to Next.js specific properties such as `pathname`, `basePath`, `trailingSlash` and `i18n`. Includes the following properties:
- `basePath` (`string`)
- `buildId` (`string || undefined`)
Expand Down

0 comments on commit 1b03ab2

Please sign in to comment.