Unverified Commit dd24033c authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

DX: hide the webpack info prefix for module paths (#62101)

### What

Hide the module file path webpack prefix for better visualization.
There're few types of webpack module prefixes 

- `wepack://`
- `wepack:///`
- `webpack://_N_E`
- `webpack-internal:///`

We're stripping them from the module path

### After vs Before
<img width="320"
src="https://github.com/vercel/next.js/assets/4800338/a9f5ae61-4fbf-42d7-b3e0-9bed1c7babb4">
<img width="420"
src="https://github.com/vercel/next.js/assets/4800338/ed6e120a-7c1c-4c31-be5d-9a1726d4e20c">


Closes NEXT-1966
Closes NEXT-1983
Closes NEXT-2504
parent 12639c48
......@@ -126,10 +126,18 @@ export function getOriginalStackFrames(
)
}
/**
* Format the webpack internal id to original file path
* webpack-internal:///./src/hello.tsx => ./src/hello.tsx
* webpack://_N_E/./src/hello.tsx => ./src/hello.tsx
* webpack://./src/hello.tsx => ./src/hello.tsx
* webpack:///./src/hello.tsx => ./src/hello.tsx
*
*/
function formatFrameSourceFile(file: string) {
return file
.replace(/^webpack-internal:\/\/\/(\.)?/, '')
.replace(/^webpack:\/\/\/(\.)?/, '')
.replace(/^webpack-internal:\/\/\/(\.)?(\((\w+)\))?/, '')
.replace(/^(webpack:\/\/\/(\.)?|webpack:\/\/(_N_E\/)?)(\((\w+)\))?/, '')
}
export function getFrameSource(frame: StackFrame): string {
......
......@@ -143,5 +143,26 @@ createNextDescribe(
await expect(versionText).not.toContain('(turbo)')
}
})
it('should not show the bundle layer info in the file trace', async () => {
await next.patchFile(
'app/server/page.js',
outdent`
export default function Page() {
throw new Error('test')
}
`
)
const browser = await next.browser('/server')
await retry(async () => {
expect(await hasRedbox(browser)).toBe(true)
})
const source = await getRedboxSource(browser)
expect(source).toContain('app/server/page.js')
expect(source).not.toContain('//app/server/page.js')
// Does not contain webpack traces in file path
expect(source).not.toMatch(/webpack(-internal:)?\/\//)
})
}
)
......@@ -156,9 +156,10 @@ createNextDescribe(
it('renders the error correctly and recovers', async () => {
const browser = await next.browser('/')
expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxSource(browser)).toContain(
`throw new Error('booooom!')`
)
const source = await getRedboxSource(browser)
expect(source).toContain(`throw new Error('booooom!')`)
expect(source).toContain('middleware.js')
expect(source).not.toContain('//middleware.js')
await next.patchFile('middleware.js', `export default function () {}`)
await hasRedbox(browser)
})
......
export default function () {
// placeholder for testing
}
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