Skip to content

Commit 8b684ee

Browse files
authored
Merge branch 'canary' into feat/opt-out-error-dark-mode
2 parents e975e69 + 87e93a2 commit 8b684ee

File tree

247 files changed

+3931
-3766
lines changed

Some content is hidden

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

247 files changed

+3931
-3766
lines changed

.github/workflows/build_test_deploy.yml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ name: Build, test, and deploy
88

99
env:
1010
NAPI_CLI_VERSION: 2.7.0
11-
TURBO_VERSION: 1.2.6
11+
TURBO_VERSION: 1.2.9
1212
RUST_TOOLCHAIN: nightly-2022-02-23
1313

1414
jobs:
@@ -908,6 +908,47 @@ jobs:
908908
- run: ./scripts/publish-native.js $GITHUB_REF
909909
- run: ./scripts/publish-release.sh
910910

911+
testDeployE2E:
912+
name: E2E (deploy)
913+
runs-on: ubuntu-latest
914+
needs: [publishRelease]
915+
env:
916+
NEXT_TELEMETRY_DISABLED: 1
917+
NEXT_TEST_JOB: 1
918+
VERCEL_TEST_TOKEN: ${{ secrets.VERCEL_TEST_TOKEN }}
919+
VERCEL_TEST_TEAM: 'vtest314-next-e2e-tests'
920+
steps:
921+
- name: Setup node
922+
uses: actions/setup-node@v3
923+
with:
924+
node-version: 16
925+
check-latest: true
926+
927+
- uses: actions/cache@v3
928+
id: restore-build
929+
with:
930+
path: ./*
931+
key: ${{ github.sha }}-${{ github.run_number }}
932+
933+
- run: npm i -g [email protected] && npx playwright install-deps
934+
name: Install playwright dependencies
935+
936+
- run: RESET_VC_PROJECT=true node scripts/reset-vercel-project.mjs
937+
name: Reset test project
938+
939+
- run: NEXT_TEST_MODE=deploy node run-tests.js --type e2e
940+
name: Run test/e2e (deploy)
941+
942+
- name: Upload test trace
943+
if: always()
944+
uses: actions/upload-artifact@v3
945+
with:
946+
name: test-trace
947+
if-no-files-found: ignore
948+
retention-days: 2
949+
path: |
950+
test/traces
951+
911952
releaseStats:
912953
name: Release Stats
913954
runs-on: ubuntu-latest

.github/workflows/pull_request_stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
# since the repo's dependencies aren't installed we need
7979
# to install napi globally
8080
- run: npm i -g @napi-rs/[email protected]
81-
- run: npm i -g [email protected].6
81+
- run: npm i -g [email protected].9
8282

8383
- name: Build
8484
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ test/tmp/**
2929
# Editors
3030
**/.idea
3131
**/.#*
32+
.nvmrc
3233

3334
# examples
3435
examples/**/out

docs/advanced-features/compiler.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ First, update to the latest version of Next.js: `npm install next@latest`. Then,
187187
}
188188
```
189189

190-
## Experimental Features
191-
192190
### Emotion
193191

194192
We're working to port `@emotion/babel-plugin` to the Next.js Compiler.
@@ -199,7 +197,7 @@ First, update to the latest version of Next.js: `npm install next@latest`. Then,
199197
// next.config.js
200198

201199
module.exports = {
202-
experimental: {
200+
compiler: {
203201
emotion: boolean | {
204202
// default is true. It will be disabled when build type is production.
205203
sourceMap?: boolean,
@@ -219,6 +217,8 @@ module.exports = {
219217

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

220+
## Experimental Features
221+
222222
### Minification
223223

224224
You can opt-in to using the Next.js compiler for minification. This is 7x faster than Terser.

docs/advanced-features/i18n-routing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ module.exports = {
164164
Next, we can use [Middleware](/docs/middleware.md) to add custom routing rules:
165165

166166
```js
167-
// pages/_middleware.ts
167+
// middleware.ts
168168

169169
import { NextRequest, NextResponse } from 'next/server'
170170

docs/advanced-features/middleware.md

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,29 @@ Middleware enables you to use code over configuration. This gives you full flexi
2424
npm install next@latest
2525
```
2626

27-
2. Then, create a `_middleware.ts` file under your `/pages` directory.
27+
2. Then, create a `middleware.ts` file under your project root directory.
2828

29-
3. Finally, export a middleware function from the `_middleware.ts` file.
29+
3. Finally, export a middleware function from the `middleware.ts` file.
3030

3131
```jsx
32-
// pages/_middleware.ts
32+
// middleware.ts
3333

