Skip to content

Commit

Permalink
Merge branch 'canary' of github.com:zeit/next.js into native-url
Browse files Browse the repository at this point in the history
  • Loading branch information
janicklas-ralph committed Apr 15, 2020
2 parents 8b6c255 + 29c697b commit a52d171
Show file tree
Hide file tree
Showing 459 changed files with 7,099 additions and 2,861 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules
**/_next/**
**/dist/**
examples/with-ioc/**
examples/with-kea/**
examples/with-kea/**
packages/next/compiled/**/*
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/1.Bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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]

## Additional context

Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ jobs:
key: ${{ github.sha }}
- run: yarn lint

checkPrecompiled:
name: Check Pre-compiled
runs-on: ubuntu-latest
needs: build
env:
NEXT_TELEMETRY_DISABLED: 1
steps:
- uses: actions/cache@v1
id: restore-build
with:
path: '.'
key: ${{ github.sha }}
- run: ./check-pre-compiled.sh

testAll:
name: Test All
runs-on: ubuntu-latest
Expand Down Expand Up @@ -59,7 +73,7 @@ jobs:
testsPass:
name: thank you, next
runs-on: ubuntu-latest
needs: [lint, testAll]
needs: [lint, checkPrecompiled, testAll]
steps:
- run: exit 0

Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
**/.next/**
**/_next/**
**/dist/**
**/dist/**
packages/next/compiled/**
3 changes: 2 additions & 1 deletion .prettierignore_staged
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/.next/**
**/_next/**
**/dist/**
**/dist/**
packages/next/compiled/**/*
12 changes: 12 additions & 0 deletions check-pre-compiled.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

yarn --cwd packages/next ncc-compiled

# Make sure to exit with 1 if there are changes after running ncc-compiled
# step to ensure we get any changes committed

if [[ ! -z $(git status -s) ]];then
echo "Detected changes"
git status
exit 1
fi
2 changes: 1 addition & 1 deletion contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Make sure you have `chromedriver` installed for your Chrome version. You can ins

