Skip to content

Commit

Permalink
Merge branch 'canary' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
damusnet authored Dec 10, 2020
2 parents 19802a7 + f4809b9 commit 004a4bf
Show file tree
Hide file tree
Showing 55 changed files with 364 additions and 78 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/cancel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Cancel
on:
pull_request_target:
types:
- edited
- synchronize

jobs:
cancel:
name: 'Cancel Previous Runs'
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- uses: styfle/cancel-workflow-action@0.5.0
with:
workflow_id: 444921, 444987
access_token: ${{ github.token }}
6 changes: 6 additions & 0 deletions docs/advanced-features/i18n-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ export default function IndexPage(props) {
}
```

## Leveraging the NEXT_LOCALE cookie

Next.js supports overriding the accept-language header with a `NEXT_LOCALE=the-locale` cookie. This cookie can be set using a language switcher and then when a user comes back to the site it will leverage the locale specified in the cookie.

For example, if a user prefers the locale `fr` but a `NEXT_LOCALE=en` cookie is set the `en` locale will be used instead until the cookie is removed or expired.

## Search Engine Optimization

Since Next.js knows what language the user is visiting it will automatically add the `lang` attribute to the `<html>` tag.
Expand Down
10 changes: 10 additions & 0 deletions errors/next-export-no-build-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Could not find a production build

#### Why This Error Occurred

When running `next export` a production build is needed.

#### Possible Ways to Fix It

- Run `next build` to create a production build before running `next export`.
- If your intention was to run the development server run `next dev` instead.
10 changes: 10 additions & 0 deletions errors/production-start-no-build-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Could not find a production build

#### Why This Error Occurred

When running `next start` or a custom server in production mode a production build is needed.

#### Possible Ways to Fix It

- Run `next build` to create a production build before booting up the production server.
- If your intention was to run the development server run `next dev` instead.
11 changes: 10 additions & 1 deletion examples/with-apollo/lib/apolloClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useMemo } from 'react'
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'
import { concatPagination } from '@apollo/client/utilities'
import merge from 'deepmerge'
import isEqual from 'lodash/isEqual'

export const APOLLO_STATE_PROP_NAME = '__APOLLO_STATE__'

Expand Down Expand Up @@ -36,7 +37,15 @@ export function initializeApollo(initialState = null) {
const existingCache = _apolloClient.extract()

// Merge the existing cache into data passed from getStaticProps/getServerSideProps
const data = merge(initialState, existingCache)
const data = merge(initialState, existingCache, {
// combine arrays using object equality (like in sets)
arrayMerge: (destinationArray, sourceArray) => [
...sourceArray,
...destinationArray.filter((d) =>
sourceArray.every((s) => !isEqual(d, s))
),
],
})

// Restore the cache with the merged data
_apolloClient.cache.restore(data)
Expand Down
1 change: 1 addition & 0 deletions examples/with-apollo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dependencies": {
"@apollo/client": "3.1.1",
"deepmerge": "^4.2.2",
"lodash": "4.17.20",
"graphql": "^15.3.0",
"next": "latest",
"prop-types": "^15.6.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/with-apollo/pages/client-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ClientOnlyPage = (props) => (
<App>
<Header />
<InfoBox>
ℹ️ This page shows how use Apollo only in the client. If you{' '}
ℹ️ This page shows how to use Apollo only in the client. If you{' '}
<a href="/client-only">reload</a> this page, you will see a loader since
Apollo didn't fetch any data on the server. This is useful when the page
doesn't have SEO requirements or blocking data fetching requirements.
Expand Down
2 changes: 1 addition & 1 deletion examples/with-docker/Dockerfile.multistage
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN yarn install --production --frozen-lockfile


# Stage 2: And then copy over node_modules, etc from that stage to the smaller base image
FROM mhart/alpine-node:base as production
FROM mhart/alpine-node:slim as production

WORKDIR /app

Expand Down
4 changes: 2 additions & 2 deletions examples/with-electron/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Electron application example

This example show how you can use Next.js inside an Electron application to avoid a lot of configuration, use Next.js router as view and use server-render to speed up the initial render of the application.
This example shows how you can use Next.js inside an Electron application to avoid a lot of configuration. It uses the Next.js router as view and server-render to speed up the initial render of the application.

For development it's going to run a HTTP server and let Next.js handle routing. In production it use `next export` to pre-generate HTML static files and use them in your app instead of running an HTTP server.
For development it's going to run an HTTP server and let Next.js handle routing. In production it uses `next export` to pre-generate HTML static files and uses them in your app instead of running an HTTP server.

**You can find a detailed documentation about how to build Electron apps with Next.js [here](https://leo.im/2017/electron-next)!**

Expand Down
4 changes: 2 additions & 2 deletions examples/with-facebook-pixel/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Example app using Facebook Pixel

This example shows how to use Next.js along with Facebook Pixel. A [custom `App`](https://nextjs.org/docs/advanced-features/custom-app) is used to track route changes and send page views to Facebook Pixel. This example uses [react-facebook-pixel](https://www.npmjs.com/package/react-facebook-pixel).
This example shows how to use Next.js along with Facebook Pixel. A custom [\_document](https://nextjs.org/docs/advanced-features/custom-document) is used to inject [base code](https://developers.facebook.com/docs/facebook-pixel/implementation/?locale=en_US). A [\_app](https://nextjs.org/docs/advanced-features/custom-app) is used to track route changes and send page views to Facebook Pixel.

## Deploy your own

Expand All @@ -24,6 +24,6 @@ Next, copy the `.env.local.example` file in this directory to `.env.local` (whic
cp .env.local.example .env.local
```

