Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "React 16 (fiber)" #3011

Merged
merged 5 commits into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ export async function renderError (error) {
if (prod) {
const initProps = { err: error, pathname, query, asPath }
const props = await loadGetInitialProps(ErrorComponent, initProps)
ReactDOM.hydrate(createElement(ErrorComponent, props), errorContainer)
ReactDOM.render(createElement(ErrorComponent, props), errorContainer)
} else {
ReactDOM.hydrate(createElement(ErrorDebugComponent, { error }), errorContainer)
ReactDOM.render(createElement(ErrorDebugComponent, { error }), errorContainer)
}
}

Expand All @@ -151,7 +151,7 @@ async function doRender ({ Component, props, hash, err, emitter }) {

// We need to clear any existing runtime error messages
ReactDOM.unmountComponentAtNode(errorContainer)
ReactDOM.hydrate(createElement(App, appProps), appContainer)
ReactDOM.render(createElement(App, appProps), appContainer)

if (emitter) {
emitter.emit('after-reactdom-render', { Component, ErrorComponent })
Expand Down
15 changes: 15 additions & 0 deletions client/next-dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'react-hot-loader/patch'
import ReactReconciler from 'react-dom/lib/ReactReconciler'
import initOnDemandEntries from './on-demand-entries-client'
import initWebpackHMR from './webpack-hot-middleware-client'

Expand Down Expand Up @@ -34,3 +35,17 @@ next.default()
.catch((err) => {
console.error(`${err.message}\n${err.stack}`)
})

// This is a patch to catch most of the errors throw inside React components.
const originalMountComponent = ReactReconciler.mountComponent
ReactReconciler.mountComponent = function (...args) {
try {
return originalMountComponent(...args)
} catch (err) {
if (!err.abort) {
next.renderError(err)
err.abort = true
}
throw err
}
}
12 changes: 0 additions & 12 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import { warn } from './utils'
import { makePublicRouterInstance } from './router'

export default class App extends Component {
state = {
hasError: null
}

static childContextTypes = {
headManager: PropTypes.object,
router: PropTypes.object
Expand All @@ -22,15 +18,7 @@ export default class App extends Component {
}
}

componentDidCatch (error, info) {
error.stack = `${error.stack}\n\n${info.componentStack}`
window.next.renderError(error)
this.setState({ hasError: true })
}

render () {
if (this.state.hasError) return null

const { Component, props, hash, router } = this.props
const url = createUrl(router)
// If there no component exported we can't proceed.
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@
"node-notifier": "5.1.2",
"nyc": "11.2.1",
"portfinder": "1.0.13",
"react": "16.0.0",
"react-dom": "16.0.0",
"react": "15.5.4",
"react-dom": "15.5.4",
"standard": "9.0.2",
"taskr": "1.1.0",
"wd": "1.4.1"
},
"peerDependencies": {
"react": "^16.0.0",
"react-dom": "^16.0.0"
"react": "^15.5.4",
"react-dom": "^15.5.4"
},
"jest": {
"testEnvironment": "node",
Expand Down
4 changes: 2 additions & 2 deletions test/integration/basic/test/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function ({ app }, suiteName, render) {
describe(suiteName, () => {
test('renders a stateless component', async () => {
const html = await render('/stateless')
expect(html.includes('<meta charSet="utf-8" class="next-head"/>')).toBeTruthy()
expect(html.includes('<meta charset="utf-8" class="next-head"/>')).toBeTruthy()
expect(html.includes('My component!')).toBeTruthy()
})

Expand All @@ -23,7 +23,7 @@ export default function ({ app }, suiteName, render) {

test('header helper renders header information', async () => {
const html = await (render('/head'))
expect(html.includes('<meta charSet="iso-8859-5" class="next-head"/>')).toBeTruthy()
expect(html.includes('<meta charset="iso-8859-5" class="next-head"/>')).toBeTruthy()
expect(html.includes('<meta content="my meta" class="next-head"/>')).toBeTruthy()
expect(html.includes('I can haz meta tags')).toBeTruthy()
})
Expand Down