Unverified Commit e114229d authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Same as #61360 (#61369)

## What?

Same PR as #61360, somehow that branch could not be checked out / wasn't
available in git.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->


Closes NEXT-2295

---------
Co-authored-by: 's avatarWill Binns-Smith <wbinnssmith@gmail.com>
parent 292cd0d3
...@@ -30,12 +30,14 @@ use turbopack_binding::{ ...@@ -30,12 +30,14 @@ use turbopack_binding::{
}, },
turbopack::{ turbopack::{
core::{ core::{
chunk::ModuleId,
diagnostics::PlainDiagnostic, diagnostics::PlainDiagnostic,
error::PrettyPrintError, error::PrettyPrintError,
issue::PlainIssue, issue::PlainIssue,
source_map::{GenerateSourceMap, Token}, source_map::{GenerateSourceMap, Token},
version::{PartialUpdate, TotalUpdate, Update, VersionState}, version::{PartialUpdate, TotalUpdate, Update, VersionState},
}, },
dev::ecmascript::EcmascriptDevChunkContent,
ecmascript_hmr_protocol::{ClientUpdateInstruction, ResourceIdentifier}, ecmascript_hmr_protocol::{ClientUpdateInstruction, ResourceIdentifier},
trace_utils::{ trace_utils::{
exit::ExitGuard, exit::ExitGuard,
...@@ -804,12 +806,16 @@ pub async fn project_trace_source( ...@@ -804,12 +806,16 @@ pub async fn project_trace_source(
let turbo_tasks = project.turbo_tasks.clone(); let turbo_tasks = project.turbo_tasks.clone();
let traced_frame = turbo_tasks let traced_frame = turbo_tasks
.run_once(async move { .run_once(async move {
let file = match Url::parse(&frame.file) { let (file, module) = match Url::parse(&frame.file) {
Ok(url) => match url.scheme() { Ok(url) => match url.scheme() {
"file" => urlencoding::decode(url.path())?.to_string(), "file" => {
let path = urlencoding::decode(url.path())?.to_string();
let module = url.query_pairs().find(|(k, _)| k == "id");
(path, module.map(|(_, m)| m.into_owned()))
}
_ => bail!("Unknown url scheme"), _ => bail!("Unknown url scheme"),
}, },
Err(_) => frame.file.to_string(), Err(_) => (frame.file.to_string(), None),
}; };
let Some(chunk_base) = file.strip_prefix( let Some(chunk_base) = file.strip_prefix(
...@@ -837,19 +843,38 @@ pub async fn project_trace_source( ...@@ -837,19 +843,38 @@ pub async fn project_trace_source(
.join(chunk_base.to_owned()) .join(chunk_base.to_owned())
}; };
let Some(versioned) = Vc::try_resolve_sidecast::<Box<dyn GenerateSourceMap>>( let content_vc = project.container.get_versioned_content(path);
project.container.get_versioned_content(path), let map = match module {
) Some(module) => {
.await? let Some(content) =
else { Vc::try_resolve_downcast_type::<EcmascriptDevChunkContent>(content_vc)
bail!("Could not GenerateSourceMap") .await?
else {
bail!("Was not EcmascriptDevChunkContent")
};
let entries = content.entries().await?;
let entry = entries.get(&ModuleId::String(module).cell().await?);
let map = match entry {
Some(entry) => *entry.code.generate_source_map().await?,
None => None,
};
map.context("Entry is missing sourcemap")?
}
None => {
let Some(versioned) =
Vc::try_resolve_sidecast::<Box<dyn GenerateSourceMap>>(content_vc).await?
else {
bail!("Could not GenerateSourceMap")
};
versioned
.generate_source_map()
.await?
.context("Chunk is missing a sourcemap")?
}
}; };
let map = versioned
.generate_source_map()
.await?
.context("Chunk is missing a sourcemap")?;
let token = map let token = map
.lookup_token(frame.line as usize, frame.column.unwrap_or(0) as usize) .lookup_token(frame.line as usize, frame.column.unwrap_or(0) as usize)
.await? .await?
......
...@@ -14,7 +14,7 @@ export function parseStack(stack: string): StackFrame[] { ...@@ -14,7 +14,7 @@ export function parseStack(stack: string): StackFrame[] {
?.replace(/\\/g, '/') ?.replace(/\\/g, '/')
?.replace(/\/$/, '') ?.replace(/\/$/, '')
if (distDir) { if (distDir) {
frame.file = 'file://' + distDir.concat(res.pop()!) frame.file = 'file://' + distDir.concat(res.pop()!) + url.search
} }
} }
} catch {} } catch {}
......
...@@ -118,17 +118,19 @@ https://nextjs.org/docs/messages/module-not-found" ...@@ -118,17 +118,19 @@ https://nextjs.org/docs/messages/module-not-found"
`; `;
exports[`ReactRefreshLogBox app turbo Should not show __webpack_exports__ when exporting anonymous arrow function 1`] = ` exports[`ReactRefreshLogBox app turbo Should not show __webpack_exports__ when exporting anonymous arrow function 1`] = `
"index.js (1:13) @ __TURBOPACK__default__export__ "index.js (3:2) @ __TURBOPACK__default__export__
> 1 | export default () => { 1 | export default () => {
| ^
2 | if (typeof window !== 'undefined') { 2 | if (typeof window !== 'undefined') {
3 | throw new Error('test') > 3 | throw new Error('test')
4 | }" | ^
4 | }
5 |
6 | return null"
`; `;
exports[`ReactRefreshLogBox app turbo boundaries 1`] = ` exports[`ReactRefreshLogBox app turbo boundaries 1`] = `
"FunctionDefault.js (0:24) @ FunctionDefault "FunctionDefault.js (0:67) @ FunctionDefault
1 | export default function FunctionDefault() { throw new Error('no'); }" 1 | export default function FunctionDefault() { throw new Error('no'); }"
`; `;
...@@ -162,13 +164,13 @@ exports[`ReactRefreshLogBox app turbo module init error not shown 1`] = ` ...@@ -162,13 +164,13 @@ exports[`ReactRefreshLogBox app turbo module init error not shown 1`] = `
`; `;
exports[`ReactRefreshLogBox app turbo should strip whitespace correctly with newline 1`] = ` exports[`ReactRefreshLogBox app turbo should strip whitespace correctly with newline 1`] = `
"index.js (5:18) @ onClick "index.js (7:6) @ onClick
3 | <> 5 |
4 | <p>index page</p> 6 | <a onClick={() => {
> 5 | > 7 | throw new Error('idk')
| ^ | ^
6 | <a onClick={() => { 8 | }}>
7 | throw new Error('idk') 9 | click me
8 | }}>" 10 | </a>"
`; `;
...@@ -6,7 +6,7 @@ import path from 'path' ...@@ -6,7 +6,7 @@ import path from 'path'
import { outdent } from 'outdent' import { outdent } from 'outdent'
describe.each(['default', 'turbo'])('Error recovery app %s', () => { describe.each(['default', 'turbo'])('Error recovery app %s', () => {
const { next } = nextTestSetup({ const { next, isTurbopack } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')), files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: { dependencies: {
react: 'latest', react: 'latest',
...@@ -143,17 +143,32 @@ describe.each(['default', 'turbo'])('Error recovery app %s', () => { ...@@ -143,17 +143,32 @@ describe.each(['default', 'turbo'])('Error recovery app %s', () => {
).toBe('1') ).toBe('1')
await session.waitForAndOpenRuntimeError() await session.waitForAndOpenRuntimeError()
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"index.js (7:10) @ eval if (isTurbopack) {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
5 | const increment = useCallback(() => { "index.js (7:5) @ eval
6 | setCount(c => c + 1)
> 7 | throw new Error('oops') 5 | const increment = useCallback(() => {
| ^ 6 | setCount(c => c + 1)
8 | }, [setCount]) > 7 | throw new Error('oops')
9 | return ( | ^
10 | <main>" 8 | }, [setCount])
`) 9 | return (
10 | <main>"
`)
} else {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"index.js (7:10) @ eval
5 | const increment = useCallback(() => {
6 | setCount(c => c + 1)
> 7 | throw new Error('oops')
| ^
8 | }, [setCount])
9 | return (
10 | <main>"
`)
}
await session.patch( await session.patch(
'index.js', 'index.js',
......
...@@ -1084,6 +1084,7 @@ ...@@ -1084,6 +1084,7 @@
}, },
"test/development/acceptance-app/error-recovery.test.ts": { "test/development/acceptance-app/error-recovery.test.ts": {
"passed": [ "passed": [
"Error recovery app turbo can recover from a event handler error",
"Error recovery app turbo can recover from a syntax error without losing state", "Error recovery app turbo can recover from a syntax error without losing state",
"Error recovery app turbo client component can recover from a component error", "Error recovery app turbo client component can recover from a component error",
"Error recovery app turbo displays build error on initial page load", "Error recovery app turbo displays build error on initial page load",
...@@ -1092,7 +1093,6 @@ ...@@ -1092,7 +1093,6 @@
"Error recovery app turbo syntax > runtime error" "Error recovery app turbo syntax > runtime error"
], ],
"failed": [ "failed": [
"Error recovery app turbo can recover from a event handler error",
"Error recovery app turbo client component can recover from syntax error", "Error recovery app turbo client component can recover from syntax error",
"Error recovery app turbo server component can recover from a component error", "Error recovery app turbo server component can recover from a component error",
"Error recovery app turbo stuck error" "Error recovery app turbo stuck error"
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