1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Strip ansi codes when logging client side (#3138)

This commit is contained in:
Tim Neutkens 2017-10-21 12:58:59 +02:00 committed by GitHub
parent 89691cbe0c
commit a28bbb0ff9
2 changed files with 8 additions and 5 deletions

View file

@ -54,20 +54,22 @@ export let router
export let ErrorComponent
let ErrorDebugComponent
let Component
let stripAnsi = (s) => s
export default async ({ ErrorDebugComponent: passedDebugComponent } = {}) => {
export default async ({ ErrorDebugComponent: passedDebugComponent, stripAnsi: passedStripAnsi } = {}) => {
// Wait for all the dynamic chunks to get loaded
for (const chunkName of chunks) {
await pageLoader.waitForChunk(chunkName)
}
stripAnsi = passedStripAnsi || stripAnsi
ErrorDebugComponent = passedDebugComponent
ErrorComponent = await pageLoader.loadPage('/_error')
try {
Component = await pageLoader.loadPage(pathname)
} catch (err) {
console.error(`${err.message}\n${err.stack}`)
console.error(stripAnsi(`${err.message}\n${err.stack}`))
Component = ErrorComponent
}
@ -119,7 +121,7 @@ export async function renderError (error) {
ReactDOM.unmountComponentAtNode(appContainer)
const errorMessage = `${error.message}\n${error.stack}`
console.error(errorMessage)
console.error(stripAnsi(errorMessage))
if (prod) {
const initProps = { err: error, pathname, query, asPath }

View file

@ -1,4 +1,5 @@
import 'react-hot-loader/patch'
import stripAnsi from 'strip-ansi'
import initNext, * as next from './'
import ErrorDebugComponent from '../lib/error-debug'
import initOnDemandEntries from './on-demand-entries-client'
@ -6,7 +7,7 @@ import initWebpackHMR from './webpack-hot-middleware-client'
window.next = next
initNext({ ErrorDebugComponent })
initNext({ ErrorDebugComponent, stripAnsi })
.then((emitter) => {
initOnDemandEntries()
initWebpackHMR()
@ -34,5 +35,5 @@ initNext({ ErrorDebugComponent })
})
})
.catch((err) => {
console.error(`${err.message}\n${err.stack}`)
console.error(stripAnsi(`${err.message}\n${err.stack}`))
})