Skip to content

Commit

Permalink
Merge branch 'canary' into next-middleware-preflight-locale-prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
nkzawa committed Apr 7, 2022
2 parents a568061 + ad99734 commit 4a9d9e3
Show file tree
Hide file tree
Showing 56 changed files with 351 additions and 996 deletions.
19 changes: 7 additions & 12 deletions docs/advanced-features/i18n-routing.md
Expand Up @@ -170,24 +170,19 @@ import { NextRequest, NextResponse } from 'next/server'

const PUBLIC_FILE = /\.(.*)$/

const stripDefaultLocale = (str: string): string => {
const stripped = str.replace('/default', '')
return stripped
}

export function middleware(request: NextRequest) {
const shouldHandleLocale =
!PUBLIC_FILE.test(request.nextUrl.pathname) &&
!request.nextUrl.pathname.includes('/api/') &&
request.nextUrl.locale === 'default'

return shouldHandleLocale
? NextResponse.redirect(
`/en${stripDefaultLocale(request.nextUrl.pathname)}${
request.nextUrl.search
}`
)
: undefined
if (shouldHandleLocale) {
const url = request.nextUrl.clone()
url.pathname = `/en${request.nextUrl.pathname}`
return NextResponse.redirect(url)
}

return undefined
}
```

Expand Down
21 changes: 21 additions & 0 deletions errors/invalid-getserversideprops-return-value.md
@@ -0,0 +1,21 @@
# Invalid getServerSideProps Return Value

#### Why This Error Occurred

In one of the page's `getServerSideProps` the return value had the incorrect shape.

#### Possible Ways to Fix It

Make sure to return the following shape from `getServerSideProps`:

```ts
export async function getServerSideProps(ctx: GetServerSidePropsContext) {
return {
props: { [key: string]: any }
}
}
```

### Useful Links

- [getServerSideProps](https://nextjs.org/docs/api-reference/data-fetching/get-server-side-props)
4 changes: 4 additions & 0 deletions errors/manifest.json
Expand Up @@ -645,6 +645,10 @@
{
"title": "import-next",
"path": "/errors/import-next.md"
},
{
"title": "invalid-getserversideprops-return-value",
"path": "/errors/invalid-getserversideprops-return-value.md"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "12.1.5-canary.2"
"version": "12.1.5-canary.3"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "12.1.5-canary.2",
"version": "12.1.5-canary.3",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "12.1.5-canary.2",
"version": "12.1.5-canary.3",
"description": "ESLint configuration used by NextJS.",
"main": "index.js",
"license": "MIT",
Expand All @@ -9,7 +9,7 @@
"directory": "packages/eslint-config-next"
},
"dependencies": {
"@next/eslint-plugin-next": "12.1.5-canary.2",
"@next/eslint-plugin-next": "12.1.5-canary.3",
"@rushstack/eslint-patch": "1.0.8",
"@typescript-eslint/parser": "5.10.1",
"eslint-import-resolver-node": "0.3.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "12.1.5-canary.2",
"version": "12.1.5-canary.3",
"description": "ESLint plugin for NextJS.",
"main": "lib/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "12.1.5-canary.2",
"version": "12.1.5-canary.3",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "12.1.5-canary.2",
"version": "12.1.5-canary.3",
"license": "MIT",
"dependencies": {
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "12.1.5-canary.2",
"version": "12.1.5-canary.3",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "12.1.5-canary.2",
"version": "12.1.5-canary.3",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "12.1.5-canary.2",
"version": "12.1.5-canary.3",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "12.1.5-canary.2",
"version": "12.1.5-canary.3",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "12.1.5-canary.2",
"version": "12.1.5-canary.3",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "12.1.5-canary.2",
"version": "12.1.5-canary.3",
"private": true,
"scripts": {
"build-native": "napi build --platform --cargo-name next_swc_napi native",
Expand Down
35 changes: 9 additions & 26 deletions packages/next/build/index.ts
Expand Up @@ -450,18 +450,12 @@ export default async function build(
namedRegex?: string
routeKeys?: { [key: string]: string }
}>
dynamicRoutes: Array<
| {
page: string
regex: string
namedRegex?: string
routeKeys?: { [key: string]: string }
}
| {
page: string
isMiddleware: true
}
>
dynamicRoutes: Array<{
page: string
regex: string
namedRegex?: string
routeKeys?: { [key: string]: string }
}>
dataRoutes: Array<{
page: string
routeKeys?: { [key: string]: string }
Expand All @@ -480,14 +474,14 @@ export default async function build(
localeDetection?: false
}
} = nextBuildSpan.traceChild('generate-routes-manifest').traceFn(() => ({
version: 4,
version: 3,
pages404: true,
basePath: config.basePath,
redirects: redirects.map((r: any) => buildCustomRoute(r, 'redirect')),
headers: headers.map((r: any) => buildCustomRoute(r, 'header')),
dynamicRoutes: getSortedRoutes(pageKeys)
.filter((page) => isDynamicRoute(page))
.map(pageToRouteOrMiddleware),
.filter((page) => isDynamicRoute(page) && !page.match(MIDDLEWARE_ROUTE))
.map(pageToRoute),
staticRoutes: getSortedRoutes(pageKeys)
.filter(
(page) =>
Expand Down Expand Up @@ -2206,14 +2200,3 @@ function pageToRoute(page: string) {
namedRegex: routeRegex.namedRegex,
}
}

function pageToRouteOrMiddleware(page: string) {
if (page.match(MIDDLEWARE_ROUTE)) {
return {
page: page.replace(/\/_middleware$/, '') || '/',
isMiddleware: true as const,
}
}

return pageToRoute(page)
}
2 changes: 1 addition & 1 deletion packages/next/client/index.tsx
Expand Up @@ -778,7 +778,7 @@ if (process.env.__NEXT_RSC) {
if (serialized) {
const readable = new ReadableStream({
start(controller) {
controller.enqueue(new TextEncoder().encode(serialized))
controller.enqueue(encoder.encode(serialized))
controller.close()
},
})
Expand Down
14 changes: 7 additions & 7 deletions packages/next/package.json
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "12.1.5-canary.2",
"version": "12.1.5-canary.3",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -69,7 +69,7 @@
]
},
"dependencies": {
"@next/env": "12.1.5-canary.2",
"@next/env": "12.1.5-canary.3",
"caniuse-lite": "^1.0.30001283",
"postcss": "8.4.5",
"styled-jsx": "5.0.1"
Expand Down Expand Up @@ -117,11 +117,11 @@
"@hapi/accept": "5.0.2",
"@napi-rs/cli": "2.4.4",
"@napi-rs/triples": "1.1.0",
"@next/polyfill-module": "12.1.5-canary.2",
"@next/polyfill-nomodule": "12.1.5-canary.2",
"@next/react-dev-overlay": "12.1.5-canary.2",
"@next/react-refresh-utils": "12.1.5-canary.2",
"@next/swc": "12.1.5-canary.2",
"@next/polyfill-module": "12.1.5-canary.3",
"@next/polyfill-nomodule": "12.1.5-canary.3",
"@next/react-dev-overlay": "12.1.5-canary.3",
"@next/react-refresh-utils": "12.1.5-canary.3",
"@next/swc": "12.1.5-canary.3",
"@peculiar/webcrypto": "1.3.1",
"@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0",
Expand Down

0 comments on commit 4a9d9e3

Please sign in to comment.