34-
import type { NextFetchEvent, NextRequest } from 'next/server'
34+
import type { NextRequest, NextResponse } from 'next/server'
35+
import { areCredentialsValid } from '../lib'
3536

36-
export function middleware(req: NextRequest, ev: NextFetchEvent) {
37-
return new Response('Hello, world!')
37+
export function middleware(req: NextRequest) {
38+
if (areCredentialsValid(req.headers.get('authorization')) {
39+
return NextResponse.next()
40+
}
41+
return NextResponse.redirect(`/login?from=${req.nextUrl.pathname}`)
3842
}
3943
```
4044
4145
In this example, we use the standard Web API Response ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Response)).
4246
4347
## API
4448
45-
Middleware is created by using a `middleware` function that lives inside a `_middleware` file. Its API is based upon the native [`FetchEvent`](https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent), [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response), and [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) objects.
49+
Middleware is created by using a `middleware` function that lives inside a `middleware` file. Its API is based upon the native [`FetchEvent`](https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent), [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response), and [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) objects.
4650
4751
These native Web API objects are extended to give you more control over how you manipulate and configure a response, based on the incoming requests.
4852
@@ -75,31 +79,6 @@ Middleware can be used for anything that shares logic for a set of pages, includ
7579
7680
## Execution Order
7781
78-
If your Middleware is created in `/pages/_middleware.ts`, it will run on all routes within the `/pages` directory. The below example assumes you have `about.tsx` and `teams.tsx` routes.
79-
80-
```bash
81-
- package.json
82-
- /pages
83-
_middleware.ts # Will run on all routes under /pages
84-
index.tsx
85-
about.tsx
86-
teams.tsx
87-
```
88-
89-
If you _do_ have sub-directories with nested routes, Middleware will run from the top down. For example, if you have `/pages/about/_middleware.ts` and `/pages/about/team/_middleware.ts`, `/about` will run first and then `/about/team`. The below example shows how this works with a nested routing structure.
90-
91-
```bash
92-
- package.json
93-
- /pages
94-
index.tsx
95-
- /about
96-
_middleware.ts # Will run first
97-
about.tsx
98-
- /teams
99-
_middleware.ts # Will run second
100-
teams.tsx
101-
```
102-
10382
Middleware runs directly after `redirects` and `headers`, before the first filesystem lookup. This excludes `/_next` files.
10483
10584
## Deployment

docs/advanced-features/react-18/server-components.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,7 @@ export default function Document() {
9494

9595
### `next/app`
9696

97-
If you're using `_app.js`, the usage is the same as [Custom App](/docs/advanced-features/custom-app).
98-
If you're using `_app.server.js` as a server component, see the example below where it only receives the `children` prop as React elements. You can wrap any other client or server components around `children` to customize the layout of your app.
99-
100-
```js
101-
// pages/_app.server.js
102-
export default function App({ children }) {
103-
return children
104-
}
105-
```
97+
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.
10698

10799
### Routing
108100

docs/api-reference/create-next-app.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ pnpm create next-app -- --ts
3131
- **--ts, --typescript** - Initialize as a TypeScript project.
3232
- **-e, --example [name]|[github-url]** - An example to bootstrap the app with. You can use an example name from the [Next.js repo](https://github.com/vercel/next.js/tree/canary/examples) or a GitHub URL. The URL can use any branch and/or subdirectory.
3333
- **--example-path [path-to-example]** - In a rare case, your GitHub URL might contain a branch name with a slash (e.g. bug/fix-1) and the path to the example (e.g. foo/bar). In this case, you must specify the path to the example separately: `--example-path foo/bar`
34-
- **--use-npm** - Explicitly tell the CLI to bootstrap the app using npm. To bootstrap using yarn we recommend running `yarn create next-app`
35-
- **--use-pnpm** - Explicitly tell the CLI to bootstrap the app using pnpm. To bootstrap using yarn we recommend running `yarn create next-app`
34+
- **--use-npm** - Explicitly tell the CLI to bootstrap the app using npm
35+
- **--use-pnpm** - Explicitly tell the CLI to bootstrap the app using pnpm
36+
37+
Note: To bootstrap using `yarn` we recommend running `yarn create next-app`
3638

3739
### Why use Create Next App?
3840

docs/api-reference/next.config.js/custom-page-extensions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616

1717
> **Note**: The default value of `pageExtensions` is [`['tsx', 'ts', 'jsx', 'js']`](https://github.com/vercel/next.js/blob/f1dbc9260d48c7995f6c52f8fbcc65f08e627992/packages/next/server/config-shared.ts#L161).
1818
19-
> **Note**: configuring `pageExtensions` also affects `_document.js`, `_app.js`, `_middleware.js` as well as files under `pages/api/`. For example, setting `pageExtensions: ['page.tsx', 'page.ts']` means the following files: `_document.tsx`, `_app.tsx`, `_middleware.ts`, `pages/users.tsx` and `pages/api/users.ts` will have to be renamed to `_document.page.tsx`, `_app.page.tsx`, `_middleware.page.ts`, `pages/users.page.tsx` and `pages/api/users.page.ts` respectively.
19+
> **Note**: configuring `pageExtensions` also affects `_document.js`, `_app.js`, `middleware.js` as well as files under `pages/api/`. For example, setting `pageExtensions: ['page.tsx', 'page.ts']` means the following files: `_document.tsx`, `_app.tsx`, `middleware.ts`, `pages/users.tsx` and `pages/api/users.ts` will have to be renamed to `_document.page.tsx`, `_app.page.tsx`, `middleware.page.ts`, `pages/users.page.tsx` and `pages/api/users.page.ts` respectively.
2020
2121
## Including non-page files in the `pages` directory
2222

@@ -32,7 +32,7 @@ module.exports = {
3232

3333
Then rename your pages to have a file extension that includes `.page` (ex. rename `MyPage.tsx` to `MyPage.page.tsx`).
3434

35-
> **Note**: Make sure you also rename `_document.js`, `_app.js`, `_middleware.js`, as well as files under `pages/api/`.
35+
> **Note**: Make sure you also rename `_document.js`, `_app.js`, `middleware.js`, as well as files under `pages/api/`.
3636
3737
Without this config, Next.js assumes every tsx/ts/jsx/js file in the `pages` directory is a page or API route, and may expose unintended routes vulnerable to denial of service attacks, or throw an error like the following when building the production bundle:
3838

docs/api-reference/next/server.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The `next/server` module provides several exports for server-only helpers, such
88

99
## NextMiddleware
1010

11-
Middleware is created by using a `middleware` function that lives inside a `_middleware` file. The Middleware API is based upon the native [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request), [`FetchEvent`](https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent), and [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) objects.
11+
Middleware is created by using a `middleware` function that lives inside a `middleware` file. The Middleware API is based upon the native [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request), [`FetchEvent`](https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent), and [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) objects.
1212

1313
These native Web API objects are extended to give you more control over how you manipulate and configure a response, based on the incoming requests.
1414

@@ -105,7 +105,6 @@ The following static methods are available on the `NextResponse` class directly:
105105
- `redirect()` - Returns a `NextResponse` with a redirect set
106106
- `rewrite()` - Returns a `NextResponse` with a rewrite set
107107
- `next()` - Returns a `NextResponse` that will continue the middleware chain
108-
- `json()` - A convenience method to create a response that encodes the provided JSON data
109108

110109
```ts
111110
import { NextResponse } from 'next/server'
@@ -120,7 +119,7 @@ export function middleware(req: NextRequest) {
120119
return NextResponse.rewrite('/not-home')
121120
}
122121

123-
return NextResponse.json({ message: 'Hello World!' })
122+
return NextResponse.next()
124123
}
125124
```
126125

@@ -183,6 +182,21 @@ console.log(NODE_ENV)
183182
console.log(process.env)
184183
```
185184

185+
### The body limitation
186+
187+
When using middlewares, it is not permitted to change the response body: you can only set responses headers.
188+
Returning a body from a middleware function will issue an `500` server error with an explicit response message.
189+
190+
The `NextResponse` API (which eventually is tweaking response headers) allows you to:
191+
192+
- redirect the incoming request to a different url
193+
- rewrite the response by displaying a given url
194+
- set response cookies
195+
- set response headers
196+
197+
These are solid tools to implement cases such as A/B testing, authentication, feature flags, bot protection...
198+
A middleware with the ability to change the response's body would bypass Next.js routing logic.
199+
186200
## Related
187201

188202
<div class="card">

0 commit comments

Comments
 (0)