Skip to content

Commit

Permalink
Merge branch 'canary' into fix-build-ext
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk authored Jul 15, 2021
2 parents 1aac66a + c46b405 commit 8be0c8c
Show file tree
Hide file tree
Showing 56 changed files with 861 additions and 219 deletions.
2 changes: 1 addition & 1 deletion docs/api-routes/api-middlewares.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default handler
## Extending the `req`/`res` objects with TypeScript

For better type-safety, it is not recommended to extend the `req` and `res` objects. Instead, use pure functions to work with them:
For better type-safety, it is not recommended to extend the `req` and `res` objects. Instead, use functions to work with them:

```ts
// utils/cookies.ts
Expand Down
6 changes: 2 additions & 4 deletions docs/basic-features/data-fetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,9 @@ You should use `getStaticProps` if:
For TypeScript, you can use the `GetStaticProps` type from `next`:

```ts
import { GetStaticProps, GetStaticPropsContext } from 'next'
import { GetStaticProps } from 'next'
export const getStaticProps: GetStaticProps = async (
context: GetStaticPropsContext
) => {
export const getStaticProps: GetStaticProps = async (context) => {
// ...
}
```
Expand Down
4 changes: 4 additions & 0 deletions errors/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@
"title": "no-document-viewport-meta",
"path": "/errors/no-document-viewport-meta.md"
},
{
"title": "no-duplicate-head",
"path": "/errors/no-duplicate-head.md"
},
{
"title": "no-head-import-in-document",
"path": "/errors/no-head-import-in-document.md"
Expand Down
38 changes: 38 additions & 0 deletions errors/no-duplicate-head.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# No Duplicate Head

### Why This Error Occurred

More than a single instance of the `<Head />` component was used in a single custom document. This can cause unexpected behavior in your application.

### Possible Ways to Fix It

Only use a single `<Head />` component in your custom document in `pages/_document.js`.

```jsx
// pages/_document.js
import Document, { Html, Head, Main, NextScript } from 'next/document'

class MyDocument extends Document {
static async getInitialProps(ctx) {
//...
}

render() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}

export default MyDocument
```

### Useful Links

- [Custom Document](https://nextjs.org/docs/advanced-features/custom-document)
2 changes: 1 addition & 1 deletion examples/cms-wordpress/components/cover-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function CoverImage({ title, coverImage, slug }) {
return (
<div className="sm:mx-0">
{slug ? (
<Link href={slug}>
<Link href={`/posts/${slug}`}>
<a aria-label={title}>{image}</a>
</Link>
) : (
Expand Down
4 changes: 3 additions & 1 deletion examples/cms-wordpress/components/post-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export default function PostPreview({
return (
<div>
<div className="mb-5">
<CoverImage title={title} coverImage={coverImage} slug={slug} />
{coverImage && (
<CoverImage title={title} coverImage={coverImage} slug={slug} />
)}
</div>
<h3 className="text-3xl mb-3 leading-snug">
<Link href={`/posts/${slug}`}>
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "11.0.2-canary.13"
"version": "11.0.2-canary.15"
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@
"wait-port": "0.2.2",
"web-streams-polyfill": "2.1.1",
"webpack-bundle-analyzer": "4.3.0",
"worker-loader": "3.0.7"
"worker-loader": "3.0.7",
"@swc/core": "1.2.63"
},
"resolutions": {
"browserslist": "4.16.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "11.0.2-canary.13",
"version": "11.0.2-canary.15",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "11.0.2-canary.13",
"version": "11.0.2-canary.15",
"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": "11.0.2-canary.13",
"@next/eslint-plugin-next": "11.0.2-canary.15",
"@rushstack/eslint-patch": "^1.0.6",
"@typescript-eslint/parser": "^4.20.0",
"eslint-import-resolver-node": "^0.3.4",
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin-next/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
'link-passhref': require('./rules/link-passhref'),
'no-document-import-in-page': require('./rules/no-document-import-in-page'),
'no-head-import-in-document': require('./rules/no-head-import-in-document'),
'no-duplicate-head': require('./rules/no-duplicate-head'),
},
configs: {
recommended: {
Expand All @@ -29,6 +30,7 @@ module.exports = {
'@next/next/link-passhref': 1,
'@next/next/no-document-import-in-page': 2,
'@next/next/no-head-import-in-document': 2,
'@next/next/no-duplicate-head': 2,
},
},
},
Expand Down
55 changes: 55 additions & 0 deletions packages/eslint-plugin-next/lib/rules/no-duplicate-head.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module.exports = {
meta: {
docs: {
description: 'Enforce no duplicate usage of <Head> in pages/document.js',
recommended: true,
},
},
create: function (context) {
let documentImportName
return {
ImportDeclaration(node) {
if (node.source.value === 'next/document') {
const documentImport = node.specifiers.find(
({ type }) => type === 'ImportDefaultSpecifier'
)
if (documentImport && documentImport.local) {
documentImportName = documentImport.local.name
}
}
},
ReturnStatement(node) {
const ancestors = context.getAncestors()
const documentClass = ancestors.find(
(ancestorNode) =>
ancestorNode.type === 'ClassDeclaration' &&
ancestorNode.superClass &&
ancestorNode.superClass.name === documentImportName
)

if (!documentClass) {
return
}

if (node.argument && node.argument.children) {
const headComponents = node.argument.children.filter(
(childrenNode) =>
childrenNode.openingElement &&
childrenNode.openingElement.name &&
childrenNode.openingElement.name.name === 'Head'
)

if (headComponents.length > 1) {
for (let i = 1; i < headComponents.length; i++) {
context.report({
node: headComponents[i],
message:
'Do not include multiple instances of <Head/>. See: https://nextjs.org/docs/messages/no-duplicate-head',
})
}
}
}
},
}
},
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "11.0.2-canary.13",
"version": "11.0.2-canary.15",
"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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "11.0.2-canary.13",
"version": "11.0.2-canary.15",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "11.0.2-canary.13",
"version": "11.0.2-canary.15",
"license": "MIT",
"dependencies": {
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "11.0.2-canary.13",
"version": "11.0.2-canary.15",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "11.0.2-canary.13",
"version": "11.0.2-canary.15",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions packages/next-mdx/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ module.exports = withMDX()

## Top level .mdx pages

Define the `pageExtensions` option to have Next.js handle `.mdx` files in the `pages` directory as pages:
Define the `pageExtensions` option to have Next.js handle `.md` and `.mdx` files in the `pages` directory as pages:

```js
// next.config.js
const withMDX = require('@next/mdx')({
extension: /\.mdx?$/,
})
module.exports = withMDX({
pageExtensions: ['js', 'jsx', 'mdx'],
pageExtensions: ['js', 'jsx', 'md', 'mdx'],
})
```

Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "11.0.2-canary.13",
"version": "11.0.2-canary.15",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "11.0.2-canary.13",
"version": "11.0.2-canary.15",
"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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "11.0.2-canary.13",
"version": "11.0.2-canary.15",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
15 changes: 14 additions & 1 deletion packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { findPagesDir } from '../lib/find-pages-dir'
import loadCustomRoutes, {
CustomRoutes,
getRedirectStatus,
modifyRouteRegex,
normalizeRouteRegex,
Redirect,
Rewrite,
Expand Down Expand Up @@ -330,6 +331,10 @@ export default async function build(
)
}

const restrictedRedirectPaths = ['/_next'].map((p) =>
config.basePath ? `${config.basePath}${p}` : p
)

const buildCustomRoute = (
r: {
source: string
Expand All @@ -347,6 +352,14 @@ export default async function build(
sensitive: false,
delimiter: '/', // default is `/#?`, but Next does not pass query info
})
let regexSource = routeRegex.source

