mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Merge branch 'master' into canary
# Conflicts: # examples/with-apollo/lib/initApollo.js # examples/with-apollo/package.json # examples/with-react-with-styles/package.json # examples/with-static-export/package.json # package.json
This commit is contained in:
commit
18f8ab392a
|
@ -2,7 +2,7 @@
|
|||
"name": "next-bench",
|
||||
"scripts": {
|
||||
"build": "next build",
|
||||
"start": "npm run build && next start",
|
||||
"start": "NODE_ENV=production npm run build && NODE_ENV=production next start",
|
||||
"bench:stateless": "ab -c1 -n3000 http://0.0.0.0:3000/stateless",
|
||||
"bench:stateless-big": "ab -c1 -n500 http://0.0.0.0:3000/stateless-big"
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ let ErrorDebugComponent
|
|||
let Component
|
||||
let stripAnsi = (s) => s
|
||||
|
||||
export const emitter = new EventEmitter()
|
||||
|
||||
export default async ({ ErrorDebugComponent: passedDebugComponent, stripAnsi: passedStripAnsi } = {}) => {
|
||||
// Wait for all the dynamic chunks to get loaded
|
||||
for (const chunkName of chunks) {
|
||||
|
@ -80,8 +82,6 @@ export default async ({ ErrorDebugComponent: passedDebugComponent, stripAnsi: pa
|
|||
err
|
||||
})
|
||||
|
||||
const emitter = new EventEmitter()
|
||||
|
||||
router.subscribe(({ Component, props, hash, err }) => {
|
||||
render({ Component, props, err, hash, emitter })
|
||||
})
|
||||
|
@ -132,7 +132,7 @@ export async function renderError (error) {
|
|||
}
|
||||
}
|
||||
|
||||
async function doRender ({ Component, props, hash, err, emitter }) {
|
||||
async function doRender ({ Component, props, hash, err, emitter: emitterProp = emitter }) {
|
||||
if (!props && Component &&
|
||||
Component !== ErrorComponent &&
|
||||
lastAppProps.Component === ErrorComponent) {
|
||||
|
@ -141,10 +141,6 @@ async function doRender ({ Component, props, hash, err, emitter }) {
|
|||
props = await loadGetInitialProps(Component, { err, pathname, query, asPath })
|
||||
}
|
||||
|
||||
if (emitter) {
|
||||
emitter.emit('before-reactdom-render', { Component, ErrorComponent })
|
||||
}
|
||||
|
||||
Component = Component || lastAppProps.Component
|
||||
props = props || lastAppProps.props
|
||||
|
||||
|
@ -152,13 +148,13 @@ async function doRender ({ Component, props, hash, err, emitter }) {
|
|||
// lastAppProps has to be set before ReactDom.render to account for ReactDom throwing an error.
|
||||
lastAppProps = appProps
|
||||
|
||||
emitterProp.emit('before-reactdom-render', { Component, ErrorComponent, appProps })
|
||||
|
||||
// We need to clear any existing runtime error messages
|
||||
ReactDOM.unmountComponentAtNode(errorContainer)
|
||||
renderReactElement(createElement(App, appProps), appContainer)
|
||||
|
||||
if (emitter) {
|
||||
emitter.emit('after-reactdom-render', { Component, ErrorComponent })
|
||||
}
|
||||
emitterProp.emit('after-reactdom-render', { Component, ErrorComponent, appProps })
|
||||
}
|
||||
|
||||
let isInitialRender = true
|
||||
|
|
|
@ -3,7 +3,7 @@ import cookie from 'cookie'
|
|||
import PropTypes from 'prop-types'
|
||||
import { ApolloProvider, getDataFromTree } from 'react-apollo'
|
||||
|
||||
import initApollo from './init-apollo'
|
||||
import initApollo from './initApollo'
|
||||
|
||||
function parseCookies (ctx = {}, options = {}) {
|
||||
return cookie.parse(
|
|
@ -15,9 +15,9 @@
|
|||
"isomorphic-unfetch": "^2.0.0",
|
||||
"next": "latest",
|
||||
"prop-types": "^15.5.10",
|
||||
"react": "^15.5.4",
|
||||
"react": "^16.0.0",
|
||||
"react-apollo": "^1.1.3",
|
||||
"react-dom": "^15.5.4"
|
||||
"react-dom": "^16.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^0.19.1",
|
||||
|
|
|
@ -4,9 +4,9 @@ import cookie from 'cookie'
|
|||
import Link from 'next/link'
|
||||
import gql from 'graphql-tag'
|
||||
|
||||
import withData from '../lib/with-data'
|
||||
import withData from '../lib/withData'
|
||||
import redirect from '../lib/redirect'
|
||||
import checkLoggedIn from '../lib/check-logged-in'
|
||||
import checkLoggedIn from '../lib/checkLoggedIn'
|
||||
|
||||
class CreateAccount extends React.Component {
|
||||
static async getInitialProps (context, apolloClient) {
|
||||
|
|
|
@ -2,9 +2,9 @@ import React from 'react'
|
|||
import cookie from 'cookie'
|
||||
import { withApollo, compose } from 'react-apollo'
|
||||
|
||||
import withData from '../lib/with-data'
|
||||
import withData from '../lib/withData'
|
||||
import redirect from '../lib/redirect'
|
||||
import checkLoggedIn from '../lib/check-logged-in'
|
||||
import checkLoggedIn from '../lib/checkLoggedIn'
|
||||
|
||||
class Index extends React.Component {
|
||||
static async getInitialProps (context, apolloClient) {
|
||||
|
|
|
@ -4,9 +4,9 @@ import cookie from 'cookie'
|
|||
import Link from 'next/link'
|
||||
import gql from 'graphql-tag'
|
||||
|
||||
import withData from '../lib/with-data'
|
||||
import withData from '../lib/withData'
|
||||
import redirect from '../lib/redirect'
|
||||
import checkLoggedIn from '../lib/check-logged-in'
|
||||
import checkLoggedIn from '../lib/checkLoggedIn'
|
||||
|
||||
class Signin extends React.Component {
|
||||
static async getInitialProps (context, apolloClient) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React from 'react'
|
||||
import ReactDOMServer from 'react-dom/lib/ReactDOMServer'
|
||||
import ReactDOMServer from 'react-dom/server'
|
||||
|
||||
export default function Noscript (props) {
|
||||
const staticMarkup = ReactDOMServer.renderToStaticMarkup(props.children)
|
||||
|
|
|
@ -2,7 +2,7 @@ module.exports = {
|
|||
webpack: (config, { dev }) => {
|
||||
if (!dev) {
|
||||
config.resolve.alias = {
|
||||
'react-dom/server': require.resolve('react-dom/dist/react-dom-server.min.js')
|
||||
'react-dom/server': require.resolve('react-dom/umd/react-dom-server.browser.production.min.js')
|
||||
}
|
||||
}
|
||||
return config
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
"start": "next start"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "^3.0.3",
|
||||
"next": "latest",
|
||||
"react": "^16.0.0",
|
||||
"react-dom": "^16.0.0",
|
||||
"react-lazyload": "^2.2.7"
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
{
|
||||
"name": "with-static-export",
|
||||
"main": "server.js",
|
||||
"dependencies": {
|
||||
"express": "^4.15.3",
|
||||
"isomorphic-unfetch": "^2.0.0",
|
||||
"next": "beta",
|
||||
"react": "^15.5.4",
|
||||
"react-dom": "^15.5.4",
|
||||
"next": "latest",
|
||||
"react": "^16.0.0",
|
||||
"react-dom": "^16.0.0",
|
||||
"serve": "^5.2.2"
|
||||
},
|
||||
"scripts": {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
"files": [
|
||||
"dist",
|
||||
"babel.js",
|
||||
"client.js",
|
||||
"link.js",
|
||||
"css.js",
|
||||
"head.js",
|
||||
|
|
|
@ -1190,6 +1190,8 @@ Next.js bundles [styled-jsx](https://github.com/zeit/styled-jsx) supporting scop
|
|||
- [with-external-scoped-css](./examples/with-external-scoped-css)
|
||||
- [with-scoped-stylesheets-and-postcss](./examples/with-scoped-stylesheets-and-postcss)
|
||||
- [with-global-stylesheet](./examples/with-global-stylesheet)
|
||||
- [with-styled-jsx-scss](./examples/with-styled-jsx-scss)
|
||||
- [with-styled-jsx-plugins](./examples/with-styled-jsx-plugins)
|
||||
|
||||
</details>
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ export default async function build (dir, conf = null) {
|
|||
const compiler = await webpack(dir, { buildId, buildDir, conf })
|
||||
|
||||
try {
|
||||
await runCompiler(compiler)
|
||||
await writeBuildStats(buildDir)
|
||||
const stats = await runCompiler(compiler)
|
||||
await writeBuildStats(buildDir, stats)
|
||||
await writeBuildId(buildDir, buildId)
|
||||
} catch (err) {
|
||||
console.error(`> Failed to build on ${buildDir}`)
|
||||
|
@ -46,7 +46,7 @@ function runCompiler (compiler) {
|
|||
})
|
||||
}
|
||||
|
||||
async function writeBuildStats (dir) {
|
||||
async function writeBuildStats (dir, stats) {
|
||||
// Here we can't use hashes in webpack chunks.
|
||||
// That's because the "app.js" is not tied to a chunk.
|
||||
// It's created by merging a few assets. (commons.js and main.js)
|
||||
|
@ -58,6 +58,9 @@ async function writeBuildStats (dir) {
|
|||
}
|
||||
const buildStatsPath = join(dir, '.next', 'build-stats.json')
|
||||
await fs.writeFile(buildStatsPath, JSON.stringify(assetHashMap), 'utf8')
|
||||
|
||||
const statsPath = join(dir, '.next', 'webpack-stats.json')
|
||||
await fs.writeFile(statsPath, JSON.stringify(stats), 'utf8')
|
||||
}
|
||||
|
||||
async function writeBuildId (dir, buildId) {
|
||||
|
|
|
@ -43,6 +43,7 @@ export default async function createCompiler (dir, { buildId, dev = false, quiet
|
|||
const entries = {
|
||||
'main.js': [
|
||||
...defaultEntries,
|
||||
...config.clientBootstrap || [],
|
||||
mainJS
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue