From 3d9ed0480930a2dbbf5187bedfa65f0c684c01d9 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Mon, 2 Dec 2024 21:32:54 +0100 Subject: [PATCH] Fix cursor position --- .../react-dev-overlay/server/middleware-turbopack.ts | 9 +++++++-- .../app-dir/dynamic-error-trace/index.test.ts | 5 ++--- .../invalid-element-type.test.ts | 4 ++-- .../owner-stack-invalid-element-type.test.ts | 6 +++--- .../owner-stack-react-missing-key-prop.test.ts | 4 ++-- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/next/src/client/components/react-dev-overlay/server/middleware-turbopack.ts b/packages/next/src/client/components/react-dev-overlay/server/middleware-turbopack.ts index d645ecfb0232b..2358cb9e7cccc 100644 --- a/packages/next/src/client/components/react-dev-overlay/server/middleware-turbopack.ts +++ b/packages/next/src/client/components/react-dev-overlay/server/middleware-turbopack.ts @@ -229,8 +229,13 @@ async function nativeTraceSource( ?.replace('__WEBPACK_DEFAULT_EXPORT__', 'default') ?.replace('__webpack_exports__.', '') || '', - column: originalPosition.column ?? 0, - file: originalPosition.source, + column: (originalPosition.column ?? 0) + 1, + file: originalPosition.source?.startsWith('file://') + ? path.relative( + process.cwd(), + url.fileURLToPath(originalPosition.source) + ) + : originalPosition.source, lineNumber: originalPosition.line ?? 0, // TODO: c&p from async createOriginalStackFrame but why not frame.arguments? arguments: [], diff --git a/test/development/app-dir/dynamic-error-trace/index.test.ts b/test/development/app-dir/dynamic-error-trace/index.test.ts index 7208f5dcc521f..7c1cfad1bbc0f 100644 --- a/test/development/app-dir/dynamic-error-trace/index.test.ts +++ b/test/development/app-dir/dynamic-error-trace/index.test.ts @@ -41,16 +41,15 @@ describe('app dir - dynamic error trace', () => { ) const codeframe = await getRedboxSource(browser) - // TODO(NDX-115): column for "^"" marker is inconsistent between native, Webpack, and Turbopack expect(codeframe).toEqual( process.env.TURBOPACK ? outdent` - app/lib.js (4:12) @ Foo + app/lib.js (4:13) @ Foo 2 | 3 | export function Foo() { > 4 | useHeaders() - | ^ + | ^ 5 | return 'foo' 6 | } 7 | diff --git a/test/development/app-dir/owner-stack-invalid-element-type/invalid-element-type.test.ts b/test/development/app-dir/owner-stack-invalid-element-type/invalid-element-type.test.ts index 0368a1d958fae..2fb28f00c2eff 100644 --- a/test/development/app-dir/owner-stack-invalid-element-type/invalid-element-type.test.ts +++ b/test/development/app-dir/owner-stack-invalid-element-type/invalid-element-type.test.ts @@ -66,12 +66,12 @@ const isOwnerStackEnabled = if (process.env.TURBOPACK) { expect(stackFramesContent).toMatchInlineSnapshot(`""`) expect(source).toMatchInlineSnapshot(` - "app/rsc/page.js (5:10) @ Inner + "app/rsc/page.js (5:11) @ Inner 3 | // Intermediate component for testing owner stack 4 | function Inner() { > 5 | return - | ^ + | ^ 6 | } 7 | 8 | export default function Page() {" diff --git a/test/development/app-dir/owner-stack-invalid-element-type/owner-stack-invalid-element-type.test.ts b/test/development/app-dir/owner-stack-invalid-element-type/owner-stack-invalid-element-type.test.ts index 83778742851a2..5bd02766929b8 100644 --- a/test/development/app-dir/owner-stack-invalid-element-type/owner-stack-invalid-element-type.test.ts +++ b/test/development/app-dir/owner-stack-invalid-element-type/owner-stack-invalid-element-type.test.ts @@ -70,15 +70,15 @@ const isOwnerStackEnabled = if (process.env.TURBOPACK) { expect(stackFramesContent).toMatchInlineSnapshot( - `"at Page (app/rsc/page.js (11:7))"` + `"at Page (app/rsc/page.js (11:8))"` ) expect(source).toMatchInlineSnapshot(` - "app/rsc/page.js (5:10) @ Inner + "app/rsc/page.js (5:11) @ Inner 3 | // Intermediate component for testing owner stack 4 | function Inner() { > 5 | return - | ^ + | ^ 6 | } 7 | 8 | export default function Page() {" diff --git a/test/development/app-dir/owner-stack-react-missing-key-prop/owner-stack-react-missing-key-prop.test.ts b/test/development/app-dir/owner-stack-react-missing-key-prop/owner-stack-react-missing-key-prop.test.ts index 1edeb79382813..d2f4a84b29978 100644 --- a/test/development/app-dir/owner-stack-react-missing-key-prop/owner-stack-react-missing-key-prop.test.ts +++ b/test/development/app-dir/owner-stack-react-missing-key-prop/owner-stack-react-missing-key-prop.test.ts @@ -29,12 +29,12 @@ const isOwnerStackEnabled = `"at Page (app/rsc/page.tsx (6:13))"` ) expect(source).toMatchInlineSnapshot(` - "app/rsc/page.tsx (7:9) @ + "app/rsc/page.tsx (7:10) @ 5 |
6 | {list.map((item, index) => ( > 7 | {item} - | ^ + | ^ 8 | ))} 9 |
10 | )"