Skip to content

Commit c13aa84

Browse files
authored
Merge branch 'canary' into bump-react-server-dom-webpack
2 parents fcb6bf2 + 6d08820 commit c13aa84

File tree

25 files changed

+83
-50
lines changed

25 files changed

+83
-50
lines changed

docs/advanced-features/middleware.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ The [`NextResponse`](#nextresponse) API allows you to:
140140

141141
- `redirect` the incoming request to a different URL
142142
- `rewrite` the response by displaying a given URL
143+
- Set request headers for API Routes, `getServerSideProps`, and `rewrite` destinations
143144
- Set response cookies
144145
- Set response headers
145146

@@ -177,6 +178,37 @@ export function middleware(request: NextRequest) {
177178
}
178179
```
179180

181+
## Setting Headers
182+
183+
You can set request and response headers using the `NextResponse` API.
184+
185+
```ts
186+
// middleware.ts
187+
188+
import { NextResponse } from 'next/server'
189+
import type { NextRequest } from 'next/server'
190+
191+
export function middleware(request: NextRequest) {
192+
// Clone the request headers and set a new header `x-hello-from-middleware1`
193+
const requestHeaders = new Headers(request.headers)
194+
requestHeaders.set('x-hello-from-middleware1', 'hello')
195+
196+
// You can also set request headers in NextResponse.rewrite
197+
const response = NextResponse.next({
198+
request: {
199+
// New request headers
200+
headers: requestHeaders,
201+
},
202+
})
203+
204+
// Set a new response header `x-hello-from-middleware2`
205+
response.headers.set('x-hello-from-middleware2', 'hello')
206+
return response
207+
}
208+
```
209+
210+
> **Note:** Avoid setting large headers as it might cause [431 Request Header Fields Too Large](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/431) error depending on your backend web server configuration.
211+
180212
## Related
181213

182214
<div class="card">

docs/api-reference/next/image.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ const Example = () => (
147147
<div className="grid-element">
148148
<Image
149149
src="/example.png"
150-
layout="fill"
150+
fill
151151
sizes="(max-width: 768px) 100vw,
152152
(max-width: 1200px) 50vw,
153153
33vw"

examples/with-stripe-typescript/components/Cart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { ReactNode } from 'react'
2-
import { CartProvider } from 'use-shopping-cart/react'
2+
import { CartProvider } from 'use-shopping-cart'
33
import * as config from '../config'
44

55
const Cart = ({ children }: { children: ReactNode }) => (

examples/with-stripe-typescript/components/CartSummary.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'
22

33
import StripeTestCards from '../components/StripeTestCards'
44

5-
import { useShoppingCart } from 'use-shopping-cart/react'
5+
import { useShoppingCart } from 'use-shopping-cart'
66
import { fetchPostJSON } from '../utils/api-helpers'
77

88
const CartSummary = () => {

examples/with-stripe-typescript/components/ClearCart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect } from 'react'
2-
import { useShoppingCart } from 'use-shopping-cart/react'
2+
import { useShoppingCart } from 'use-shopping-cart'
33

44
export default function ClearCart() {
55
const { clearCart } = useShoppingCart()

examples/with-stripe-typescript/components/Products.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import products from '../data/products'
22
import { formatCurrencyString } from 'use-shopping-cart'
3-
import { useShoppingCart } from 'use-shopping-cart/react'
3+
import { useShoppingCart } from 'use-shopping-cart'
44

55
const Products = () => {
66
const { addItem, removeItem } = useShoppingCart()

examples/with-stripe-typescript/package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66
"start": "next start"
77
},
88
"dependencies": {
9-
"@stripe/react-stripe-js": "1.7.0",
10-
"@stripe/stripe-js": "1.22.0",
11-
"micro": "^9.3.4",
9+
"@stripe/react-stripe-js": "1.13.0",
10+
"@stripe/stripe-js": "1.42.0",
11+
"micro": "^9.4.1",
1212
"micro-cors": "^0.1.1",
1313
"next": "latest",
14-
"react": "^17.0.2",
15-
"react-dom": "^17.0.2",
16-
"stripe": "8.200.0",
17-
"swr": "^0.1.16",
18-
"use-shopping-cart": "3.0.5"
14+
"react": "^18.2.0",
15+
"react-dom": "^18.2.0",
16+
"stripe": "10.14.0",
17+
"swr": "^1.3.0",
18+
"use-shopping-cart": "3.1.2",
19+
"redux": "4.2.0"
1920
},
2021
"devDependencies": {
21-
"@types/micro": "^7.3.3",
22-
"@types/micro-cors": "^0.1.0",
23-
"@types/node": "^13.1.2",
24-
"@types/react": "^16.9.17",
25-
"typescript": "4.5.5"
22+
"@types/micro": "^7.3.7",
23+
"@types/micro-cors": "^0.1.2",
24+
"@types/node": "^18.11.2",
25+
"@types/react": "^18.0.21",
26+
"typescript": "4.8.4"
2627
}
2728
}

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": "12.3.2-canary.31"
19+
"version": "12.3.2-canary.32"
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": "12.3.2-canary.31",
3+
"version": "12.3.2-canary.32",
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": "12.3.2-canary.31",
3+
"version": "12.3.2-canary.32",
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": "12.3.2-canary.31",
12+
"@next/eslint-plugin-next": "12.3.2-canary.32",
1313
"@rushstack/eslint-patch": "^1.1.3",
1414
"@typescript-eslint/parser": "^5.21.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": "12.3.2-canary.31",
3+
"version": "12.3.2-canary.32",
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": "12.3.2-canary.31",
3+
"version": "12.3.2-canary.32",
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": "12.3.2-canary.31",
3+
"version": "12.3.2-canary.32",
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": "12.3.2-canary.31",
3+
"version": "12.3.2-canary.32",
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": "12.3.2-canary.31",
3+
"version": "12.3.2-canary.32",
44
"keywords": [
55
"react",
66
"next",

packages/next-mdx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/mdx",
3-
"version": "12.3.2-canary.31",
3+
"version": "12.3.2-canary.32",
44
"main": "index.js",
55
"license": "MIT",
66
"repository": {

packages/next-plugin-storybook/package.json

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

packages/next-polyfill-module/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/polyfill-module",
3-
"version": "12.3.2-canary.31",
3+
"version": "12.3.2-canary.32",
44
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
55
"main": "dist/polyfill-module.js",
66
"license": "MIT",

packages/next-polyfill-nomodule/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/polyfill-nomodule",
3-
"version": "12.3.2-canary.31",
3+
"version": "12.3.2-canary.32",
44
"description": "A polyfill for non-dead, nomodule browsers.",
55
"main": "dist/polyfill-nomodule.js",
66
"license": "MIT",

packages/next-swc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/swc",
3-
"version": "12.3.2-canary.31",
3+
"version": "12.3.2-canary.32",
44
"private": true,
55
"scripts": {
66
"build-native": "napi build --platform -p next-swc-napi --cargo-name next_swc_napi --features plugin --js false native",

packages/next/client/components/react-dev-overlay/hot-reloader.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function performFullReload(err: any, sendMessage: any) {
128128

129129
// Attempt to update code on the fly, fall back to a hard reload.
130130
function tryApplyUpdates(
131-
onHotUpdateSuccess: any,
131+
onHotUpdateSuccess: (hasUpdates: boolean) => void,
132132
sendMessage: any,
133133
dispatch: DispatchFn
134134
) {
@@ -174,7 +174,7 @@ function tryApplyUpdates(
174174
if (isUpdateAvailable()) {
175175
// While we were updating, there was a new update! Do it again.
176176
tryApplyUpdates(
177-
hasUpdates ? onBuildOk : onHotUpdateSuccess,
177+
hasUpdates ? () => onBuildOk(dispatch) : onHotUpdateSuccess,
178178
sendMessage,
179179
dispatch
180180
)

packages/next/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "next",
3-
"version": "12.3.2-canary.31",
3+
"version": "12.3.2-canary.32",
44
"description": "The React Framework",
55
"main": "./dist/server/next.js",
66
"license": "MIT",
@@ -74,7 +74,7 @@
7474
]
7575
},
7676
"dependencies": {
77-
"@next/env": "12.3.2-canary.31",
77+
"@next/env": "12.3.2-canary.32",
7878
"@swc/helpers": "0.4.11",
7979
"caniuse-lite": "^1.0.30001406",
8080
"postcss": "8.4.14",
@@ -125,11 +125,11 @@
125125
"@hapi/accept": "5.0.2",
126126
"@napi-rs/cli": "2.12.0",
127127
"@napi-rs/triples": "1.1.0",
128-
"@next/polyfill-module": "12.3.2-canary.31",
129-
"@next/polyfill-nomodule": "12.3.2-canary.31",
130-
"@next/react-dev-overlay": "12.3.2-canary.31",
131-
"@next/react-refresh-utils": "12.3.2-canary.31",
132-
"@next/swc": "12.3.2-canary.31",
128+
"@next/polyfill-module": "12.3.2-canary.32",
129+
"@next/polyfill-nomodule": "12.3.2-canary.32",
130+
"@next/react-dev-overlay": "12.3.2-canary.32",
131+
"@next/react-refresh-utils": "12.3.2-canary.32",
132+
"@next/swc": "12.3.2-canary.32",
133133
"@segment/ajv-human-errors": "2.1.2",
134134
"@taskr/clear": "1.1.0",
135135
"@taskr/esnext": "1.1.0",

packages/react-dev-overlay/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/react-dev-overlay",
3-
"version": "12.3.2-canary.31",
3+
"version": "12.3.2-canary.32",
44
"description": "A development-only overlay for developing React applications.",
55
"repository": {
66
"url": "vercel/next.js",

packages/react-refresh-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/react-refresh-utils",
3-
"version": "12.3.2-canary.31",
3+
"version": "12.3.2-canary.32",
44
"description": "An experimental package providing utilities for React Refresh.",
55
"repository": {
66
"url": "vercel/next.js",

pnpm-lock.yaml

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)