Skip to content

Commit c07f850

Browse files
timothyisMatthew Sweeney
authored andcommitted
Upgrade to Next.js 9 (#1034)
* Upgrade to Next.js 9 * Update _document AMP usage * Update to remove build config * Allow Next.js to build without config * Remove exportTrailingSlash config * Update config * Remove serverless target * Fix Next.js configuration * Fix broken merge conflict
1 parent 489fbc0 commit c07f850

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+394
-277
lines changed

next.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ module.exports = phase => {
9292
const isDev = phase === PHASE_DEVELOPMENT_SERVER
9393

9494
const config = {
95+
exportTrailingSlash: true,
96+
9597
// Allow mdx and md files to be pages
9698
pageExtensions: ['jsx', 'js', 'mdx', 'md'],
9799

98-
assetPrefix: isExport ? '/docs' : '',
100+
assetPrefix: isExport || isProdBuild ? '/docs' : '',
99101

100102
env: {
101103
VERSION: require('./package.json').version,

now.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
"version": 2,
33
"public": true,
44
"builds": [
5-
{ "src": "package.json", "use": "@now/static-build" },
5+
{
6+
"src": "package.json",
7+
"use": "@now/static-build",
8+
"config": {
9+
"forceBuildIn": "bru1"
10+
}
11+
},
612
{ "src": "static/*", "use": "@now/static" }
713
],
814
"routes": [

package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
"private": true,
55
"scripts": {
66
"dev": "next",
7-
"build": "cross-env NODE_ENV=production next build",
8-
"now-build": "yarn run build && yarn run export",
9-
"now-dev": "next -p $PORT",
10-
"start": "cross-env NODE_ENV=production next start",
11-
"export": "next export -o dist",
7+
"build": "next build",
8+
"start": "next start",
129
"lint": "eslint .",
1310
"test": "yarn run lint",
11+
"export": "next export -o dist",
12+
"now-build": "yarn run build && yarn run export",
1413
"update-mdx-meta": "node scripts/update-mdx-meta",
1514
"prettier": "prettier --write \"**/*.{js,json,md,mdx}\"",
1615
"docs-index": "node ./scripts/index-docs.js"
@@ -43,14 +42,14 @@
4342
"lodash.debounce": "4.0.8",
4443
"md5": "2.2.1",
4544
"mitt": "1.1.2",
46-
"next": "8.1.1-canary.37",
45+
"next": "9.0.3-canary.2",
4746
"nprogress": "0.2.0",
4847
"prop-types": "15.6.2",
4948
"qs": "6.6.0",
5049
"ramda": "0.25.0",
51-
"react": "16.8.4",
50+
"react": "16.8.6",
5251
"react-autosuggest": "9.4.3",
53-
"react-dom": "16.8.4",
52+
"react-dom": "16.8.6",
5453
"react-instantsearch-dom": "5.4.0",
5554
"react-markdown": "4.0.6",
5655
"refractor": "2.8.0",

pages/_app.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ import authenticate from '~/lib/authenticate'
44
import { UserContext } from '~/lib/user-context'
55

66
export default class MyApp extends App {
7-
static async getInitialProps({ Component, ctx }) {
8-
let pageProps = {}
9-
// const req = ctx.req
10-
11-
if (Component.getInitialProps) {
12-
pageProps = await Component.getInitialProps(ctx)
13-
}
14-
15-
return { pageProps }
16-
}
17-
187
state = {
198
user: {},
209
userLoaded: false

pages/_document.js

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,73 @@
11
import Document_, { Html, Head, Main, NextScript } from 'next/document'
22
import { GA_ID } from '../lib/metrics'
3+
import { useAmp } from 'next/amp'
4+
5+
function AmpWrap({ ampOnly, nonAmp }) {
6+
const isAmp = useAmp()
7+
if (ampOnly) return isAmp && ampOnly
8+
return !isAmp && nonAmp
9+
}
310

411
export default class Document extends Document_ {
512
render() {
613
const { amphtml } = this.props
714
return (
815
<Html lang="en">
916
<Head>
10-
{amphtml && (
11-
<script
12-
async
13-
key="amp-analytics"
14-
custom-element="amp-analytics"
15-
src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"
16-
/>
17-
)}
17+
<AmpWrap
18+
ampOnly={
19+
<script
20+
async
21+
key="amp-analytics"
22+
custom-element="amp-analytics"
23+
src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"
24+
/>
25+
}
26+
/>
1827
</Head>
1928
<body>
2029
<Main />
21-
{amphtml ? (
22-
<>
23-
<amp-analytics type="gtag" data-credentials="include">
24-
<script
25-
type="application/json"
26-
dangerouslySetInnerHTML={{
27-
__html: JSON.stringify({
28-
vars: {
29-
gtag_id: GA_ID,
30-
config: {
31-
[GA_ID]: { groups: 'default' }
30+
<AmpWrap
31+
ampOnly={
32+
<>
33+
<amp-analytics type="gtag" data-credentials="include">
34+
<script
35+
type="application/json"
36+
dangerouslySetInnerHTML={{
37+
__html: JSON.stringify({
38+
vars: {
39+
gtag_id: GA_ID,
40+
config: {
41+
[GA_ID]: { groups: 'default' }
42+
}
3243
}
33-
}
34-
})
35-
}}
44+
})
45+
}}
46+
/>
47+
</amp-analytics>
48+
</>
49+
}
50+
/>
51+
<AmpWrap
52+
nonAmp={
53+
<>
54+
<script
55+
async
56+
src={`https://www.googletagmanager.com/gtag/js?id=${GA_ID}`}
3657
/>
37-
</amp-analytics>
38-
</>
39-
) : (
40-
<>
41-
<script
42-
async
43-
src={`https://www.googletagmanager.com/gtag/js?id=${GA_ID}`}
44-
/>
45-
<script
46-
dangerouslySetInnerHTML={{
47-
__html: `
58+
<script
59+
dangerouslySetInnerHTML={{
60+
__html: `
4861
window.dataLayer = window.dataLayer || [];
4962
function gtag(){dataLayer.push(arguments);}
5063
gtag('js', new Date());
5164
gtag('config', '${GA_ID}');
5265
`
53-
}}
54-
/>
55-
</>
56-
)}
66+
}}
67+
/>
68+
</>
69+
}
70+
/>
5771
<NextScript />
5872
</body>
5973
</Html>

pages/docs/v2/advanced/builders/bash-now-bash.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const meta = {
1414
description:
1515
'The official Bash Builder for ZEIT Now. Write Bash functions that serve HTTP requests.',
1616
editUrl: 'pages/docs/v2/advanced/builders/bash-now-bash.mdx',
17-
lastEdited: '2019-07-22T21:10:56.000Z'
17+
lastEdited: '2019-07-22T15:33:14.000Z'
1818
}
1919

2020
<Tag>Status: Alpha</Tag>
@@ -228,6 +228,8 @@ handler() {
228228

229229
**Demo:** <https://bash-version-rkb5w4ua6.now.sh/>
230230

231-
export default withAmp(({ children }) => <Doc meta={meta}>{children}</Doc>, {
232-
hybrid: true
233-
})
231+
export default ({ children }) => <Doc meta={meta}>{children}</Doc>
232+
233+
export const config = {
234+
amp: 'hybrid'
235+
}

pages/docs/v2/advanced/builders/developer-guide.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const meta = {
66
description:
77
'How to create a Builder to take ZEIT Now deployment sources and output either static files or lambdas with almost limitless possibilities.',
88
editUrl: 'pages/docs/v2/advanced/builders/developer-guide.mdx',
9-
lastEdited: '2019-07-16T12:01:51.000Z'
9+
lastEdited: '2019-07-22T15:33:14.000Z'
1010
}
1111

1212
A builder is an npm module that exposes a `build` function and optionally an `analyze` function and `prepareCache` function.
@@ -455,6 +455,8 @@ const originalFiles = { 'one.go': fileFsRef1, 'two.go': fileFsRef2 }
455455
const renamedFiles = rename(originalFiles, path => path.replace(/\.go$/, '')
456456
```
457457
458-
export default withAmp(({ children }) => <Doc meta={meta}>{children}</Doc>, {
459-
hybrid: true
460-
})
458+
export default ({ children }) => <Doc meta={meta}>{children}</Doc>
459+
460+
export const config = {
461+
amp: 'hybrid'
462+
}

pages/docs/v2/advanced/builders/go-now-go.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const meta = {
1212
description:
1313
'The official Go Builder for ZEIT Now. Serverless invokable functions from Go source code for ZEIT Now deployments.',
1414
editUrl: 'pages/docs/v2/advanced/builders/go-now-go.mdx',
15-
lastEdited: '2019-07-22T21:10:56.000Z'
15+
lastEdited: '2019-07-22T15:33:14.000Z'
1616
}
1717

1818
<Tag>Status: Alpha</Tag>
@@ -89,6 +89,8 @@ With GitHub, you will need to [create a personal token](https://github.com/setti
8989
9090
Go 1.x is used.
9191
92-
export default withAmp(({ children }) => <Doc meta={meta}>{children}</Doc>, {
93-
hybrid: true
94-
})
92+
export default ({ children }) => <Doc meta={meta}>{children}</Doc>
93+
94+
export const config = {
95+
amp: 'hybrid'
96+
}

pages/docs/v2/advanced/builders/html-minifier-now-html-minifier.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const meta = {
1414
'The official HTML Minifier Builder for ZEIT Now. Minify HTML sources when deploying to ZEIT Now.',
1515
editUrl:
1616
'pages/docs/v2/advanced/builders/html-minifier-now-html-minifier.mdx',
17-
lastEdited: '2019-07-16T12:01:51.000Z'
17+
lastEdited: '2019-07-22T15:33:14.000Z'
1818
}
1919

2020
<Tag>Status: Deprecated</Tag>
@@ -76,6 +76,8 @@ The example deployment above is open-source and you can view the code for it her
7676

7777
The entrypoint is always a `.html` file you want to optimize.
7878

79-
export default withAmp(({ children }) => <Doc meta={meta}>{children}</Doc>, {
80-
hybrid: true
81-
})
79+
export default ({ children }) => <Doc meta={meta}>{children}</Doc>
80+
81+
export const config = {
82+
amp: 'hybrid'
83+
}

pages/docs/v2/advanced/builders/markdown-now-md.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const meta = {
1313
description:
1414
'The official Markdown Builder for ZEIT Now. Transform markdown sources to a HTML output for ZEIT Now deployments.',
1515
editUrl: 'pages/docs/v2/advanced/builders/markdown-now-md.mdx',
16-
lastEdited: '2019-07-16T12:01:51.000Z'
16+
lastEdited: '2019-07-22T15:33:14.000Z'
1717
}
1818

1919
<Tag>Status: Deprecated</Tag>
@@ -63,6 +63,8 @@ Also, the source code of the deployment can be checked by appending `/_src` e.
6363

6464
The entrypoint is always an `.md` file you want to convert to HTML.
6565

66-
export default withAmp(({ children }) => <Doc meta={meta}>{children}</Doc>, {
67-
hybrid: true
68-
})
66+
export default ({ children }) => <Doc meta={meta}>{children}</Doc>
67+
68+
export const config = {
69+
amp: 'hybrid'
70+
}

0 commit comments

Comments
 (0)