Set the `NEXT_PUBLIC_FACEBOOK_PIXEL_ID` variable in `.env.local` to match your facebook app's pixel ID. If not specified, tracking will be disabled.
Set the `NEXT_PUBLIC_FACEBOOK_PIXEL_ID` variable in `.env.local` to match your facebook app's pixel ID.

Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
3 changes: 1 addition & 2 deletions examples/with-facebook-pixel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"dependencies": {
"next": "latest",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-facebook-pixel": "^1.0.3"
"react-dom": "^16.13.1"
},
"license": "MIT"
}
3 changes: 0 additions & 3 deletions examples/with-next-translate/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,3 @@ yarn-error.log*

# vercel
.vercel

# next-translate
pages/
3 changes: 0 additions & 3 deletions examples/with-next-translate/i18n.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"locales": ["en", "ca"],
"defaultLocale": "en",
"currentPagesDir": "_pages",
"finalPagesDir": "pages",
"localesPath": "locales",
"pages": {
"*": ["common"],
"/": ["home"]
Expand Down
9 changes: 2 additions & 7 deletions examples/with-next-translate/next.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
const { locales, defaultLocale } = require('./i18n.json')
const nextTranslate = require('next-translate')

module.exports = {
i18n: {
locales,
defaultLocale,
},
}
module.exports = nextTranslate({})
8 changes: 4 additions & 4 deletions examples/with-next-translate/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "with-next-translate",
"scripts": {
"dev": "next-translate && next dev",
"build": "next-translate && next build",
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "10.0.0",
"next-translate": "0.19.0",
"next": "10.0.3",
"next-translate": "1.0.0",
"react": "17.0.1",
"react-dom": "17.0.1"
},
Expand Down
File renamed without changes.
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": "10.0.4-canary.2"
"version": "10.0.4-canary.4"
}
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": "10.0.4-canary.2",
"version": "10.0.4-canary.4",
"keywords": [
"react",
"next",
Expand Down
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": "10.0.4-canary.2",
"version": "10.0.4-canary.4",
"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": "10.0.4-canary.2",
"version": "10.0.4-canary.4",
"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": "10.0.4-canary.2",
"version": "10.0.4-canary.4",
"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": "10.0.4-canary.2",
"version": "10.0.4-canary.4",
"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": "10.0.4-canary.2",
"version": "10.0.4-canary.4",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-google-analytics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-google-analytics",
"version": "10.0.4-canary.2",
"version": "10.0.4-canary.4",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-google-analytics"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-sentry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-sentry",
"version": "10.0.4-canary.2",
"version": "10.0.4-canary.4",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-sentry"
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": "10.0.4-canary.2",
"version": "10.0.4-canary.4",
"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": "10.0.4-canary.2",
"version": "10.0.4-canary.4",
"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": "10.0.4-canary.2",
"version": "10.0.4-canary.4",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
7 changes: 6 additions & 1 deletion packages/next/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[![Next.js](https://assets.vercel.com/image/upload/v1538361091/repositories/next-js/next-js.png)](https://nextjs.org)
<p align="center">
<a href="https://nextjs.org">
<img src="https://assets.vercel.com/image/upload/v1607554385/repositories/next-js/next-logo.png" height="128">
<h1 align="center">Next.js</h1>
</a>
</p>

<p align="center">
<a aria-label="Vercel logo" href="https://vercel.com">
Expand Down
9 changes: 0 additions & 9 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,6 @@ export default async function getBaseWebpackConfig(
...nodePathList, // Support for NODE_PATH environment variable
],
alias: {
// These aliases make sure the wrapper module is not included in the bundles
// Which makes bundles slightly smaller, but also skips parsing a module that we know will result in this alias
'next/head': 'next/dist/next-server/lib/head.js',
'next/router': 'next/dist/client/router.js',
'next/experimental-script': config.experimental.scriptLoader
? 'next/dist/client/experimental-script.js'
: '',
'next/config': 'next/dist/next-server/lib/runtime-config.js',
'next/dynamic': 'next/dist/next-server/lib/dynamic.js',
next: NEXT_PROJECT_ROOT,
...(isWebpack5 && !isServer
? {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/cli/next-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const nextExport: cliCommand = (argv) => {

exportApp(dir, options)
.then(() => {
printAndExit('Export successful', 0)
printAndExit(`Export successful. Files written to ${options.outdir}`, 0)
})
.catch((err) => {
printAndExit(err)
Expand Down
2 changes: 1 addition & 1 deletion packages/next/compiled/terser-webpack-plugin/cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/next/compiled/terser/LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
UglifyJS is released under the BSD license:
Terser is released under the BSD license:

Copyright 2012-2018 (c) Mihai Bazon <mihai.bazon@gmail.com>

Expand Down
2 changes: 1 addition & 1 deletion packages/next/compiled/terser/bundle.min.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions packages/next/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,11 @@ export default async function exportApp(
Log.info(`using build directory: ${distDir}`)
}

if (!existsSync(distDir)) {
const buildIdFile = join(distDir, BUILD_ID_FILE)

if (!existsSync(buildIdFile)) {
throw new Error(
`Build directory ${distDir} does not exist. Make sure you run "next build" before running "next start" or "next export".`
`Could not find a production build in the '${distDir}' directory. Try building your app with 'next build' before starting the static export. https://err.sh/vercel/next.js/next-export-no-build-id`
)
}

Expand All @@ -186,7 +188,7 @@ export default async function exportApp(
)
}

const buildId = readFileSync(join(distDir, BUILD_ID_FILE), 'utf8')
const buildId = readFileSync(buildIdFile, 'utf8')
const pagesManifest =
!options.pages &&
(require(join(
Expand Down
5 changes: 5 additions & 0 deletions packages/next/lib/load-custom-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,14 @@ export default async function loadCustomRoutes(
destination: '/:file',
permanent: true,
locale: config.i18n ? false : undefined,
internal: true,
} as Redirect,
{
source: '/:notfile((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/\\.]+)',
destination: '/:notfile/',
permanent: true,
locale: config.i18n ? false : undefined,
internal: true,
} as Redirect
)
if (config.basePath) {
Expand All @@ -481,6 +483,7 @@ export default async function loadCustomRoutes(
permanent: true,
basePath: false,
locale: config.i18n ? false : undefined,
internal: true,
} as Redirect)
}
} else {
Expand All @@ -489,6 +492,7 @@ export default async function loadCustomRoutes(
destination: '/:path+',
permanent: true,
locale: config.i18n ? false : undefined,
internal: true,
} as Redirect)
if (config.basePath) {
redirects.unshift({
Expand All @@ -497,6 +501,7 @@ export default async function loadCustomRoutes(
permanent: true,
basePath: false,
locale: config.i18n ? false : undefined,
internal: true,
} as Redirect)
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/next/next-server/lib/post-process.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { parse, HTMLElement } from 'node-html-parser'
import { OPTIMIZED_FONT_PROVIDERS } from './constants'

const MIDDLEWARE_TIME_BUDGET = 10
const MIDDLEWARE_TIME_BUDGET =
parseInt(process.env.__POST_PROCESS_MIDDLEWARE_TIME_BUDGET || '', 10) || 10
const MAXIMUM_IMAGE_PRELOADS = 2
const IMAGE_PRELOAD_SIZE_THRESHOLD = 2500

Expand Down
Loading

0 comments on commit 004a4bf

Please sign in to comment.