if (!(r as any).internal) {
regexSource = modifyRouteRegex(
routeRegex.source,
type === 'redirect' ? restrictedRedirectPaths : undefined
)
}

return {
...r,
Expand All @@ -356,7 +369,7 @@ export default async function build(
permanent: undefined,
}
: {}),
regex: normalizeRouteRegex(routeRegex.source),
regex: normalizeRouteRegex(regexSource),
}
}

Expand Down
15 changes: 10 additions & 5 deletions packages/next/client/dev/error-overlay/hot-dev-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
// can be found here:
// https://github.com/facebook/create-react-app/blob/v3.4.1/packages/react-dev-utils/webpackHotDevClient.js

import * as DevOverlay from '@next/react-dev-overlay/lib/client'
import {
register,
onBuildError,
onBuildOk,
onRefresh,
} from '@next/react-dev-overlay/lib/client'
import stripAnsi from 'next/dist/compiled/strip-ansi'
import { addMessageListener } from './eventsource'
import formatWebpackMessages from './format-webpack-messages'
Expand All @@ -43,7 +48,7 @@ import formatWebpackMessages from './format-webpack-messages'
let hadRuntimeError = false
let customHmrEventHandler
export default function connect() {
DevOverlay.register()
register()

addMessageListener((event) => {
// This is the heartbeat event
Expand Down Expand Up @@ -154,7 +159,7 @@ function handleErrors(errors) {
})

// Only show the first error.
DevOverlay.onBuildError(formatted.errors[0])
onBuildError(formatted.errors[0])

// Also log them to the console.
if (typeof console !== 'undefined' && typeof console.error === 'function') {
Expand All @@ -176,9 +181,9 @@ function handleErrors(errors) {
let startLatency = undefined

function onFastRefresh(hasUpdates) {
DevOverlay.onBuildOk()
onBuildOk()
if (hasUpdates) {
DevOverlay.onRefresh()
onRefresh()
}

if (startLatency) {
Expand Down
Loading

0 comments on commit 8be0c8c

Please sign in to comment.