Skip to content

Commit

Permalink
Merge branch 'canary' into fix-image-cache-race-condition
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Feb 2, 2022
2 parents c2beb84 + aae0370 commit 552fa7f
Show file tree
Hide file tree
Showing 58 changed files with 454 additions and 190 deletions.
4 changes: 3 additions & 1 deletion docs/advanced-features/using-mdx.md
Expand Up @@ -46,6 +46,8 @@ The following steps outline how to setup `@next/mdx` in your Next.js project:
options: {
remarkPlugins: [],
rehypePlugins: [],
// If you use `MDXProvider`, uncomment the following line.
// providerImportSource: "@mdx-js/react",
},
})
module.exports = withMDX({
Expand Down Expand Up @@ -153,7 +155,7 @@ The above generates the following `HTML`:
</ul>
```

When you want to style your own elements to give a custom feel to your website or application, you can pass in shortcodes. These are your own custom components that map to `HTML` elements. To do this you use the `MDXProvider` and pass a components object as a prop. Each object key in the components object maps to a `HTML` element name.
When you want to style your own elements to give a custom feel to your website or application, you can pass in shortcodes. These are your own custom components that map to `HTML` elements. To do this you use the `MDXProvider` and pass a components object as a prop. Each object key in the components object maps to a `HTML` element name. You also need to specify `providerImportSource: "@mdx-js/react"` in `next.config.js`.

```jsx
// pages/index.js
Expand Down
4 changes: 3 additions & 1 deletion docs/api-routes/api-middlewares.md
Expand Up @@ -34,7 +34,9 @@ export const config = {

The `api` object includes all configs available for API routes.

`bodyParser` Enables body parsing, you can disable it if you want to consume it as a `Stream`:
`bodyParser` is automatically enabled. If you want to consume the body as a `Stream` or with [`raw-body`](https://www.npmjs.com/package/raw-body), you can set this to `false`.

One use case for disabling the automatic `bodyParsing` is to allow you to verify the raw body of a **webhook** request, for example [from GitHub](https://docs.github.com/en/developers/webhooks-and-events/webhooks/securing-your-webhooks#validating-payloads-from-github).

```js
export const config = {
Expand Down
4 changes: 2 additions & 2 deletions examples/with-docker/Dockerfile
Expand Up @@ -7,8 +7,8 @@ COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

# If using npm with a `package-lock.json` comment out above and use below instead
# COPY package.json package-lock.json /
# RUN npm install
# COPY package.json package-lock.json ./
# RUN npm ci

# Rebuild the source code only when needed
FROM node:16-alpine AS builder
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "12.0.11-canary.0"
"version": "12.0.11-canary.2"
}
11 changes: 4 additions & 7 deletions packages/create-next-app/helpers/install.ts
Expand Up @@ -69,16 +69,13 @@ export function install(
* install`.
*/
args = ['install']
if (useYarn) {
if (!isOnline) {
console.log(chalk.yellow('You appear to be offline.'))
if (!isOnline) {
console.log(chalk.yellow('You appear to be offline.'))
if (useYarn) {
console.log(chalk.yellow('Falling back to the local Yarn cache.'))
console.log()
args.push('--offline')
}
} else {
if (!isOnline) {
console.log(chalk.yellow('You appear to be offline.'))
} else {
console.log()
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "12.0.11-canary.0",
"version": "12.0.11-canary.2",
"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.0.11-canary.0",
"version": "12.0.11-canary.2",
"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.0.11-canary.0",
"@next/eslint-plugin-next": "12.0.11-canary.2",
"@rushstack/eslint-patch": "^1.0.8",
"@typescript-eslint/parser": "^5.0.0",
"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.0.11-canary.0",
"version": "12.0.11-canary.2",
"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.0.11-canary.0",
"version": "12.0.11-canary.2",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
11 changes: 4 additions & 7 deletions packages/next-codemod/lib/install.ts
Expand Up @@ -69,16 +69,13 @@ export function install(
* install`.
*/
args = ['install']
if (useYarn) {
if (!isOnline) {
console.log(chalk.yellow('You appear to be offline.'))
if (!isOnline) {
console.log(chalk.yellow('You appear to be offline.'))
if (useYarn) {
console.log(chalk.yellow('Falling back to the local Yarn cache.'))
console.log()
args.push('--offline')
}
} else {
if (!isOnline) {
console.log(chalk.yellow('You appear to be offline.'))
} else {
console.log()
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "12.0.11-canary.0",
"version": "12.0.11-canary.2",
"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.0.11-canary.0",
"version": "12.0.11-canary.2",
"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.0.11-canary.0",
"version": "12.0.11-canary.2",
"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.0.11-canary.0",
"version": "12.0.11-canary.2",
"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.0.11-canary.0",
"version": "12.0.11-canary.2",
"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.0.11-canary.0",
"version": "12.0.11-canary.2",
"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.0.11-canary.0",
"version": "12.0.11-canary.2",
"private": true,
"scripts": {
"build-native": "napi build --platform --cargo-name next_swc_napi native",
Expand Down
Expand Up @@ -44,37 +44,25 @@ export default async function middlewareSSRLoader(this: any) {
}
// Set server context
self.__current_route = ${JSON.stringify(page)}
self.__server_context = {
Component: pageMod.default,
pageConfig: pageMod.config || {},
buildManifest,
reactLoadableManifest,
Document,
App,
getStaticProps: pageMod.getStaticProps,
getServerSideProps: pageMod.getServerSideProps,
getStaticPaths: pageMod.getStaticPaths,
ComponentMod: undefined,
serverComponentManifest: ${isServerComponent} ? rscManifest : null,
// components
errorMod,
error500Mod,
// renderOpts
page: ${JSON.stringify(page)},
buildId: ${JSON.stringify(buildId)},
dev: ${dev},
env: process.env,
supportsDynamicHTML: true,
concurrentFeatures: true,
disableOptimizedLoading: true,
}
const render = getRender({
dev: ${dev},
page: ${JSON.stringify(page)},
pageMod,
errorMod,
error500Mod,
App,
Document,
buildManifest,
reactLoadableManifest,
serverComponentManifest: ${isServerComponent} ? rscManifest : null,
isServerComponent: ${isServerComponent},
config: ${stringifiedConfig},
buildId: ${JSON.stringify(buildId)},
})
export default function rscMiddleware(opts) {
Expand Down
@@ -1,4 +1,7 @@
import type { NextConfig } from '../../../../server/config-shared'
import type { DocumentType, AppType } from '../../../../shared/lib/utils'
import type { BuildManifest } from '../../../../server/get-page-files'
import type { ReactLoadableManifest } from '../../../../server/load-components'

import { NextRequest } from '../../../../server/web/spec-extension/request'
import { toNodeHeaders } from '../../../../server/web/utils'
Expand All @@ -20,20 +23,98 @@ function sendError(req: any, error: Error) {
})
}

// Polyfilled for `path-browserify` inside the Web Server.
process.cwd = () => ''

export function getRender({
dev,
page,
pageMod,
errorMod,
error500Mod,
Document,
App,
buildManifest,
reactLoadableManifest,
serverComponentManifest,
isServerComponent,
config,
buildId,
}: {
Document: any
dev: boolean
page: string
pageMod: any
errorMod: any
error500Mod: any
Document: DocumentType
App: AppType
buildManifest: BuildManifest
reactLoadableManifest: ReactLoadableManifest
serverComponentManifest: any | null
isServerComponent: boolean
config: NextConfig
buildId: string
}) {
// Polyfilled for `path-browserify`.
process.cwd = () => ''
const baseLoadComponentResult = {
dev,
buildManifest,
reactLoadableManifest,
Document,
App,
}

const server = new WebServer({
conf: config,
minimalMode: true,
webServerConfig: {
extendRenderOpts: {
buildId,
supportsDynamicHTML: true,
concurrentFeatures: true,
disableOptimizedLoading: true,
serverComponentManifest,
},
loadComponent: async (pathname) => {
if (pathname === page) {
return {
...baseLoadComponentResult,
Component: pageMod.default,
pageConfig: pageMod.config || {},
getStaticProps: pageMod.getStaticProps,
getServerSideProps: pageMod.getServerSideProps,
getStaticPaths: pageMod.getStaticPaths,
ComponentMod: pageMod,
}
}

// If there is a custom 500 page, we need to handle it separately.
if (pathname === '/500' && error500Mod) {
return {
...baseLoadComponentResult,
Component: error500Mod.default,
pageConfig: error500Mod.config || {},
getStaticProps: error500Mod.getStaticProps,
getServerSideProps: error500Mod.getServerSideProps,
getStaticPaths: error500Mod.getStaticPaths,
ComponentMod: error500Mod,
}
}

if (pathname === '/_error') {
return {
...baseLoadComponentResult,
Component: errorMod.default,
pageConfig: errorMod.config || {},
getStaticProps: errorMod.getStaticProps,
getServerSideProps: errorMod.getServerSideProps,
getStaticPaths: errorMod.getStaticPaths,
ComponentMod: errorMod,
}
}

return null
},
},
})
const requestHandler = server.getRequestHandler()

Expand Down Expand Up @@ -72,8 +153,8 @@ export function getRender({
? JSON.parse(query.__props__)
: undefined

// Extend the context.
Object.assign((self as any).__server_context, {
// Extend the render options.
server.updateRenderOpts({
renderServerComponentData,
serverComponentProps,
})
Expand Down
Expand Up @@ -179,10 +179,11 @@ export function getUtils({
// Simulate a RegExp match from the \`req.url\` input
exec: (str: string) => {
const obj = parseQs(str)
const matchesHasLocale =
i18n && detectedLocale && obj['1'] === detectedLocale

// favor named matches if available
const routeKeyNames = Object.keys(routeKeys || {})

const filterLocaleItem = (val: string | string[]) => {
if (i18n) {
// locale items can be included in route-matches
Expand Down Expand Up @@ -228,8 +229,13 @@ export function getUtils({

return Object.keys(obj).reduce((prev, key) => {
if (!filterLocaleItem(obj[key])) {
let normalizedKey = key

if (matchesHasLocale) {
normalizedKey = parseInt(key, 10) - 1 + ''
}
return Object.assign(prev, {
[key]: obj[key],
[normalizedKey]: obj[key],
})
}
return prev
Expand Down

0 comments on commit 552fa7f

Please sign in to comment.