mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
68626c5147
* Handle production errors correctly * Improved source map support * Make react-hot-loader hold state again * Remove console.log * Load modules on demand * Catch errors in rewriteErrorTrace * Update comment * Update comment * Remove source-map-support * Load modules in next-dev * Make sure error logged has sourcemaps too * Add tests for production runtime errors * Add tests for development runtime errors. Fix issue with client side errors in development * Move functionality back to renderError now that error handling is consistent * Rename to applySourcemaps
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
import stripAnsi from 'strip-ansi'
|
|
import initNext, * as next from './'
|
|
import {ClientDebug} from '../lib/error-debug'
|
|
import initOnDemandEntries from './on-demand-entries-client'
|
|
import initWebpackHMR from './webpack-hot-middleware-client'
|
|
import {AppContainer as HotAppContainer} from 'react-hot-loader'
|
|
import {applySourcemaps} from './source-map-support'
|
|
|
|
window.next = next
|
|
|
|
initNext({ HotAppContainer, ErrorDebugComponent: ClientDebug, applySourcemaps, stripAnsi })
|
|
.then((emitter) => {
|
|
initOnDemandEntries()
|
|
initWebpackHMR()
|
|
|
|
let lastScroll
|
|
|
|
emitter.on('before-reactdom-render', ({ Component, ErrorComponent }) => {
|
|
// Remember scroll when ErrorComponent is being rendered to later restore it
|
|
if (!lastScroll && Component === ErrorComponent) {
|
|
const { pageXOffset, pageYOffset } = window
|
|
lastScroll = {
|
|
x: pageXOffset,
|
|
y: pageYOffset
|
|
}
|
|
}
|
|
})
|
|
|
|
emitter.on('after-reactdom-render', ({ Component, ErrorComponent }) => {
|
|
if (lastScroll && Component !== ErrorComponent) {
|
|
// Restore scroll after ErrorComponent was replaced with a page component by HMR
|
|
const { x, y } = lastScroll
|
|
window.scroll(x, y)
|
|
lastScroll = null
|
|
}
|
|
})
|
|
})
|
|
.catch((err) => {
|
|
console.error(stripAnsi(`${err.message}\n${err.stack}`))
|
|
})
|