Unverified Commit 2e29c7b1 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix missing source code display for some jsx errors (#60390)

There're some cases that error frames file is still conating
"webpack-internal" for server component and also the webpack layer info
such as `(rsc)` so that the source file is not properly recovered

### After


![image](https://github.com/vercel/next.js/assets/4800338/78ba137d-62f0-4c5b-b502-c3500b8b79db)


### Before

![image](https://github.com/vercel/next.js/assets/4800338/bd585c7c-2264-4f30-9deb-5fec004be19f)


Closes NEXT-2020
Closes NEXT-1996
parent 1481b264
......@@ -121,6 +121,12 @@ export function getOriginalStackFrames(
)
}
function formatFrameSourceFile(file: string) {
return file
.replace(/^webpack-internal:(\/)+(\.)?/, '')
.replace(/^webpack:(\/)+(\.)?/, '')
}
export function getFrameSource(frame: StackFrame): string {
let str = ''
try {
......@@ -144,8 +150,9 @@ export function getFrameSource(frame: StackFrame): string {
// meaningful.
str += u.pathname
str += ' '
str = formatFrameSourceFile(str)
} catch {
str += (frame.file || '(unknown)') + ' '
str += formatFrameSourceFile(frame.file || '(unknown)') + ' '
}
if (frame.lineNumber != null) {
......
......@@ -76,5 +76,26 @@ createNextDescribe(
`Error: Invariant: cookies() expects to have requestAsyncStorage, none available.`
)
})
it('should show source code for jsx errors from server component', async () => {
await next.patchFile(
'app/server/page.js',
outdent`
export default function Page() {
return <div>{alert('warn')}</div>
}
`
)
const browser = await next.browser('/server')
await check(
async () => ((await hasRedbox(browser, true)) ? 'success' : 'fail'),
/success/
)
const errorDescription = await getRedboxDescription(browser)
expect(errorDescription).toContain(`Error: alert is not defined`)
})
}
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment