Skip to content

Commit

Permalink
Merge branch 'canary' into remove-concurrency-from-next-export
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Oct 26, 2019
2 parents 2e005d3 + 94e81c0 commit 10ceab7
Show file tree
Hide file tree
Showing 11 changed files with 402 additions and 180 deletions.
20 changes: 16 additions & 4 deletions examples/with-react-intl/pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import App from 'next/app'
import React from 'react'
import { IntlProvider } from 'react-intl'
import { createIntl, createIntlCache, RawIntlProvider } from 'react-intl'

// This is optional but highly recommended
// since it prevents memory leak
const cache = createIntlCache()

export default class MyApp extends App {
static async getInitialProps ({ Component, router, ctx }) {
static async getInitialProps ({ Component, ctx }) {
let pageProps = {}

if (Component.getInitialProps) {
Expand All @@ -21,10 +25,18 @@ export default class MyApp extends App {
render () {
const { Component, pageProps, locale, messages } = this.props

const intl = createIntl(
{
locale,
messages
},
cache
)

return (
<IntlProvider locale={locale} messages={messages}>
<RawIntlProvider value={intl}>
<Component {...pageProps} />
</IntlProvider>
</RawIntlProvider>
)
}
}
3 changes: 3 additions & 0 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,9 @@ export default async function getBaseWebpackConfig(
'process.env.__NEXT_PRERENDER_INDICATOR': JSON.stringify(
config.devIndicators.autoPrerender
),
'process.env.__NEXT_STRICT_MODE': JSON.stringify(
config.reactStrictMode
),
...(isServer
? {
// Fix bad-actors in the npm ecosystem (e.g. `node-formidable`)
Expand Down
14 changes: 11 additions & 3 deletions packages/next/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,19 @@ async function doRender ({ App, Component, props, err }) {
appProps
})

// We catch runtime errors using componentDidCatch which will trigger renderError
renderReactElement(
const elem = (
<AppContainer>
<App {...appProps} />
</AppContainer>,
</AppContainer>
)

// We catch runtime errors using componentDidCatch which will trigger renderError
renderReactElement(
process.env.__NEXT_STRICT_MODE ? (
<React.StrictMode>{elem}</React.StrictMode>
) : (
elem
),
appElement
)

Expand Down
1 change: 1 addition & 0 deletions packages/next/next-server/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const defaultConfig: { [key: string]: any } = {
},
serverRuntimeConfig: {},
publicRuntimeConfig: {},
reactStrictMode: false,
}

const experimentalWarning = execOnce(() => {
Expand Down
6 changes: 5 additions & 1 deletion packages/next/next-server/server/spr-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { promisify } from 'util'
import { PrerenderManifest } from '../../build'
import { PRERENDER_MANIFEST } from '../lib/constants'
import { normalizePagePath } from './normalize-page-path'
import mkdirpOrig from 'mkdirp'

const mkdirp = promisify(mkdirpOrig)
const readFile = promisify(fs.readFile)
const writeFile = promisify(fs.writeFile)

Expand Down Expand Up @@ -166,7 +168,9 @@ export async function setSprCache(
// `next build` output's manifest.
if (sprOptions.flushToDisk) {
try {
await writeFile(getSeedPath(pathname, 'html'), data.html, 'utf8')
const seedPath = getSeedPath(pathname, 'html')
await mkdirp(path.dirname(seedPath))
await writeFile(seedPath, data.html, 'utf8')
await writeFile(
getSeedPath(pathname, 'json'),
JSON.stringify(data.pageData),
Expand Down
21 changes: 10 additions & 11 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@
},
"dependencies": {
"@ampproject/toolbox-optimizer": "1.1.1",
"@babel/core": "7.4.5",
"@babel/plugin-proposal-class-properties": "7.4.4",
"@babel/plugin-proposal-object-rest-spread": "7.4.4",
"@babel/core": "7.6.4",
"@babel/plugin-proposal-class-properties": "7.5.5",
"@babel/plugin-proposal-object-rest-spread": "7.6.2",
"@babel/plugin-syntax-dynamic-import": "7.2.0",
"@babel/plugin-transform-modules-commonjs": "7.4.4",
"@babel/plugin-transform-runtime": "7.4.4",
"@babel/preset-env": "7.4.5",
"@babel/preset-react": "7.0.0",
"@babel/preset-typescript": "7.3.3",
"@babel/runtime": "7.4.5",
"@babel/runtime-corejs2": "7.4.5",
"@babel/plugin-transform-modules-commonjs": "7.6.0",
"@babel/plugin-transform-runtime": "7.6.2",
"@babel/preset-env": "7.6.3",
"@babel/preset-react": "7.6.3",
"@babel/preset-typescript": "7.6.0",
"@babel/runtime": "7.6.3",
"@babel/runtime-corejs2": "7.6.3",
"amphtml-validator": "1.0.23",
"async-retry": "1.2.3",
"async-sema": "3.0.0",
Expand Down Expand Up @@ -135,7 +135,6 @@
"react-dom": "^16.6.0"
},
"devDependencies": {
"@babel/parser": "7.4.5",
"@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0",
"@taskr/watch": "1.1.0",
Expand Down
1 change: 1 addition & 0 deletions packages/next/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export class Head extends Component<
cssFiles.forEach(file => {
cssLinkElements.push(
<link
key="${file}-preload"
nonce={this.props.nonce}
rel="preload"
href={`${assetPrefix}/_next/${encodeURI(file)}`}
Expand Down
30 changes: 30 additions & 0 deletions test/integration/prerender/pages/user/[user]/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react'
import Link from 'next/link'

// eslint-disable-next-line camelcase
export async function unstable_getStaticParams () {
return []
}

// eslint-disable-next-line camelcase
export async function unstable_getStaticProps ({ params }) {
return {
props: {
user: params.user,
time: (await import('perf_hooks')).performance.now()
},
revalidate: 10
}
}

export default ({ user, time }) => {
return (
<>
<p>User: {user}</p>
<span>time: {time}</span>
<Link href='/'>
<a id='home'>to home</a>
</Link>
</>
)
}
26 changes: 24 additions & 2 deletions test/integration/prerender/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let appPort
let buildId
let distPagesDir
let exportDir
let stderr

const startServer = async (optEnv = {}) => {
const scriptPath = join(appDir, 'server.js')
Expand Down Expand Up @@ -264,6 +265,11 @@ const runTests = (dev = false) => {
dataRoute: `/_next/data/${buildId}/blog/[post]/[comment].json`,
dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/blog\\/([^\\/]+?)\\/([^\\/]+?)\\.json$`,
routeRegex: '^\\/blog\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$'
},
'/user/[user]/profile': {
dataRoute: `/_next/data/${buildId}/user/[user]/profile.json`,
dataRouteRegex: `^\\/_next\\/data\\/${escapedBuildId}\\/user\\/([^\\/]+?)\\/profile\\.json$`,
routeRegex: `^\\/user\\/([^\\/]+?)\\/profile(?:\\/)?$`
}
})
})
Expand Down Expand Up @@ -351,6 +357,12 @@ const runTests = (dev = false) => {
const val = await browser.eval('window.thisShouldStay')
expect(val).toBe(true)
})

it('should not error when flushing cache files', async () => {
await fetchViaHTTP(appPort, '/user/user-1/profile')
await waitFor(500)
expect(stderr).not.toMatch(/Failed to update prerender files for/)
})
}
}

Expand All @@ -374,8 +386,13 @@ describe('SPR Prerender', () => {
'utf8'
)
await nextBuild(appDir)
stderr = ''
appPort = await findPort()
app = nextStart(appDir, appPort)
app = nextStart(appDir, appPort, {
onStderr: msg => {
stderr += msg
}
})
distPagesDir = join(appDir, '.next/serverless/pages')
buildId = await fs.readFile(join(appDir, '.next/BUILD_ID'), 'utf8')
})
Expand Down Expand Up @@ -404,8 +421,13 @@ describe('SPR Prerender', () => {
await fs.unlink(nextConfig)
} catch (_) {}
await nextBuild(appDir)
stderr = ''
appPort = await findPort()
app = await nextStart(appDir, appPort)
app = await nextStart(appDir, appPort, {
onStderr: msg => {
stderr += msg
}
})
buildId = await fs.readFile(join(appDir, '.next/BUILD_ID'), 'utf8')
distPagesDir = join(appDir, '.next/server/static', buildId, 'pages')
})
Expand Down
4 changes: 2 additions & 2 deletions test/integration/size-limit/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('Production response size', () => {
)

// These numbers are without gzip compression!
expect(responseSizeKilobytes).toBeLessThanOrEqual(220) // Kilobytes
expect(responseSizeKilobytes).toBeLessThanOrEqual(221) // Kilobytes
})

it('should not increase the overall response size of modern build', async () => {
Expand All @@ -99,6 +99,6 @@ describe('Production response size', () => {
)

// These numbers are without gzip compression!
expect(responseSizeKilobytes).toBeLessThanOrEqual(198) // Kilobytes
expect(responseSizeKilobytes).toBeLessThanOrEqual(199) // Kilobytes
})
})
Loading

0 comments on commit 10ceab7

Please sign in to comment.