diff --git a/.eslintignore b/.eslintignore
index e748682fbadd..48f9e69a5701 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -13,3 +13,5 @@ packages/next-codemod/transforms/__testfixtures__/**/*
packages/next-codemod/transforms/__tests__/**/*
packages/next-codemod/**/*.js
packages/next-codemod/**/*.d.ts
+packages/next-env/**/*.d.ts
+test/integration/async-modules/**
diff --git a/.github/actions/next-stats-action/src/index.js b/.github/actions/next-stats-action/src/index.js
index 2bacd52b3501..f24fe427faf8 100644
--- a/.github/actions/next-stats-action/src/index.js
+++ b/.github/actions/next-stats-action/src/index.js
@@ -1,3 +1,5 @@
+const path = require('path')
+const fs = require('fs-extra')
const exec = require('./util/exec')
const logger = require('./util/logger')
const runConfigs = require('./run')
@@ -25,6 +27,13 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
;(async () => {
try {
+ if (await fs.pathExists(path.join(__dirname, '../SKIP_NEXT_STATS.txt'))) {
+ console.log(
+ 'SKIP_NEXT_STATS.txt file present, exiting stats generation..'
+ )
+ process.exit(0)
+ }
+
const { stdout: gitName } = await exec(
'git config user.name && git config user.email'
)
diff --git a/.github/actions/next-stats-action/src/prepare/action-info.js b/.github/actions/next-stats-action/src/prepare/action-info.js
index 427fee1fd774..fff1ffc955cb 100644
--- a/.github/actions/next-stats-action/src/prepare/action-info.js
+++ b/.github/actions/next-stats-action/src/prepare/action-info.js
@@ -56,7 +56,9 @@ module.exports = function actionInfo() {
isLocal: LOCAL_STATS,
commitId: null,
issueId: ISSUE_ID,
- isRelease: releaseTypes.has(GITHUB_ACTION),
+ isRelease:
+ GITHUB_REPOSITORY === 'vercel/next.js' &&
+ (GITHUB_REF || '').includes('canary'),
}
// get comment
diff --git a/.github/workflows/build_test_deploy.yml b/.github/workflows/build_test_deploy.yml
index 3220cb97664f..884eaaf91cf8 100644
--- a/.github/workflows/build_test_deploy.yml
+++ b/.github/workflows/build_test_deploy.yml
@@ -107,12 +107,14 @@ jobs:
steps:
- uses: actions/checkout@v2
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- - run: cat package.json | jq '.resolutions.webpack = "^5.0.0-beta.30"' > package.json.tmp && mv package.json.tmp package.json
- - run: cat package.json | jq '.resolutions.react = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp package.json
- - run: cat package.json | jq '.resolutions."react-dom" = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp package.json
+ - run: cat packages/next/package.json | jq '.resolutions.webpack = "^5.0.0-beta.30"' > package.json.tmp && mv package.json.tmp packages/next/package.json
+ - run: cat packages/next/package.json | jq '.resolutions.react = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp packages/next/package.json
+ - run: cat packages/next/package.json | jq '.resolutions."react-dom" = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp packages/next/package.json
- run: yarn install --check-files
- run: node run-tests.js test/integration/production/test/index.test.js
- run: node run-tests.js test/integration/basic/test/index.test.js
+ - run: node run-tests.js test/integration/async-modules/test/index.test.js
+ - run: node run-tests.js test/integration/font-optimization/test/index.test.js
- run: node run-tests.js test/acceptance/*
testFirefox:
@@ -184,3 +186,18 @@ jobs:
key: ${{ github.sha }}
- run: ./publish-release.sh
+
+ prStats:
+ name: Release Stats
+ runs-on: ubuntu-latest
+ needs: [publishRelease]
+ steps:
+ - uses: actions/cache@v2
+ id: restore-build
+ with:
+ path: ./*
+ key: ${{ github.sha }}
+ - run: ./release-stats.sh
+ - uses: ./.github/actions/next-stats-action
+ env:
+ PR_STATS_COMMENT_TOKEN: ${{ secrets.PR_STATS_COMMENT_TOKEN }}
diff --git a/.github/workflows/release_stats.yml b/.github/workflows/release_stats.yml
deleted file mode 100644
index c734488bdc26..000000000000
--- a/.github/workflows/release_stats.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-on: release
-
-name: Generate Release Stats
-
-jobs:
- prStats:
- name: Release Stats
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - uses: ./.github/actions/next-stats-action
- env:
- PR_STATS_COMMENT_TOKEN: ${{ secrets.PR_STATS_COMMENT_TOKEN }}
diff --git a/.prettierignore b/.prettierignore
index d40368c6af1f..f20bc5d8b472 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -13,3 +13,4 @@ packages/next-codemod/transforms/__testfixtures__/**/*
packages/next-codemod/transforms/__tests__/**/*
packages/next-codemod/**/*.js
packages/next-codemod/**/*.d.ts
+packages/next-env/**/*.d.ts
\ No newline at end of file
diff --git a/docs/advanced-features/codemods.md b/docs/advanced-features/codemods.md
index be387fc827f6..5c42d4551bb9 100644
--- a/docs/advanced-features/codemods.md
+++ b/docs/advanced-features/codemods.md
@@ -132,7 +132,7 @@ export default withRouter(
)
```
-This is just one case. All the cases that are transformed (and tested) can be found in the [`__testfixtures__` directory](./transforms/__testfixtures__/url-to-withrouter).
+This is just one case. All the cases that are transformed (and tested) can be found in the [`__testfixtures__` directory](https://github.com/vercel/next.js/tree/canary/packages/next-codemod/transforms/__testfixtures__/url-to-withrouter).
#### Usage
diff --git a/docs/advanced-features/custom-app.md b/docs/advanced-features/custom-app.md
index 8f0ea8aab405..571bf79da5a6 100644
--- a/docs/advanced-features/custom-app.md
+++ b/docs/advanced-features/custom-app.md
@@ -44,6 +44,7 @@ The `Component` prop is the active `page`, so whenever you navigate between rout
- If your app is running and you just added a custom `App`, you'll need to restart the development server. Only required if `pages/_app.js` didn't exist before.
- Adding a custom `getInitialProps` in your `App` will disable [Automatic Static Optimization](/docs/advanced-features/automatic-static-optimization.md) in pages without [Static Generation](/docs/basic-features/data-fetching.md#getstaticprops-static-generation).
+- `App` currently does not support Next.js [Data Fetching methods](/docs/basic-features/data-fetching.md) like [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) or [`getServerSideProps`](/docs/basic-features/data-fetching.md#getserversideprops-server-side-rendering).
### TypeScript
diff --git a/docs/advanced-features/custom-document.md b/docs/advanced-features/custom-document.md
index 363ff1215f43..2c75cca86b37 100644
--- a/docs/advanced-features/custom-document.md
+++ b/docs/advanced-features/custom-document.md
@@ -51,9 +51,10 @@ The `ctx` object is equivalent to the one received in [`getInitialProps`](/docs/
## Caveats
-- `Document` is only rendered in the server, event handlers like `onClick` won't work
-- React components outside of `` will not be initialized by the browser. Do _not_ add application logic here or custom CSS (like `styled-jsx`). If you need shared components in all your pages (like a menu or a toolbar), take a look at the [`App`](/docs/advanced-features/custom-app.md) component instead
-- `Document`'s `getInitialProps` function is not called during client-side transitions, nor when a page is [statically optimized](/docs/advanced-features/automatic-static-optimization.md)
+- `Document` is only rendered in the server, event handlers like `onClick` won't work.
+- React components outside of `` will not be initialized by the browser. Do _not_ add application logic here or custom CSS (like `styled-jsx`). If you need shared components in all your pages (like a menu or a toolbar), take a look at the [`App`](/docs/advanced-features/custom-app.md) component instead.
+- `Document`'s `getInitialProps` function is not called during client-side transitions, nor when a page is [statically optimized](/docs/advanced-features/automatic-static-optimization.md).
+- `Document` currently does not support Next.js [Data Fetching methods](/docs/basic-features/data-fetching.md) like [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) or [`getServerSideProps`](/docs/basic-features/data-fetching.md#getserversideprops-server-side-rendering).
## Customizing `renderPage`
diff --git a/docs/advanced-features/preview-mode.md b/docs/advanced-features/preview-mode.md
index a1b05fb09c65..79ac857448dc 100644
--- a/docs/advanced-features/preview-mode.md
+++ b/docs/advanced-features/preview-mode.md
@@ -39,7 +39,7 @@ First, create a **preview API route**. It can have any name - e.g. `pages/api/pr
In this API route, you need to call `setPreviewData` on the response object. The argument for `setPreviewData` should be an object, and this can be used by `getStaticProps` (more on this later). For now, we’ll use `{}`.
```js
-export default (req, res) => {
+export default function handler(req, res) {
// ...
res.setPreviewData({})
// ...
@@ -54,7 +54,7 @@ You can test this manually by creating an API route like below and accessing it
// A simple example for testing it manually from your browser.
// If this is located at pages/api/preview.js, then
// open /api/preview from your browser.
-export default (req, res) => {
+export default function handler(req, res) {
res.setPreviewData({})
res.end('Preview mode enabled')
}
@@ -175,7 +175,7 @@ By default, no expiration date is set for the preview mode cookies, so the previ
To clear the preview cookies manually, you can create an API route which calls `clearPreviewData` and then access this API route.
```js
-export default (req, res) => {
+export default function handler(req, res) {
// Clears the preview mode cookies.
// This function accepts no arguments.
res.clearPreviewData()
diff --git a/docs/api-reference/create-next-app.md b/docs/api-reference/create-next-app.md
index f5dead47ab75..1b96f94179d2 100644
--- a/docs/api-reference/create-next-app.md
+++ b/docs/api-reference/create-next-app.md
@@ -18,6 +18,7 @@ yarn create next-app
- **-e, --example [name]|[github-url]** - An example to bootstrap the app with. You can use an example name from the [Next.js repo](https://github.com/vercel/next.js/tree/master/examples) or a GitHub URL. The URL can use any branch and/or subdirectory.
- **--example-path [path-to-example]** - In a rare case, your GitHub URL might contain a branch name with a slash (e.g. bug/fix-1) and the path to the example (e.g. foo/bar). In this case, you must specify the path to the example separately: `--example-path foo/bar`
+- **--use-npm** - Explicitly tell the CLI to bootstrap the app using npm. Yarn will be used by default if it's installed
### Why use Create Next App?
diff --git a/docs/api-reference/next.config.js/environment-variables.md b/docs/api-reference/next.config.js/environment-variables.md
index a0766ef442db..582f1449b60d 100644
--- a/docs/api-reference/next.config.js/environment-variables.md
+++ b/docs/api-reference/next.config.js/environment-variables.md
@@ -10,7 +10,6 @@ description: Learn to add and access environment variables in your Next.js appli
` element. For example, here's an SEO component with Gatsby:
+
+```js
+// src/components/seo.js
+
+import { Helmet } from 'react-helmet'
+
+export default function SEO({ description, title, siteTitle }) {
+ return (
+
+
+ + + + + + + + + + + ) +} +``` + +## Learn more + +Take a look at [this pull request](https://github.com/leerob/gatsby-to-nextjs/pull/1) for more details on how an app can be migrated from Gatsby to Next.js. If you have questions or if this guide didn't work for you, feel free to reach out to our community on [GitHub Discussions](https://github.com/vercel/next.js/discussions). diff --git a/errors/export-no-custom-routes.md b/errors/export-no-custom-routes.md new file mode 100644 index 000000000000..9a18c5747e24 --- /dev/null +++ b/errors/export-no-custom-routes.md @@ -0,0 +1,19 @@ +# `next export` No Custom Routes + +#### Why This Error Occurred + +In your `next.config.js` `rewrites`, `redirects`, or `headers` were defined while `next export` was being run outside of a platform that supports them. + +These configs do not apply when exporting your Next.js application manually. + +#### Possible Ways to Fix It + +Disable the `rewrites`, `redirects`, and `headers` from your `next.config.js` when using `next export` to deploy your application or deploy your application using [a method](https://nextjs.org/docs/deployment#vercel-recommended) that supports these configs. + +### Useful Links + +- [Deployment Documentation](https://nextjs.org/docs/deployment#vercel-recommended) +- [`next export` Documentation](https://nextjs.org/docs/advanced-features/static-html-export) +- [Rewrites Documentation](https://nextjs.org/docs/api-reference/next.config.js/rewrites) +- [Redirects Documentation](https://nextjs.org/docs/api-reference/next.config.js/redirects) +- [Headers Documentation](https://nextjs.org/docs/api-reference/next.config.js/headers) diff --git a/examples/amp-first/README.md b/examples/amp-first/README.md index 675c1d532b7b..3c837e93d2ed 100644 --- a/examples/amp-first/README.md +++ b/examples/amp-first/README.md @@ -60,7 +60,7 @@ Things you need to do after installing the boilerplate: ``` - **amp-list & amp-mustache:** mustache templates conflict with JSX and it's template literals need to be escaped. A simple approach is to escape them via back ticks: `` src={`{{imageUrl}}`} ``. -- **amp-script:** you can use [amp-script](https://amp.dev/documentation/components/amp-script/) to add custom JavaScript to your AMP pages. The boilerplate includes a helper [`components/amp/AmpScript.js`](components/amp/AmpScript.js) to simplify using amp-script. The helper also supports embedding inline scripts. Good to know: Next.js uses [AMP Optimizer](https://github.com/ampproject/amp-toolbox/tree/master/packages/optimizer) under the hood, which automatically adds the needed script hashes for [inline amp-scripts](https://amp.dev/documentation/components/amp-script/#load-javascript-from-a-local-element). +- **amp-script:** you can use [amp-script](https://amp.dev/documentation/components/amp-script/) to add custom JavaScript to your AMP pages. The boilerplate includes a helper [`components/amp/AmpScript.js`](components/amp/AmpScript.js) to simplify using `amp-script`. The helper also supports embedding inline scripts. Good to know: Next.js uses [AMP Optimizer](https://github.com/ampproject/amp-toolbox/tree/master/packages/optimizer) under the hood, which automatically adds the needed script hashes for [inline amp-scripts](https://amp.dev/documentation/components/amp-script/#load-javascript-from-a-local-element). ## Deployment diff --git a/examples/api-routes-rest/README.md b/examples/api-routes-rest/README.md index 3f12cd4a6766..4bcb51a25655 100644 --- a/examples/api-routes-rest/README.md +++ b/examples/api-routes-rest/README.md @@ -1,6 +1,6 @@ # API routes with REST -Next.js ships with [API routes](https://github.com/vercel/next.js#api-routes), which provide an easy solution to build your own `API`. This example shows how it can be used to create your [REST](https://en.wikipedia.org/wiki/Representational_state_transfer) api. +Next.js ships with [API routes](https://github.com/vercel/next.js#api-routes), which provide an easy solution to build your own `API`. This example shows how it can be used to create your [REST](https://en.wikipedia.org/wiki/Representational_state_transfer) `API`. ## Deploy your own diff --git a/examples/blog-starter-typescript/README.md b/examples/blog-starter-typescript/README.md index 95cee4f58b6f..e8db3fc2498c 100644 --- a/examples/blog-starter-typescript/README.md +++ b/examples/blog-starter-typescript/README.md @@ -2,11 +2,11 @@ This is the existing [blog-starter](https://github.com/vercel/next.js/tree/canary/examples/blog-starter) plus TypeScript. -This example showcases Next.js's [Static Generation](https://nextjs.org/docs/basic-features/pages) feature using markdown files as the data source. +This example showcases Next.js's [Static Generation](https://nextjs.org/docs/basic-features/pages) feature using Markdown files as the data source. -The blog posts are stored in `/_posts` as markdown files with front matter support. Adding a new markdown file in there will create a new blog post. +The blog posts are stored in `/_posts` as Markdown files with front matter support. Adding a new Markdown file in there will create a new blog post. -To create the blog posts we use [`remark`](https://github.com/remarkjs/remark) and [`remark-html`](https://github.com/remarkjs/remark-html) to convert the markdown files into an HTML string, and then send it down as a prop to the page. The metadata of every post is handled by [`gray-matter`](https://github.com/jonschlinkert/gray-matter) and also sent in props to the page. +To create the blog posts we use [`remark`](https://github.com/remarkjs/remark) and [`remark-html`](https://github.com/remarkjs/remark-html) to convert the Markdown files into an HTML string, and then send it down as a prop to the page. The metadata of every post is handled by [`gray-matter`](https://github.com/jonschlinkert/gray-matter) and also sent in props to the page. ## How to use diff --git a/examples/blog-starter/README.md b/examples/blog-starter/README.md index 7f6cf9b81912..01f09e679171 100644 --- a/examples/blog-starter/README.md +++ b/examples/blog-starter/README.md @@ -1,10 +1,10 @@ # A statically generated blog example using Next.js and Markdown -This example showcases Next.js's [Static Generation](https://nextjs.org/docs/basic-features/pages) feature using markdown files as the data source. +This example showcases Next.js's [Static Generation](https://nextjs.org/docs/basic-features/pages) feature using Markdown files as the data source. -The blog posts are stored in `/_posts` as markdown files with front matter support. Adding a new markdown file in there will create a new blog post. +The blog posts are stored in `/_posts` as Markdown files with front matter support. Adding a new Markdown file in there will create a new blog post. -To create the blog posts we use [`remark`](https://github.com/remarkjs/remark) and [`remark-html`](https://github.com/remarkjs/remark-html) to convert the markdown files into an HTML string, and then send it down as a prop to the page. The metadata of every post is handled by [`gray-matter`](https://github.com/jonschlinkert/gray-matter) and also sent in props to the page. +To create the blog posts we use [`remark`](https://github.com/remarkjs/remark) and [`remark-html`](https://github.com/remarkjs/remark-html) to convert the Markdown files into an HTML string, and then send it down as a prop to the page. The metadata of every post is handled by [`gray-matter`](https://github.com/jonschlinkert/gray-matter) and also sent in props to the page. ## Demo diff --git a/examples/environment-variables/pages/index.js b/examples/environment-variables/pages/index.js index bda145075e66..848863d6b2b7 100644 --- a/examples/environment-variables/pages/index.js +++ b/examples/environment-variables/pages/index.js @@ -17,7 +17,7 @@ const IndexPage = () => (
In general only .env.local
or .env
are needed
for this, but the table also features the usage of{' '}
- .env.develoment
and .env.production
.
+ .env.development
and .env.production
.