Skip to content

Turbopack: hide useless method names #73586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: sokra/module-factory-function-name
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
groupCodeFrameLines,
parseLineNumberFromCodeFrameLine,
} from './parse-code-frame'
import { isHiddenMethodName } from '../../../../../../shared/lib/stack-trace-utils'

export type CodeFrameProps = { stackFrame: StackFrame; codeFrame: string }

Expand Down Expand Up @@ -44,10 +45,14 @@ export function CodeFrame({ stackFrame, codeFrame }: CodeFrameProps) {
<span className="code-frame-icon">
<FileIcon lang={fileExtension} />
</span>
<span data-text>
{getFrameSource(stackFrame)} @{' '}
<HotlinkedText text={stackFrame.methodName} />
</span>
{isHiddenMethodName(stackFrame.methodName) ? (
<span data-text>{getFrameSource(stackFrame)}</span>
) : (
<span data-text>
{getFrameSource(stackFrame)} @{' '}
<HotlinkedText text={stackFrame.methodName} />
</span>
)}
<button
aria-label="Open in editor"
data-with-open-in-editor-link-source-file
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/server/patch-error-inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { parseStack } from '../client/components/react-dev-overlay/server/middle
import { getOriginalCodeFrame } from '../client/components/react-dev-overlay/server/shared'
import { workUnitAsyncStorage } from './app-render/work-unit-async-storage.external'
import { dim } from '../lib/picocolors'
import { isHiddenMethodName } from '../shared/lib/stack-trace-utils'

type FindSourceMapPayload = (
sourceURL: string
Expand Down Expand Up @@ -83,7 +84,7 @@ function frameToString(frame: StackFrame): string {
fileLocation = frame.file
}

return frame.methodName
return frame.methodName && !isHiddenMethodName(frame.methodName)
? ` at ${frame.methodName} (${fileLocation}${sourceLocation})`
: ` at ${fileLocation}${sourceLocation}`
}
Expand Down
6 changes: 6 additions & 0 deletions packages/next/src/shared/lib/stack-trace-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Hide the method name when showing a stack trace in the error overlay or when displaying a stack trace in the console.
export function isHiddenMethodName(methodName: string) {
return /^(?:Object\.|Module\.)?(?:<anonymous>|eval|__TURBOPACK__module__evaluation__)$/.test(
methodName
)
}
20 changes: 9 additions & 11 deletions test/development/acceptance-app/ReactRefreshLogBox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ describe('ReactRefreshLogBox app', () => {
"description": "Error: no",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (3:7) @ Module.
{module evaluation}
"source": "index.js (3:7)
> 3 | throw new Error('no')
| ^",
"stack": [
Expand All @@ -110,7 +109,7 @@ describe('ReactRefreshLogBox app', () => {
"description": "Error: no",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (3:7) @ eval
"source": "index.js (3:7)
> 3 | throw new Error('no')
| ^",
"stack": [
Expand All @@ -130,7 +129,7 @@ describe('ReactRefreshLogBox app', () => {
"description": "Error: no",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (3:7) @ eval
"source": "index.js (3:7)
> 3 | throw new Error('no')
| ^",
"stack": [
Expand Down Expand Up @@ -1208,7 +1207,7 @@ describe('ReactRefreshLogBox app', () => {
"description": "Error: This is an error from an anonymous function",
"environmentLabel": "Server",
"label": "Runtime Error",
"source": "app/page.js (4:13) @ <anonymous>
"source": "app/page.js (4:13)
> 4 | throw new Error("This is an error from an anonymous function");
| ^",
"stack": [
Expand All @@ -1223,7 +1222,7 @@ describe('ReactRefreshLogBox app', () => {
"description": "Error: This is an error from an anonymous function",
"environmentLabel": "Server",
"label": "Runtime Error",
"source": "app/page.js (4:13) @ eval
"source": "app/page.js (4:13)
> 4 | throw new Error("This is an error from an anonymous function");
| ^",
"stack": [
Expand Down Expand Up @@ -1527,7 +1526,7 @@ describe('ReactRefreshLogBox app', () => {
"description": "Error: module error",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (1:7) @ eval
"source": "index.js (1:7)
> 1 | throw new Error('module error')
| ^",
"stack": [
Expand Down Expand Up @@ -1679,8 +1678,7 @@ export default function Home() {
"description": "Error: utils error",
"environmentLabel": null,
"label": "Runtime Error",
"source": "app/utils.ts (1:7) @ Module.
{module evaluation}
"source": "app/utils.ts (1:7)
> 1 | throw new Error('utils error')
| ^",
"stack": [
Expand All @@ -1697,7 +1695,7 @@ export default function Home() {
"description": "Error: utils error",
"environmentLabel": null,
"label": "Runtime Error",
"source": "app/utils.ts (1:7) @ eval
"source": "app/utils.ts (1:7)
> 1 | throw new Error('utils error')
| ^",
"stack": [
Expand All @@ -1717,7 +1715,7 @@ export default function Home() {
"description": "Error: utils error",
"environmentLabel": null,
"label": "Runtime Error",
"source": "app/utils.ts (1:7) @ eval
"source": "app/utils.ts (1:7)
> 1 | throw new Error('utils error')
| ^",
"stack": [
Expand Down
2 changes: 1 addition & 1 deletion test/development/acceptance-app/error-recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ describe('Error recovery app', () => {
"description": "Error: no 1",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (7:11) @ eval
"source": "index.js (7:11)
> 7 | throw Error('no ' + i)
| ^",
"stack": [
Expand Down
6 changes: 3 additions & 3 deletions test/development/acceptance/ReactRefreshLogBox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('ReactRefreshLogBox', () => {
"description": "Error: no",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (3:7) @ eval
"source": "index.js (3:7)
> 3 | throw new Error('no')
| ^",
"stack": [
Expand Down Expand Up @@ -189,7 +189,7 @@ describe('ReactRefreshLogBox', () => {
"description": "Error: no",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (3:7) @ eval
"source": "index.js (3:7)
> 3 | throw new Error('no')
| ^",
"stack": [
Expand Down Expand Up @@ -1249,7 +1249,7 @@ describe('ReactRefreshLogBox', () => {
"description": "Error: anonymous error!",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/index.js (3:11) @ eval
"source": "pages/index.js (3:11)
> 3 | throw new Error("anonymous error!");
| ^",
"stack": [
Expand Down
2 changes: 1 addition & 1 deletion test/development/acceptance/error-recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ describe('pages/ error recovery', () => {
"description": "Error: no 1",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (5:9) @ eval
"source": "index.js (5:9)
> 5 | throw Error('no ' + i)
| ^",
"stack": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('app-dir - owner-stack-react-missing-key-prop', () => {
at Page (app/rsc/page.tsx (6:13))"
`)
expect(source).toMatchInlineSnapshot(`
"app/rsc/page.tsx (7:9) @ <anonymous>
"app/rsc/page.tsx (7:9)

5 | <div>
6 | {list.map((item, index) => (
Expand All @@ -41,7 +41,7 @@ describe('app-dir - owner-stack-react-missing-key-prop', () => {
at Page (app/rsc/page.tsx (6:13))"
`)
expect(source).toMatchInlineSnapshot(`
"app/rsc/page.tsx (7:9) @ eval
"app/rsc/page.tsx (7:9)

5 | <div>
6 | {list.map((item, index) => (
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('app-dir - owner-stack-react-missing-key-prop', () => {
at Page (app/ssr/page.tsx (8:13))"
`)
expect(source).toMatchInlineSnapshot(`
"app/ssr/page.tsx (9:9) @ eval
"app/ssr/page.tsx (9:9)

7 | <div>
8 | {list.map((item, index) => (
Expand Down
28 changes: 12 additions & 16 deletions test/development/app-dir/ssr-in-rsc/ssr-in-rsc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ describe('react-dom/server in React Server environment', () => {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "TypeError: Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": "app/exports/app-code/react-dom-server-node-explicit/page.js (1:1) @ Object.{module evaluation}
"source": "app/exports/app-code/react-dom-server-node-explicit/page.js (1:1)

> 1 | import * as ReactDOMServerNode from 'react-dom/server.node'
| ^
Expand All @@ -334,10 +334,9 @@ describe('react-dom/server in React Server environment', () => {
`)
} else {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "Error: react-dom/server is not supported in React Server Components.",
"source": "app/exports/app-code/react-dom-server-node-explicit/page.js (1:1) @ Module.
{module evaluation}
{
"description": "Error: react-dom/server is not supported in React Server Components.",
"source": "app/exports/app-code/react-dom-server-node-explicit/page.js (1:1)

> 1 | import * as ReactDOMServerNode from 'react-dom/server.node'
| ^
Expand Down Expand Up @@ -437,7 +436,7 @@ describe('react-dom/server in React Server environment', () => {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "TypeError: Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": "internal-pkg/server.node.js (1:1) @ Object.{module evaluation}
"source": "internal-pkg/server.node.js (1:1)

> 1 | import * as ReactDOMServerEdge from 'react-dom/server.node'
| ^
Expand All @@ -448,10 +447,9 @@ describe('react-dom/server in React Server environment', () => {
`)
} else {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "Error: react-dom/server is not supported in React Server Components.",
"source": "internal-pkg/server.node.js (1:1) @ Module.
{module evaluation}
{
"description": "Error: react-dom/server is not supported in React Server Components.",
"source": "internal-pkg/server.node.js (1:1)

> 1 | import * as ReactDOMServerEdge from 'react-dom/server.node'
| ^
Expand Down Expand Up @@ -736,7 +734,7 @@ describe('react-dom/server in React Server environment', () => {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "TypeError: Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": "internal-pkg/server.node.js (1:1) @ Object.{module evaluation}
"source": "internal-pkg/server.node.js (1:1)

> 1 | import * as ReactDOMServerEdge from 'react-dom/server.node'
| ^
Expand All @@ -749,8 +747,7 @@ describe('react-dom/server in React Server environment', () => {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "Error: react-dom/server is not supported in React Server Components.",
"source": "internal-pkg/server.node.js (1:1) @ Module.
{module evaluation}
"source": "internal-pkg/server.node.js (1:1)

> 1 | import * as ReactDOMServerEdge from 'react-dom/server.node'
| ^
Expand Down Expand Up @@ -795,7 +792,7 @@ describe('react-dom/server in React Server environment', () => {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "TypeError: Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": "internal-pkg/server.node.js (1:1) @ Object.{module evaluation}
"source": "internal-pkg/server.node.js (1:1)

> 1 | import * as ReactDOMServerEdge from 'react-dom/server.node'
| ^
Expand All @@ -808,8 +805,7 @@ describe('react-dom/server in React Server environment', () => {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "Error: react-dom/server is not supported in React Server Components.",
"source": "internal-pkg/server.node.js (1:1) @ Module.
{module evaluation}
"source": "internal-pkg/server.node.js (1:1)

> 1 | import * as ReactDOMServerEdge from 'react-dom/server.node'
| ^
Expand Down
19 changes: 9 additions & 10 deletions test/development/middleware-errors/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ describe('middleware - development errors', () => {
expect(stripAnsi(next.cliOutput)).toContain(
isTurbopack
? '\n ⨯ Error [ReferenceError]: test is not defined' +
'\n at eval (middleware.js:4:8)' +
'\n at middleware.js:4:8' +
'\n at <unknown> (middleware.js:4:8)' +
// TODO(veil): Should be sourcemapped
'\n at __TURBOPACK__default__export__ ('
: '\n ⨯ Error [ReferenceError]: test is not defined' +
// TODO(veil): Redundant and not clickable
'\n at eval (file://webpack-internal:///(middleware)/./middleware.js)' +
'\n at eval (middleware.js:4:8)' +
'\n at file://webpack-internal:///(middleware)/./middleware.js' +
'\n at middleware.js:4:8' +
'\n at default (middleware.js:4:8)' +
"\n 2 | import { NextResponse } from 'next/server'"
)
Expand All @@ -205,7 +205,7 @@ describe('middleware - development errors', () => {
"description": "ReferenceError: test is not defined",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.js (4:9) @ eval
"source": "middleware.js (4:9)
> 4 | eval('test')
| ^",
"stack": [
Expand All @@ -221,7 +221,7 @@ describe('middleware - development errors', () => {
"description": "ReferenceError: test is not defined",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.js (4:9) @ eval
"source": "middleware.js (4:9)
> 4 | eval('test')
| ^",
"stack": [
Expand Down Expand Up @@ -268,12 +268,12 @@ describe('middleware - development errors', () => {
isTurbopack
? '\n ⨯ Error: booooom!' +
// TODO(veil): Should be sourcemapped
'\n at Module.__TURBOPACK__module__evaluation__ (middleware.js:3:12)'
'\n at middleware.js:3:12'
: '\n ⨯ Error: booooom!' +
// TODO: Should be anonymous method without a method name
'\n at <unknown> (middleware.js:3)' +
// TODO: Should be ignore-listed
'\n at eval (middleware.js:3:12)' +
'\n at middleware.js:3:12' +
'\n at (middleware)/./middleware.js (.next/server/middleware.js:18:1)' +
'\n at __webpack_require__ '
)
Expand All @@ -288,8 +288,7 @@ describe('middleware - development errors', () => {
"description": "Error: booooom!",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.js (3:13) @ Module.
{module evaluation}
"source": "middleware.js (3:13)
> 3 | throw new Error('booooom!')
| ^",
"stack": [
Expand All @@ -303,7 +302,7 @@ describe('middleware - development errors', () => {
"description": "Error: booooom!",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.js (3:13) @ eval
"source": "middleware.js (3:13)
> 3 | throw new Error('booooom!')
| ^",
"stack": [
Expand Down
2 changes: 1 addition & 1 deletion test/development/pages-dir/client-navigation/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ describe('Client Navigation', () => {
"description": "Error: An Expected error occurred",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/error-in-the-browser-global-scope.js (2:9) @ eval
"source": "pages/error-in-the-browser-global-scope.js (2:9)
> 2 | throw new Error('An Expected error occurred')
| ^",
"stack": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ describe('Client Navigation rendering', () => {
"description": "ReferenceError: aa is not defined",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/error-in-the-global-scope.js (1:1) @ eval
"source": "pages/error-in-the-global-scope.js (1:1)
> 1 | aa = 10 //eslint-disable-line
| ^",
"stack": [
Expand Down
Loading
Loading