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
Merged
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 @@ -475,7 +475,7 @@ describe('ReactDOM HostSingleton', () => {
expect(hydrationErrors).toEqual([
[
"Hydration failed because the server rendered HTML didn't match the client.",
'at div',
'at div (<anonymous>)',
],
]);
expect(persistentElements).toEqual([
Expand Down
2 changes: 1 addition & 1 deletion packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ function pushServerComponentStack(
let name = componentInfo.name;
const env = componentInfo.env;
if (env) {
name += ' (' + env + ')';
name += ' [' + env + ']';
}
task.componentStack = {
tag: 3,
Expand Down
14 changes: 12 additions & 2 deletions packages/shared/ReactComponentStackFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {disableLogs, reenableLogs} from 'shared/ConsolePatchingDev';
import ReactSharedInternals from 'shared/ReactSharedInternals';

let prefix;
let suffix;
export function describeBuiltInComponentFrame(name: string): string {
if (enableComponentStackLocations) {
if (prefix === undefined) {
Expand All @@ -33,17 +34,26 @@ export function describeBuiltInComponentFrame(name: string): string {
} catch (x) {
const match = x.stack.trim().match(/\n( *(at )?)/);
prefix = (match && match[1]) || '';
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.

: // 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.

: // Other
'';
}
}
// We use the prefix to ensure our stacks line up with native stack frames.
return '\n' + prefix + name;
return '\n' + prefix + name + suffix;
} 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 @.

}

let reentry = false;
Expand Down