-
Notifications
You must be signed in to change notification settings - Fork 49k
[Flight] Parse Stack Trace from Structured CallSite if available #33135
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
Conversation
0c177dc
to
72bc9a6
Compare
78d60d9
to
f862175
Compare
Since we can only trigger prepareStackFrame once, it's important to cache this since the second time it gets accessed we won't be able to get to it.
f862175
to
dd0eaba
Compare
} | ||
// At the same time we generate a string stack trace just in case someone | ||
// else reads it. Ideally, we'd call the previous prepareStackTrace to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might have to call the previous one regardless in case the previous one is a custom one that also contains side-effects. Or do that in Next.js depending on the timing. The tricky bit is figuring how if that's the native one we want to avoid because it would be wasteful to call that.
return String(error.stack); | ||
} finally { | ||
Error.prepareStackTrace = previousPrepare; | ||
const identifierRegExp = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to test that? Asking because people already complain that our lint rules don't allow unicode characters in Component names so this may come up again here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to mirror what V8 does as much as possible so we get the same from parsing and not.
https://github.com/v8/v8/blob/main/src/objects/call-site-info.cc#L767
However, I didn't dig into what isIdentifier does since you get lost in codegen. I just saw others do this. Usually what I do is this:
) This is first step to include more enclosing line/column in the parsed data. We install our own `prepareStackTrace` to collect structured callsite data and only fall back to parsing the string if it was already evaluated or if `prepareStackTrace` doesn't work in this environment. We still mirror the default V8 format for encoding the function name part. A lot of this is covered by tests already. DiffTrain build for [0ff1d13](0ff1d13)
… fake function (#33136) Stacked on #33135. This encodes the line/column of the enclosing function as part of the stack traces. When that information is available. I adjusted the fake function code generation so that the beginning of the arrow function aligns with these as much as possible. This ensures that when the browser tries to look up the line/column of the enclosing function, such as for getting the function name, it gets the right one. If we can't get the enclosing line/column, then we encode it at the beginning of the file. This is likely to get a miss in the source map identifiers, which means that the function name gets extracted from the runtime name instead which is better. Another thing where this is used is the in the Performance Track. Ideally that would be fixed by https://issues.chromium.org/u/1/issues/415968771 but the enclosing information is useful for other things like the function name resolution anyway. We can also use this for the "View source for this element" in React DevTools.
… fake function (#33136) Stacked on #33135. This encodes the line/column of the enclosing function as part of the stack traces. When that information is available. I adjusted the fake function code generation so that the beginning of the arrow function aligns with these as much as possible. This ensures that when the browser tries to look up the line/column of the enclosing function, such as for getting the function name, it gets the right one. If we can't get the enclosing line/column, then we encode it at the beginning of the file. This is likely to get a miss in the source map identifiers, which means that the function name gets extracted from the runtime name instead which is better. Another thing where this is used is the in the Performance Track. Ideally that would be fixed by https://issues.chromium.org/u/1/issues/415968771 but the enclosing information is useful for other things like the function name resolution anyway. We can also use this for the "View source for this element" in React DevTools. DiffTrain build for [4a70286](4a70286)
This is first step to include more enclosing line/column in the parsed data.
We install our own
prepareStackTrace
to collect structured callsite data and only fall back to parsing the string if it was already evaluated or ifprepareStackTrace
doesn't work in this environment.We still mirror the default V8 format for encoding the function name part. A lot of this is covered by tests already.