8000 Strip ansi codes when logging client side (#3138) · JavaScriptExpert/next.js@a28bbb0 · GitHub
[go: up one dir, main page]

Skip to content

Commit a28bbb0

Browse files
authored
Strip ansi codes when logging client side (vercel#3138)
1 parent 89691cb commit a28bbb0

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

client/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,22 @@ export let router
5454
export let ErrorComponent
5555
let ErrorDebugComponent
5656
let Component
57+
let stripAnsi = (s) => s
5758

58-
export default async ({ ErrorDebugComponent: passedDebugComponent } = {}) => {
59+
export default async ({ ErrorDebugComponent: passedDebugComponent, stripAnsi: passedStripAnsi } = {}) => {
5960
// Wait for all the dynamic chunks to get loaded
6061
for (const chunkName of chunks) {
6162
await pageLoader.waitForChunk(chunkName)
6263
}
6364

65+
stripAnsi = passedStripAnsi || stripAnsi
6466
ErrorDebugComponent = passedDebugComponent
6567
ErrorComponent = await pageLoader.loadPage('/_error')
6668

6769
try {
6870
Component = await pageLoader.loadPage(pathname)
6971
} catch (err) {
70-
console.error(`${err.message}\n${err.stack}`)
72+
console.error(stripAnsi(`${err.message}\n${err.stack}`))
7173
Component = ErrorComponent
7274
}
7375

@@ -119,7 +121,7 @@ export async function renderError (error) {
119121
ReactDOM.unmountComponentAtNode(appContainer)
120122

121123
const errorMessage = `${error.message}\n${error.stack}`
122-
console.error(errorMessage)
124+
console.error(stripAnsi(errorMessage))
123125

124126
if (prod) {
125127
const initProps = { err: error, pathname, query, asPath }

client/next-dev.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import 'react-hot-loader/patch'
2+
import stripAnsi from 'strip-ansi'
23
import initNext, * as next from './'
34
import ErrorDebugComponent from '../lib/error-debug'
45
import initOnDemandEntries from './on-demand-entries-client'
56
import initWebpackHMR from './webpack-hot-middleware-client'
67

78
window.next = next
89

9-
initNext({ ErrorDebugComponent })
10+
initNext({ ErrorDebugComponent, stripAnsi })
1011
.then((emitter) => {
1112
initOnDemandEntries()
1213
initWebpackHMR()
@@ -34,5 +35,5 @@ initNext({ ErrorDebugComponent })
3435
})
3536
})
3637
.catch((err) => {
37-
console.error(`${err.message}\n${err.stack}`)
38+
console.error(stripAnsi(`${err.message}\n${err.stack}`))
3839
})

0 commit comments

Comments
 (0)
0