- `brew cask install chromedriver` on Mac OS X
- `chocolatey install chromedriver` on Windows
- Or manually downloading it from the [chromedriver repo](https://chromedriver.storage.googleapis.com/index.html) and adding the binary to `<next-repo>/node_modules/.bin`
- Or manually download the version that matches your installed chrome version (if there's no match, download a version under it, but not above) from the [chromedriver repo](https://chromedriver.storage.googleapis.com/index.html) and add the binary to `<next-repo>/node_modules/.bin`

Running all tests:

Expand Down
1 change: 1 addition & 0 deletions docs/advanced-features/preview-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Take a look at the following examples to learn more:
- [DatoCMS Example](https://github.com/zeit/next.js/tree/canary/examples/cms-datocms) ([Demo](https://next-blog-datocms.now.sh/))
- [TakeShape Example](https://github.com/zeit/next.js/tree/canary/examples/cms-takeshape) ([Demo](https://next-blog-takeshape.now.sh/))
- [Sanity Example](https://github.com/zeit/next.js/tree/canary/examples/cms-sanity) ([Demo](https://next-blog-sanity.now.sh/))
- [Prismic Example](https://github.com/zeit/next.js/tree/canary/examples/cms-prismic) ([Demo](https://next-blog-prismic.now.sh/))

## More Details

Expand Down
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 @@ -85,7 +85,7 @@ For the initial page load, `getInitialProps` will execute on the server only. `g

## TypeScript

If you're using TypeScript, you can use the `NextPage` type for functional components:
If you're using TypeScript, you can use the `NextPage` type for function components:

```jsx
import { NextPage } from 'next'
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/next.config.js/build-target.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Your application will be built and deployed as a monolith. This is the default t

## `serverless` target

> Deployments to [ZEIT Now](https://zeit.co) will automatically enable this target. You do not need to opt-into it yourself, but you can.
> Deployments to [ZEIT Now](https://zeit.co) will automatically enable this target. You should not opt-into it yourself.
This target will output independent pages that don't require a monolithic server.

Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/next/link.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default Home
- `href` - The path inside `pages` directory. This is the only required prop
- `as` - The path that will be rendered in the browser URL bar. Used for dynamic routes
- [`passHref`](#forcing-Link-to-expose-href-to-its-child) - Forces `Link` to send the `href` property to its child. Defaults to `false`
- `prefetch` - Prefetch the page in the background. Defaults to `true`
- `prefetch` - Prefetch the page in the background. Defaults to `true`. Any `<Link />` that is in the viewport (initially or through scroll) will be preloaded. Pages with data requirements will preload `JSON` files with the data for faster page transitions.
- [`replace`](#replace-the-url-instead-of-push) - Replace the current `history` state instead of adding a new url into the stack. Defaults to `false`
- [`scroll`](#disable-scrolling-to-the-top-of-the-page) - Scroll to the top of the page after a navigation. Defaults to `true`

Expand Down
1 change: 1 addition & 0 deletions docs/basic-features/data-fetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ Take a look at the following examples to learn more:
- [DatoCMS Example](https://github.com/zeit/next.js/tree/canary/examples/cms-datocms) ([Demo](https://next-blog-datocms.now.sh/))
- [TakeShape Example](https://github.com/zeit/next.js/tree/canary/examples/cms-takeshape) ([Demo](https://next-blog-takeshape.now.sh/))
- [Sanity Example](https://github.com/zeit/next.js/tree/canary/examples/cms-sanity) ([Demo](https://next-blog-sanity.now.sh/))
- [Prismic Example](https://github.com/zeit/next.js/tree/canary/examples/cms-prismic) ([Demo](https://next-blog-prismic.now.sh/))

## Learn more

Expand Down
1 change: 1 addition & 0 deletions docs/basic-features/pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ Take a look at the following examples to learn more:
- [DatoCMS Example](https://github.com/zeit/next.js/tree/canary/examples/cms-datocms) ([Demo](https://next-blog-datocms.now.sh/))
- [TakeShape Example](https://github.com/zeit/next.js/tree/canary/examples/cms-takeshape) ([Demo](https://next-blog-takeshape.now.sh/))
- [Sanity Example](https://github.com/zeit/next.js/tree/canary/examples/cms-sanity) ([Demo](https://next-blog-sanity.now.sh/))
- [Prismic Example](https://github.com/zeit/next.js/tree/canary/examples/cms-prismic) ([Demo](https://next-blog-prismic.now.sh/))

## Learn more

Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default (req: NextApiRequest, res: NextApiResponse<Data>) => {

## Custom `App`

If you have a [custom `App` ](/docs/advanced-features/custom-app), you can use the built-in type `AppProps`, like so:
If you have a [custom `App` ](/docs/advanced-features/custom-app), you can use the built-in type `AppProps` and change file name to `./pages/_app.tsx` like so:

```ts
import { AppProps } from 'next/app'
Expand Down
8 changes: 4 additions & 4 deletions docs/routing/shallow-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: You can use shallow routing to change the URL without triggering a
</ul>
</details>

Shallow routing allows you to change the URL without running [`getInitialProps`](/docs/api-reference/data-fetching/getInitialProps.md).
Shallow routing allows you to change the URL without running data fetching methods again, that includes [`getServerSideProps`](/docs/basic-features/data-fetching.md#getserversideprops-server-side-rendering), [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation), and [`getInitialProps`](/docs/api-reference/data-fetching/getInitialProps.md).

You'll receive the updated `pathname` and the `query` via the [`router` object](/docs/api-reference/next/router.md#router-object) (added by [`useRouter`](/docs/api-reference/next/router.md#useRouter) or [`withRouter`](/docs/api-reference/next/router.md#withRouter)), without losing state.

Expand All @@ -27,7 +27,7 @@ function Page() {

useEffect(() => {
// Always do navigations after the first render
router.push('/?counter=10', null, { shallow: true })
router.push('/?counter=10', undefined, { shallow: true })
}, [])

useEffect(() => {
Expand All @@ -43,7 +43,7 @@ If you don't need to add the router object to the page, you can also use the [Ro
```jsx
import Router from 'next/router'
// Inside your page
Router.push('/?counter=10', null, { shallow: true })
Router.push('/?counter=10', undefined, { shallow: true })
```

The URL will get updated to `/?counter=10`. and the page won't get replaced, only the state of the route is changed.
Expand All @@ -68,4 +68,4 @@ Shallow routing **only** works for same page URL changes. For example, let's ass
Router.push('/?counter=10', '/about?counter=10', { shallow: true })
```

Since that's a new page, it'll unload the current page, load the new one and call `getInitialProps` even though we asked to do shallow routing.
Since that's a new page, it'll unload the current page, load the new one and wait for data fetching even though we asked to do shallow routing.
17 changes: 4 additions & 13 deletions errors/missing-env-value.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@

#### Why This Error Occurred

One of your pages' config requested an env value that wasn't populated.
In one of your pages you attempted to access an environment value that is not provided in the environment.

```js
// pages/index.js
export const config = {
// this value isn't provided in `.env`
env: ['MISSING_KEY'],
}
```
When accessing environment variables on the client they must be prefixed with `NEXT_PUBLIC_` to signify they are safe to be inlined for the client.

```
// .env (notice no `MISSING_KEY` provided here)
NOTION_KEY='...'
```
When accessing environment variables on the server in `getStaticProps`, `getServerSideProps`, or an API route the value must be provided in the environment at runtime.

#### Possible Ways to Fix It

Either remove the requested env value from the page's config, populate it in your `.env` file, or manually populate it in your environment before running `next dev` or `next build`.
Either remove the code accessing the env value, populate it in your `.env` file, or manually populate it in your environment before running `next dev` or `next build`.

### Useful Links

Expand Down
2 changes: 1 addition & 1 deletion errors/opt-out-auto-static-optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

You are using `getInitialProps` in your [Custom `<App>`](https://nextjs.org/docs#custom-app).

This causes **all pages** to be executed on the server -- disabling [Automatic Static Optimization](https://nextjs.org/docs#automatic-static-optimization).
This causes **all non-getStaticProps pages** to be executed on the server -- disabling [Automatic Static Optimization](https://nextjs.org/docs#automatic-static-optimization).

#### Possible Ways to Fix It

Expand Down
10 changes: 5 additions & 5 deletions examples/api-routes-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"start": "next start"
},
"dependencies": {
"apollo-server-micro": "2.6.7",
"graphql": "14.4.2",
"isomorphic-unfetch": "3.0.0",
"apollo-server-micro": "2.11.0",
"graphql": "14.6.0",
"next": "latest",
"react": "^16.8.6",
"react-dom": "^16.8.6"
"react": "16.13.1",
"react-dom": "16.13.1",
"swr": "0.1.18"
},
"license": "ISC"
}
38 changes: 20 additions & 18 deletions examples/api-routes-graphql/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import fetch from 'isomorphic-unfetch'
import useSWR from 'swr'

const Index = ({ users }) => (
<div>
{users.map((user, i) => (
<div key={i}>{user.name}</div>
))}
</div>
)

Index.getInitialProps = async () => {
const response = await fetch('http://localhost:3000/api/graphql', {
const fetcher = query =>
fetch('/api/graphql', {
method: 'POST',
headers: {
'Content-type': 'application/json',
},
body: JSON.stringify({ query: '{ users { name } }' }),
body: JSON.stringify({ query }),
})
.then(res => res.json())
.then(json => json.data)

const {
data: { users },
} = await response.json()
export default function Index() {
const { data, error } = useSWR('{ users { name } }', fetcher)

return { users }
}
if (error) return <div>Failed to load</div>
if (!data) return <div>Loading...</div>

export default Index
const { users } = data

return (
<div>
{users.map((user, i) => (
<div key={i}>{user.name}</div>
))}
</div>
)
}
4 changes: 2 additions & 2 deletions examples/api-routes-middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
},
"dependencies": {
"cookie": "0.4.0",
"isomorphic-unfetch": "3.0.0",
"next": "latest",
"react": "^16.8.6",
"react-dom": "^16.8.6"
"react-dom": "^16.8.6",
"swr": "0.1.18"
},
"license": "ISC"
}
4 changes: 3 additions & 1 deletion examples/api-routes-middleware/pages/api/cookies.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import cookies from '../../utils/cookies'

const handler = (req, res) => {
// The cookie middleware will add the `set-cookie` header
res.cookie('Next.js', 'api-middleware!')
res.end('Hello Next.js middleware!')
// Return the `set-cookie` header so we can display it in the browser and show that it works!
res.end(res.getHeader('Set-Cookie'))
}

export default cookies(handler)
16 changes: 8 additions & 8 deletions examples/api-routes-middleware/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import fetch from 'isomorphic-unfetch'
import useSWR from 'swr'

const Index = ({ cookie }) => <div>{`Cookie from response: ${cookie}`}</div>
const fetcher = url => fetch(url).then(res => res.text())

export async function getServerSideProps() {
const response = await fetch('http://localhost:3000/api/cookies')
const cookie = response.headers.get('set-cookie')
export default function Index() {
const { data, error } = useSWR('/api/cookies', fetcher)

return { props: { cookie } }
}
if (error) return <div>Failed to load</div>
if (!data) return <div>Loading...</div>

export default Index
return <div>{`Cookie from response: "${data}"`}</div>
}
4 changes: 2 additions & 2 deletions examples/api-routes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
},
"dependencies": {
"next": "latest",
"node-fetch": "2.6.0",
"react": "^16.8.6",
"react-dom": "^16.8.6"
"react-dom": "^16.8.6",
"swr": "0.1.18"
},
"license": "ISC"
}
28 changes: 14 additions & 14 deletions examples/api-routes/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import useSWR from 'swr'
import Person from '../components/Person'
import fetch from 'node-fetch'

const Index = ({ people }) => (
<ul>
{people.map((p, i) => (
<Person key={i} person={p} />
))}
</ul>
)
const fetcher = url => fetch(url).then(res => res.json())

export async function getServerSideProps() {
const response = await fetch('http://localhost:3000/api/people')
const people = await response.json()
export default function Index() {
const { data, error } = useSWR('/api/people', fetcher)

return { props: { people } }
}
if (error) return <div>Failed to load</div>
if (!data) return <div>Loading...</div>

export default Index
return (
<ul>
{data.map((p, i) => (
<Person key={i} person={p} />
))}
</ul>
)
}
Loading

0 comments on commit a52d171

Please sign in to comment.