Skip to content

Commit

Permalink
Merge branch 'canary' into uploadcare-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut committed Nov 30, 2020
2 parents bbd27f2 + 1231ddb commit a8555b2
Show file tree
Hide file tree
Showing 491 changed files with 15,169 additions and 6,222 deletions.
7 changes: 5 additions & 2 deletions .github/ISSUE_TEMPLATE/1.Bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ about: Create a bug report for the Next.js core / examples
labels: 'template: bug'
---

<!-- NOTE: This template is not optional. If you remove it or leave out sections there is a high likelihood it will be moved to the GitHub Discussions "Help" section -->

# Bug report

## Describe the bug
Expand Down Expand Up @@ -31,8 +33,9 @@ If applicable, add screenshots to help explain your problem.

- OS: [e.g. macOS, Windows]
- Browser (if applies) [e.g. chrome, safari]
- Version of Next.js: [e.g. 6.0.2]
- Version of Node.js: [e.g. 10.10.0]
- Version of Next.js: [e.g. 10.0.1]
- Version of Node.js: [e.g. 12.0.0]
- Deployment: [e.g. next start, next export, Vercel, other platform]

## Additional context

Expand Down
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/2.Feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ about: Create a feature request for the Next.js core
labels: 'template: story'
---

<!-- NOTE: Feature requests will be converted to the GitHub Discussions "Ideas" section. -->

# Feature request

## Is your feature request related to a problem? Please describe.
Expand Down
25 changes: 21 additions & 4 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v2
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- run: yarn install --frozen-lockfile --check-files
- run: node run-tests.js --timings --write-timings -g 1/4
- run: node run-tests.js --timings --write-timings -g 1/1
- uses: actions/cache@v2
id: cache-build
with:
Expand Down Expand Up @@ -47,8 +47,25 @@ jobs:
key: ${{ github.sha }}
- run: ./check-pre-compiled.sh

