Skip to content
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

Add unknown location information to component stacks #30290

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

sebmarkbage
Copy link
Collaborator

This is the same change as in #30289 but for the main runtime - e.g. parent stacks in errorInfo.componentStack, appended stacks to console.error coming from React itself and when we add virtual frames to owner stacks.

Since we don't add location information these frames look weird to some stack parsers - such as the native one. This is an existing issue when you want to use some off-the-shelf parsers to parse production component stacks for example.

While we won't add Error objects to logs ourselves necessarily, some third party could want to do the same thing we do in DevTools and so we should provide the same capability to just take this trace and print it using an Error object.

@sebmarkbage sebmarkbage requested a review from hoxyq July 7, 2024 17:16
Copy link

vercel bot commented Jul 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 7, 2024 10:58pm

suffix =
x.stack.indexOf('\n at') > -1
? // V8
' (<anonymous>)'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least in Chrome DevTools this is a hardcoded special value that means this doesn't have a location.

' (<anonymous>)'
: // JSC/Spidermonkey
x.stack.indexOf('@') > -1
? '@unknown:0:0'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can really be anything include empty '@' but then Firefox can still present it as :0 which is maybe confusing. So the string unknown is just used here to communicate that we don't know the location.

} else {
return describeComponentFrame(name);
}
}

export function describeDebugInfoFrame(name: string, env: ?string): string {
return describeBuiltInComponentFrame(name + (env ? ' (' + env + ')' : ''));
return describeBuiltInComponentFrame(name + (env ? ' [' + env + ']' : ''));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my original reasoning for parenthesis #28415 (comment)

However, after further research it seems like e.g. (native) is no longer used by V8 and the only non-location is (<anonymous>) so this pattern doesn't follow and it actually gets parsed as if it's a real location.

Meanwhile brackets doesn't seem to have any meaning in any format as far as I can tell from further research so just becomes a name.

All formats are ambiguous when the actual name contains meaningful punctuations like ( or @.

@sebmarkbage sebmarkbage merged commit df783f9 into facebook:main Jul 8, 2024
139 checks passed
github-actions bot pushed a commit that referenced this pull request Jul 8, 2024
This is the same change as in #30289 but for the main runtime - e.g.
parent stacks in errorInfo.componentStack, appended stacks to
console.error coming from React itself and when we add virtual frames to
owner stacks.

Since we don't add location information these frames look weird to some
stack parsers - such as the native one. This is an existing issue when
you want to use some off-the-shelf parsers to parse production component
stacks for example.

While we won't add Error objects to logs ourselves necessarily, some
third party could want to do the same thing we do in DevTools and so we
should provide the same capability to just take this trace and print it
using an Error object.

DiffTrain build for [df783f9](df783f9)
github-actions bot pushed a commit that referenced this pull request Jul 8, 2024
This is the same change as in #30289 but for the main runtime - e.g.
parent stacks in errorInfo.componentStack, appended stacks to
console.error coming from React itself and when we add virtual frames to
owner stacks.

Since we don't add location information these frames look weird to some
stack parsers - such as the native one. This is an existing issue when
you want to use some off-the-shelf parsers to parse production component
stacks for example.

While we won't add Error objects to logs ourselves necessarily, some
third party could want to do the same thing we do in DevTools and so we
should provide the same capability to just take this trace and print it
using an Error object.

DiffTrain build for commit df783f9.
huozhi added a commit to vercel/next.js that referenced this pull request Jul 9, 2024
### What

Change the display of error trace in error overlay. 

* Replace unknown location `<anonymous>` from the stack trace but still
keep the content before the location.
* Filter out all `node:` prefixes (including node:async_hooks etc.)



### Why

Regarding to the chaneg in facebook/react#30290

We only stripped the `(<anonymous>)` part but still keep the first part
of stack trace, e.g. in react it could be the component name.

cc @sebmarkbage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants