Skip to content

Commit db6b71b

Browse files
authored
Merge branch 'canary' into add-turbo-powered-packing
2 parents ce47a11 + 0572e21 commit db6b71b

File tree

87 files changed

+456
-379
lines changed

Some content is hidden

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

87 files changed

+456
-379
lines changed

.github/labeler.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,18 @@
3131
{ "type": "user", "pattern": "styfle" },
3232
{ "type": "user", "pattern": "leerob" },
3333
{ "type": "user", "pattern": "kdy1" },
34-
{ "type": "user", "pattern": "timneutkens" }
34+
{ "type": "user", "pattern": "timneutkens" },
35+
{ "type": "user", "pattern": "sebmarkbage" },
36+
{ "type": "user", "pattern": "wyattjoh" },
37+
{ "type": "user", "pattern": "kwonoj" },
38+
{ "type": "user", "pattern": "gnoff" },
39+
{ "type": "user", "pattern": "padmaia" },
40+
{ "type": "user", "pattern": "Brooooooklyn" },
41+
{ "type": "user", "pattern": "ForsakenHarmony" },
42+
{ "type": "user", "pattern": "feedthejim" },
43+
{ "type": "user", "pattern": "JanKaifer" },
44+
{ "type": "user", "pattern": "balazsorban44" },
45+
{ "type": "user", "pattern": "hanneslund" }
3546
],
3647
"created-by: Next.js docs team": [
3748
{ "type": "user", "pattern": "MaedahBatool" },

docs/advanced-features/middleware.md

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ description: Learn how to use Middleware to run code before a request is complet
99

1010
| Version | Changes |
1111
| --------- | ------------------------------------------------------------------------------------------ |
12+
| `v13.1.0` | Advanced Middleware flags added |
1213
| `v13.0.0` | Middleware can modify request headers, response headers, and send responses |
1314
| `v12.2.0` | Middleware is stable |
1415
| `v12.0.9` | Enforce absolute URLs in Edge Runtime ([PR](https://github.com/vercel/next.js/pull/33410)) |
@@ -220,18 +221,7 @@ export function middleware(request: NextRequest) {
220221
221222
## Producing a Response
222223

223-
You can respond to middleware directly by returning a `NextResponse` (responding from middleware is available since Next.js v13.0.0).
224-
225-
To enable middleware responses, update `next.config.js`:
226-
227-
```js
228-
// next.config.js
229-
module.exports = {
230-
experimental: {
231-
allowMiddlewareResponseBody: true,
232-
},
233-
}
234-
```
224+
You can respond to middleware directly by returning a `NextResponse` (responding from middleware is available since Next.js v13.1.0).
235225

236226
Once enabled, you can provide a response from middleware using the `Response` or `NextResponse` API:
237227

@@ -257,6 +247,66 @@ export function middleware(request: NextRequest) {
257247
}
258248
```
259249

250+
## Advanced Middleware Flags
251+
252+
In `v13.1` of Next.js two additional flags were introduced for middleware, `skipMiddlewareUrlNormalize` and `skipTrailingSlashRedirect` to handle advanced use cases.
253+
254+
`skipTrailingSlashRedirect` allows disabling Next.js default redirects for adding or removing trailing slashes allowing custom handling inside middleware which can allow maintaining the trailing slash for some paths but not others allowing easier incremental migrations.
255+
256+
```js
257+
// next.config.js
258+
module.exports = {
259+
skipTrailingSlashRedirect: true,
260+
}
261+
```
262+
263+
```js
264+
// middleware.js
265+
266+
const legacyPrefixes = ['/docs', '/blog']
267+
268+
export default async function middleware(req) {
269+
const { pathname } = req.nextUrl
270+
271+
if (legacyPrefixes.some((prefix) => pathname.startsWith(prefix))) {
272+
return NextResponse.next()
273+
}
274+
275+
// apply trailing slash handling
276+
if (
277+
!pathname.endsWith('/') &&
278+
!pathname.match(/((?!\.well-known(?:\/.*)?)(?:[^/]+\/)*[^/]+\.\w+)/)
279+
) {
280+
req.nextUrl.pathname += '/'
281+
return NextResponse.redirect(req.nextUrl)
282+
}
283+
}
284+
```
285+
286+
`skipMiddlewareUrlNormalize` allows disabling the URL normalizing Next.js does to make handling direct visits and client-transitions the same. There are some advanced cases where you need full control using the original URL which this unlocks.
287+
288+
```js
289+
// next.config.js
290+
291+
module.exports = {
292+
skipMiddlewareUrlNormalize: true,
293+
}
294+
```
295+
296+
```js
297+
// middleware.js
298+
299+
export default async function middleware(req) {
300+
const { pathname } = req.nextUrl
301+
302+
// GET /_next/data/build-id/hello.json
303+
304+
console.log(pathname)
305+
// with the flag this now /_next/data/build-id/hello.json
306+
// without the flag this would be normalized to /hello
307+
}
308+
```
309+
260310
## Related
261311

262312
<div class="card">

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"registry": "https://registry.npmjs.org/"
1717
}
1818
},
19-
"version": "13.0.8-canary.2"
19+
"version": "13.0.8-canary.4"
2020
}

packages/create-next-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-next-app",
3-
"version": "13.0.8-canary.2",
3+
"version": "13.0.8-canary.4",
44
"keywords": [
55
"react",
66
"next",

packages/eslint-config-next/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-config-next",
3-
"version": "13.0.8-canary.2",
3+
"version": "13.0.8-canary.4",
44
"description": "ESLint configuration used by NextJS.",
55
"main": "index.js",
66
"license": "MIT",
@@ -9,7 +9,7 @@
99
"directory": "packages/eslint-config-next"
1010
},
1111
"dependencies": {
12-
"@next/eslint-plugin-next": "13.0.8-canary.2",
12+
"@next/eslint-plugin-next": "13.0.8-canary.4",
1313
"@rushstack/eslint-patch": "^1.1.3",
1414
"@typescript-eslint/parser": "^5.42.0",
1515
"eslint-import-resolver-node": "^0.3.6",

packages/eslint-plugin-next/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/eslint-plugin-next",
3-
"version": "13.0.8-canary.2",
3+
"version": "13.0.8-canary.4",
44
"description": "ESLint plugin for NextJS.",
55
"main": "dist/index.js",
66
"license": "MIT",

packages/font/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/font",
3-
"version": "13.0.8-canary.2",
3+
"version": "13.0.8-canary.4",
44
"repository": {
55
"url": "vercel/next.js",
66
"directory": "packages/font"

packages/next-bundle-analyzer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/bundle-analyzer",
3-
"version": "13.0.8-canary.2",
3+
"version": "13.0.8-canary.4",
44
"main": "index.js",
55
"types": "index.d.ts",
66
"license": "MIT",

packages/next-codemod/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/codemod",
3-
"version": "13.0.8-canary.2",
3+
"version": "13.0.8-canary.4",
44
"license": "MIT",
55
"dependencies": {
66
"chalk": "4.1.0",

packages/next-env/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/env",
3-
"version": "13.0.8-canary.2",
3+
"version": "13.0.8-canary.4",
44
"keywords": [
55
"react",
66
"next",

0 commit comments

Comments
 (0)