testAll:
name: Test All
testUnit:
name: Test Unit
runs-on: ubuntu-latest
needs: build
env:
NEXT_TELEMETRY_DISABLED: 1
NEXT_TEST_JOB: 1
HEADLESS: true
steps:
- uses: actions/cache@v2
id: restore-build
with:
path: ./*
key: ${{ github.sha }}

- run: node run-tests.js --timings --type unit -g 1/1

testIntegration:
name: Test Integration
runs-on: ubuntu-latest
needs: build
env:
Expand Down Expand Up @@ -116,7 +133,7 @@ jobs:
testsPass:
name: thank you, next
runs-on: ubuntu-latest
needs: [lint, checkPrecompiled, testAll, testYarnPnP]
needs: [lint, checkPrecompiled, testIntegration, testUnit, testYarnPnP]
steps:
- run: exit 0

Expand Down
40 changes: 28 additions & 12 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ stages:
- script: dir
- script: dir $(System.DefaultWorkingDirectory)
- script: echo $(Build.SourceVersion)
- powershell: Set-MpPreference -ExclusionPath $(System.DefaultWorkingDirectory)
- powershell: Set-MpPreference -ExclusionPath $(Pipeline.Workspace)/.yarn
- powershell: Set-MpPreference -DisableIntrusionPreventionSystem $true -DisableIOAVProtection $true -DisableRealtimeMonitoring $true -DisableScriptScanning $true -EnableControlledFolderAccess Disabled -EnableNetworkProtection AuditMode -Force -MAPSReporting Disabled -SubmitSamplesConsent NeverSend
- powershell: Get-MpComputerStatus
- task: NodeTool@0
inputs:
Expand All @@ -33,19 +30,17 @@ stages:
yarn install --frozen-lockfile --check-files
displayName: 'Install dependencies'
- script: |
node run-tests.js --timings --write-timings --azure -g 1/4
node run-tests.js --timings --write-timings --azure -g 1/1
displayName: 'Fetch test timing data'
- stage: Test
dependsOn: Build
jobs:
- job: test_ie11
- job: test_ie11_production
pool:
vmImage: 'windows-2019'
steps:
- checkout: none
- powershell: Set-MpPreference -ExclusionPath $(System.DefaultWorkingDirectory)
- powershell: Set-MpPreference -ExclusionPath $(Pipeline.Workspace)/.yarn
- powershell: Set-MpPreference -DisableIntrusionPreventionSystem $true -DisableIOAVProtection $true -DisableRealtimeMonitoring $true -DisableScriptScanning $true -EnableControlledFolderAccess Disabled -EnableNetworkProtection AuditMode -Force -MAPSReporting Disabled -SubmitSamplesConsent NeverSend
- task: NodeTool@0
inputs:
versionSpec: $(node_version)
Expand All @@ -60,7 +55,31 @@ stages:
- script: |
yarn testie --forceExit test/integration/production/
displayName: 'Run tests'
- job: test_chrome
- job: test_unit
pool:
vmImage: 'windows-2019'
steps:
- checkout: none
- script: |
wmic datafile where name="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" get Version /value
displayName: 'List Chrome version'
- task: NodeTool@0
inputs:
versionSpec: $(node_version)
displayName: 'Install Node.js'
- task: Cache@2
inputs:
# use deterministic cache key that is specific
# to this test run
key: $(Build.SourceVersion)
path: $(System.DefaultWorkingDirectory)
displayName: Cache Build
- script: |
node run-tests.js -g 1/1 --timings --azure --type unit
displayName: 'Run tests'
- job: test_chrome_integration
pool:
vmImage: 'windows-2019'
strategy:
Expand All @@ -75,9 +94,6 @@ stages:
group: 4/4
steps:
- checkout: none
- powershell: Set-MpPreference -ExclusionPath $(System.DefaultWorkingDirectory)
- powershell: Set-MpPreference -ExclusionPath $(Pipeline.Workspace)/.yarn
- powershell: Set-MpPreference -DisableIntrusionPreventionSystem $true -DisableIOAVProtection $true -DisableRealtimeMonitoring $true -DisableScriptScanning $true -EnableControlledFolderAccess Disabled -EnableNetworkProtection AuditMode -Force -MAPSReporting Disabled -SubmitSamplesConsent NeverSend
- script: |
wmic datafile where name="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" get Version /value
displayName: 'List Chrome version'
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced-features/customizing-babel-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ description: Extend the babel preset added by Next.js with your own configs.
</ul>
</details>

Next.js includes the `next/babel` preset to your app, it includes everything needed to compile React applications and server-side code. But if you want to extend the default Babel configs, it's also possible.
Next.js includes the `next/babel` preset to your app, which includes everything needed to compile React applications and server-side code. But if you want to extend the default Babel configs, it's also possible.

To start, you only need to define a `.babelrc` file at the top of your app, if such file is found, we're going to consider it the _source of truth_, therefore it needs to define what Next.js needs as well, which is the `next/babel` preset.
To start, you only need to define a `.babelrc` file at the top of your app. If such a file is found, it will be considered as the _source of truth_, and therefore it needs to define what Next.js needs as well, which is the `next/babel` preset.

Here's an example `.babelrc` file:

Expand Down
12 changes: 8 additions & 4 deletions docs/advanced-features/i18n-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ When `localeDetection` is set to `false` Next.js will no longer automatically re

## Accessing the locale information

You can access the locale information via the Next.js router. For example, using the [`useRouter()`](https://nextjs.org/docs/api-reference/next/router#userouter) hook the following properties are available:
You can access the locale information via the Next.js router. For example, using the [`useRouter()`](/docs/api-reference/next/router.md#userouter) hook the following properties are available:

- `locale` contains the currently active locale.
- `locales` contains all configured locales.
- `defaultLocale` contains the configured default locale.

When [pre-rendering](/docs/basic-features/pages#static-generation-recommended) pages with `getStaticProps` or `getServerSideProps`, the locale information is provided in [the context](https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation) provided to the function.
When [pre-rendering](/docs/basic-features/pages.md#static-generation-recommended) pages with `getStaticProps` or `getServerSideProps`, the locale information is provided in [the context](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) provided to the function.

When leveraging `getStaticPaths`, the configured locales are provided in the context parameter of the function under `locales` and the configured defaultLocale under `defaultLocale`.

Expand Down Expand Up @@ -224,7 +224,7 @@ Next.js doesn't know about variants of a page so it's up to you to add the `href

### Automatically Statically Optimized Pages

For pages that are automatically statically optimized, a version of the page will be generated for each locale.
For pages that are [automatically statically optimized](/docs/advanced-features/automatic-static-optimization.md), a version of the page will be generated for each locale.

### Non-dynamic getStaticProps Pages

Expand Down Expand Up @@ -255,7 +255,7 @@ export async function getStaticProps({ locale }) {

### Dynamic getStaticProps Pages

For dynamic `getStaticProps` pages, any locale variants of the page that is desired to be prerendered needs to be returned from [`getStaticPaths`](/docs/basic-features/data-fetching#getstaticpaths-static-generation). Along with the `params` object that can be returned for the `paths`, you can also return a `locale` field specifying which locale you want to render. For example:
For dynamic `getStaticProps` pages, any locale variants of the page that is desired to be prerendered needs to be returned from [`getStaticPaths`](/docs/basic-features/data-fetching.md#getstaticpaths-static-generation). Along with the `params` object that can be returned for the `paths`, you can also return a `locale` field specifying which locale you want to render. For example:

```js
// pages/blog/[slug].js
Expand All @@ -269,3 +269,7 @@ export const getStaticPaths = ({ locales }) => {
}
}
```

## Caveats

Internationalized Routing does not currently support [Static HTML Export (`next export`)](/docs/advanced-features/static-html-export.md) as you are no longer leveraging Next.js' server-side routing in that case.
27 changes: 5 additions & 22 deletions docs/advanced-features/multi-zones.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Multi Zones

<details>
<details open>
<summary><b>Examples</b></summary>
<ul>
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-zones">With Zones</a></li>
Expand All @@ -21,27 +21,10 @@ With multi zones support, you can merge both these apps into a single one allowi
There are no special zones related APIs. You only need to do following:

- Make sure to keep only the pages you need in your app, meaning that an app can't have pages from another app, if app `A` has `/blog` then app `B` shouldn't have it too.
- Make sure to add an [assetPrefix](/docs/api-reference/next.config.js/cdn-support-with-asset-prefix.md) to avoid conflicts with static files.
- Make sure to configure a [basePath](/docs/api-reference/next.config.js/basepath.md) to avoid conflicts with pages and static files.

## How to merge zones

You can merge zones using any HTTP proxy.

For [Vercel](https://vercel.com/), you can use a single `vercel.json` to deploy both apps. It allows you to define routing routes for multiple apps like below:

```json
{
"version": 2,
"builds": [
{ "src": "blog/package.json", "use": "@vercel/next" },
{ "src": "home/package.json", "use": "@vercel/next" }
],
"routes": [
{ "src": "/blog/_next(.*)", "dest": "blog/_next$1" },
{ "src": "/blog(.*)", "dest": "blog/blog$1" },
{ "src": "(.*)", "dest": "home$1" }
]
}
```

You can also configure a proxy server to route using a set of routes like the ones above, e.g deploy the blog app to `https://blog.example.com` and the home app to `https://home.example.com` and then add a proxy server for both apps in `https://example.com`.
You can merge zones using [Rewrites](/docs/api-reference/next.config.js/rewrites.md) in one of the apps or any HTTP proxy.

For [Vercel](https://vercel.com/), you can use a [monorepo](https://vercel.com/blog/monorepos) to deploy both apps. Check the [Monorepos blog post](https://vercel.com/blog/monorepos) for more details on how it works and our [`with-zones` example](https://github.com/vercel/next.js/tree/canary/examples/with-zones) for a detailed guide using multiple Next.js applications.
2 changes: 2 additions & 0 deletions docs/advanced-features/static-html-export.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ By default, `next export` will generate an `out` directory, which can be served
- The [`fallback: true`](/docs/basic-features/data-fetching.md#fallback-true) mode of `getStaticPaths` is not supported when using `next export`.
- [API Routes](/docs/api-routes/introduction.md) are not supported by this method because they can't be prerendered to HTML.
- [`getServerSideProps`](/docs/basic-features/data-fetching.md#getserversideprops-server-side-rendering) cannot be used within pages because the method requires a server. Consider using [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) instead.
- [Internationalized Routing](/docs/advanced-features/i18n-routing.md) is not supported as it requires Next.js' server-side routing.
- The [`next/image`](/docs/api-reference/next/image.md) component's default loader is not supported when using `next export`. However, other [loader](/docs/basic-features/image-optimization.md#loader) options will work.
2 changes: 1 addition & 1 deletion docs/api-reference/data-fetching/getInitialProps.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default Page

Data returned from `getInitialProps` is serialized when server rendering, similar to what [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) does. Make sure the returned object from `getInitialProps` is a plain `Object` and not using `Date`, `Map` or `Set`.

For the initial page load, `getInitialProps` will run on the server only. `getInitialProps` will then run on the client when navigating to a different route via the [`next/link`](/docs/api-reference/next/link.md) component or by using [`next/router`](/docs/api-reference/next/router.md).
For the initial page load, `getInitialProps` will run on the server only. `getInitialProps` will then run on the client when navigating to a different route via the [`next/link`](/docs/api-reference/next/link.md) component or by using [`next/router`](/docs/api-reference/next/router.md). However, if `getInitialProps` is used in a custom `_app.js`, and the page being navigated to implements `getServerSideProps`, then `getInitialProps` will run on the server.

## Context Object

Expand Down
2 changes: 2 additions & 0 deletions docs/api-reference/next.config.js/basepath.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module.exports = {
}
```

Note: this value must be set at build time and can not be changed without re-building as the value is inlined in the client-side bundles.

## Links

When linking to other pages using `next/link` and `next/router` the `basePath` will be automatically applied.
Expand Down
38 changes: 38 additions & 0 deletions docs/api-reference/next.config.js/headers.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,41 @@ module.exports = {
},
}
```

### Headers with i18n support

When leveraging [`i18n` support](/docs/advanced-features/i18n-routing.md) with headers each `source` is automatically prefixed to handle the configured `locales` unless you add `locale: false` to the header:

```js
module.exports = {
i18n: {
locales: ['en', 'fr', 'de'],
defaultLocale: 'en',
},

async headers() {
return [
{
source: '/with-locale', // automatically handles all locales
headers: [
{
key: 'x-hello',
value: 'world',
},
],
},
{
// does not handle locales automatically since locale: false is set
source: '/nl/with-locale-manual',
locale: false,
headers: [
{
key: 'x-hello',
value: 'world',
},
],
},
]
},
}
```
36 changes: 33 additions & 3 deletions docs/api-reference/next.config.js/redirects.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ module.exports = {

### Regex Path Matching

To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/blog/:slug(\\d{1,})` will match `/blog/123` but not `/blog/abc`:
To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/post/:slug(\\d{1,})` will match `/post/123` but not `/post/abc`:

```js
module.exports = {
async redirects() {
return [
{
source: '/old-blog/:post(\\d{1,})',
destination: '/blog/:post', // Matched parameters can be used in the destination
source: '/post/:slug(\\d{1,})',
destination: '/news/:slug', // Matched parameters can be used in the destination
permanent: false,
},
]
Expand Down Expand Up @@ -120,4 +120,34 @@ module.exports = {
}
```

### Redirects with i18n support

When leveraging [`i18n` support](/docs/advanced-features/i18n-routing.md) with redirects each `source` and `destination` is automatically prefixed to handle the configured `locales` unless you add `locale: false` to the redirect:

```js
module.exports = {
i18n: {
locales: ['en', 'fr', 'de'],
defaultLocale: 'en',
},

async redirects() {
return [
{
source: '/with-locale', // automatically handles all locales
destination: '/another', // automatically passes the locale on
permanent: false,
},
{
// does not handle locales automatically since locale: false is set
source: '/nl/with-locale-manual',
destination: '/nl/another',
locale: false,
permanent: false,
},
]
},
}
```

In some rare cases, you might need to assign a custom status code for older HTTP Clients to properly redirect. In these cases, you can use the `statusCode` property instead of the `permanent` property, but not both. Note: to ensure IE11 compatibility a `Refresh` header is automatically added for the 308 status code.
28 changes: 28 additions & 0 deletions docs/api-reference/next.config.js/rewrites.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,31 @@ module.exports = {
},
}
```

### Rewrites with i18n support

When leveraging [`i18n` support](/docs/advanced-features/i18n-routing.md) with rewrites each `source` and `destination` is automatically prefixed to handle the configured `locales` unless you add `locale: false` to the rewrite:

```js
module.exports = {
i18n: {
locales: ['en', 'fr', 'de'],
defaultLocale: 'en',
},

async rewrites() {
return [
{
source: '/with-locale', // automatically handles all locales
destination: '/another', // automatically passes the locale on
},
{
// does not handle locales automatically since locale: false is set
source: '/nl/with-locale-manual',
destination: '/nl/another',
locale: false,
},
]
},
}
```
Loading

0 comments on commit a8555b2

Please sign in to comment.