Skip to content

Commit

Permalink
Merge branch 'canary' into canary
Browse files Browse the repository at this point in the history
  • Loading branch information
msreekm authored Jul 26, 2020
2 parents e1e6607 + 2f50f1f commit 71884a4
Show file tree
Hide file tree
Showing 73 changed files with 1,585 additions and 285 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ jobs:
- uses: actions/checkout@v2
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- run: yarn install --frozen-lockfile --check-files
- uses: actions/cache@v1
- uses: actions/cache@v2
id: cache-build
with:
path: '.'
path: ./*
key: ${{ github.sha }}

lint:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/cache@v1
- uses: actions/cache@v2
id: restore-build
with:
path: '.'
path: ./*
key: ${{ github.sha }}
- run: yarn lint

Expand All @@ -39,10 +39,10 @@ jobs:
env:
NEXT_TELEMETRY_DISABLED: 1
steps:
- uses: actions/cache@v1
- uses: actions/cache@v2
id: restore-build
with:
path: '.'
path: ./*
key: ${{ github.sha }}
- run: ./check-pre-compiled.sh

Expand All @@ -59,10 +59,10 @@ jobs:
matrix:
group: [1, 2, 3, 4, 5, 6]
steps:
- uses: actions/cache@v1
- uses: actions/cache@v2
id: restore-build
with:
path: '.'
path: ./*
key: ${{ github.sha }}

# TODO: remove after we fix watchpack watching too much
Expand Down Expand Up @@ -104,10 +104,10 @@ jobs:
BROWSERNAME: 'firefox'
NEXT_TELEMETRY_DISABLED: 1
steps:
- uses: actions/cache@v1
- uses: actions/cache@v2
id: restore-build
with:
path: '.'
path: ./*
key: ${{ github.sha }}
- run: node run-tests.js test/integration/production/test/index.test.js

Expand All @@ -123,10 +123,10 @@ jobs:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
steps:
- uses: actions/cache@v1
- uses: actions/cache@v2
id: restore-build
with:
path: '.'
path: ./*
key: ${{ github.sha }}
- run: '[[ -z "$BROWSERSTACK_ACCESS_KEY" ]] && echo "Skipping for PR" || node run-tests.js test/integration/production/test/index.test.js'

Expand All @@ -143,10 +143,10 @@ jobs:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
steps:
- uses: actions/cache@v1
- uses: actions/cache@v2
id: restore-build
with:
path: '.'
path: ./*
key: ${{ github.sha }}
- run: '[[ -z "$BROWSERSTACK_ACCESS_KEY" ]] && echo "Skipping for PR" || node run-tests.js test/integration/production-nav/test/index.test.js'

Expand All @@ -157,10 +157,10 @@ jobs:
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- uses: actions/cache@v1
- uses: actions/cache@v2
id: restore-build
with:
path: '.'
path: ./*
key: ${{ github.sha }}

- run: ./publish-release.sh
8 changes: 4 additions & 4 deletions .github/workflows/test_react_next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:

# - run: yarn upgrade react@next react-dom@next -W --dev

# - uses: actions/cache@v1
# - uses: actions/cache@v2
# id: cache-build
# with:
# path: '.'
# path: ./*
# key: ${{ github.sha }}

testAll:
Expand All @@ -35,10 +35,10 @@ jobs:
matrix:
group: [1, 2, 3, 4, 5, 6]
steps:
# - uses: actions/cache@v1
# - uses: actions/cache@v2
# id: restore-build
# with:
# path: '.'
# path: ./*
# key: ${{ github.sha }}

- uses: actions/checkout@v2
Expand Down
18 changes: 18 additions & 0 deletions docs/advanced-features/custom-document.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,21 @@ class MyDocument extends Document {

export default MyDocument
```

## TypeScript

You can use the built-in `DocumentContext` type and change the file name to `./pages/_document.tsx` like so:

```tsx
import Document, { DocumentContext } from 'next/document'

class MyDocument extends Document {
static async getInitialProps(ctx: DocumentContext) {
const initialProps = await Document.getInitialProps(ctx)

return initialProps
}
}

export default MyDocument
```
7 changes: 7 additions & 0 deletions docs/api-reference/next.config.js/rewrites.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ description: Add rewrites to your Next.js app.

# Rewrites

<details>
<summary><b>Examples</b></summary>
<ul>
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/rewrites">Rewrites</a></li>
</ul>
</details>

Rewrites allow you to map an incoming request path to a different destination path.

Rewrites are only available on the Node.js environment and do not affect client-side routing.
Expand Down
2 changes: 1 addition & 1 deletion errors/no-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ cache:
Using GitHub's [actions/cache](https://github.com/actions/cache), add the following step in your workflow file:
```yaml
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { useMemo } from 'react'
import { ApolloClient } from 'apollo-client'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { ApolloClient, InMemoryCache } from '@apollo/client'

let apolloClient

function createIsomorphLink() {
if (typeof window === 'undefined') {
const { SchemaLink } = require('apollo-link-schema')
const { SchemaLink } = require('@apollo/client/link/schema')
const { schema } = require('./schema')
return new SchemaLink({ schema })
} else {
const { HttpLink } = require('apollo-link-http')
const { HttpLink } = require('@apollo/client/link/http')
return new HttpLink({
uri: '/api/graphql',
credentials: 'same-origin',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gql from 'graphql-tag'
import { gql } from '@apollo/client'

export const typeDefs = gql`
type User {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,11 @@
"start": "next start"
},
"dependencies": {
"@apollo/react-common": "^3.1.4",
"@apollo/react-hooks": "^3.1.5",
"@apollo/client": "^3.0.2",
"@hapi/iron": "6.0.0",
"apollo-cache-inmemory": "^1.6.6",
"apollo-client": "^2.6.10",
"apollo-link-http": "^1.5.17",
"apollo-link-schema": "^1.2.5",
"apollo-server-micro": "^2.14.2",
"apollo-utilities": "^1.3.2",
"cookie": "^0.4.1",
"graphql": "^14.0.2",
"graphql-tag": "^2.10.3",
"next": "latest",
"prop-types": "^15.6.2",
"react": "^16.7.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApolloProvider } from '@apollo/react-hooks'
import { ApolloProvider } from '@apollo/client'
import { useApollo } from '../apollo/client'

export default function App({ Component, pageProps }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useEffect } from 'react'
import { useRouter } from 'next/router'
import Link from 'next/link'
import gql from 'graphql-tag'
import { useQuery } from '@apollo/react-hooks'
import { gql, useQuery } from '@apollo/client'

const ViewerQuery = gql`
query ViewerQuery {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState } from 'react'
import { useRouter } from 'next/router'
import Link from 'next/link'
import gql from 'graphql-tag'
import { useMutation, useApolloClient } from '@apollo/react-hooks'
import { gql } from '@apollo/client'
import { useMutation, useApolloClient } from '@apollo/client'
import { getErrorMessage } from '../lib/form'
import Field from '../components/field'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useEffect } from 'react'
import { useRouter } from 'next/router'
import { useMutation, useApolloClient } from '@apollo/react-hooks'
import gql from 'graphql-tag'
import { gql, useMutation, useApolloClient } from '@apollo/client'

const SignOutMutation = gql`
mutation SignOutMutation {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useState } from 'react'
import { useRouter } from 'next/router'
import Link from 'next/link'
import gql from 'graphql-tag'
import { useMutation } from '@apollo/react-hooks'
import { gql, useMutation } from '@apollo/client'
import { getErrorMessage } from '../lib/form'
import Field from '../components/field'

Expand Down
34 changes: 34 additions & 0 deletions examples/rewrites/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
23 changes: 23 additions & 0 deletions examples/rewrites/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Rewrites Example

This example shows how to use [rewrites in Next.js](https://nextjs.org/docs/api-reference/next.config.js/rewrites) to map an incoming request path to a different destination path.

The index page ([`pages/index.js`](pages/index.js)) has a list of links that match the rewrites defined in [`next.config.js`](next.config.js). Run or deploy the app to see how it works!

## Deploy your own

Deploy the example using [Vercel](https://vercel.com):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/vercel/next.js/tree/canary/examples/rewrites)

## How to use

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:

```bash
npx create-next-app --example rewrites rewrites-app
# or
yarn create next-app --example rewrites rewrites-app
```

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)).
29 changes: 29 additions & 0 deletions examples/rewrites/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
async rewrites() {
return [
{
source: '/team',
destination: '/about',
},
{
source: '/about-us',
destination: '/about',
},
// Path Matching - will match `/post/a` but not `/post/a/b`
{
source: '/post/:slug',
destination: '/news/:slug',
},
// Wildcard Path Matching - will match `/news/a` and `/news/a/b`
{
source: '/blog/:slug*',
destination: '/news/:slug*',
},
// Rewriting to an external URL
{
source: '/docs/:slug',
destination: 'http://example.com/docs/:slug',
},
]
},
}
15 changes: 15 additions & 0 deletions examples/rewrites/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "rewrites",
"version": "1.0.0",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "9.4.5-canary.43",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"license": "MIT"
}
Loading

0 comments on commit 71884a4

Please sign in to comment.