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

[Flight] Enable sync stack traces for errors and console replay #31270

Merged
merged 1 commit into from
Oct 16, 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
7 changes: 3 additions & 4 deletions packages/react-client/src/ReactFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
enableRefAsProp,
enableFlightReadableStream,
enableOwnerStacks,
enableServerComponentLogs,
} from 'shared/ReactFeatureFlags';

import {
Expand Down Expand Up @@ -1928,7 +1929,7 @@ function resolveErrorDev(
}

let error;
if (!enableOwnerStacks) {
if (!enableOwnerStacks && !enableServerComponentLogs) {
// Executing Error within a native stack isn't really limited to owner stacks
// but we gate it behind the same flag for now while iterating.
// eslint-disable-next-line react-internal/prod-error-codes
Expand Down Expand Up @@ -2463,9 +2464,7 @@ function resolveConsoleEntry(
const env = payload[3];
const args = payload.slice(4);

if (!enableOwnerStacks) {
// Printing with stack isn't really limited to owner stacks but
// we gate it behind the same flag for now while iterating.
if (!enableOwnerStacks && !enableServerComponentLogs) {
bindToConsole(methodName, args, env)();
return;
}
Expand Down
29 changes: 26 additions & 3 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,10 @@ describe('ReactFlight', () => {
errors: [
{
message: 'This is an error',
stack: gate(flags => flags.enableOwnerStacks)
stack: gate(
flags =>
flags.enableOwnerStacks || flags.enableServerComponentLogs,
)
? expect.stringContaining(
'Error: This is an error\n' +
' at eval (eval at testFunction (eval at createFakeFunction (**), <anonymous>:1:35)\n' +
Expand Down Expand Up @@ -1378,7 +1381,17 @@ describe('ReactFlight', () => {
['file:///testing.js', 'Server'],
[__filename, 'Server'],
]
: [],
: gate(flags => flags.enableServerComponentLogs)
? [
// TODO: What should we request here? The outer (<anonymous>) or the inner (inspected-page.html)?
['inspected-page.html:29:11), <anonymous>', 'Server'],
[
'file://~/(some)(really)(exotic-directory)/ReactFlight-test.js',
'Server',
],
['file:///testing.js', 'Server'],
]
: [],
});
} else {
expect(errors.map(getErrorForJestMatcher)).toEqual([
Expand Down Expand Up @@ -2940,7 +2953,11 @@ describe('ReactFlight', () => {
.join('\n')
.replaceAll(
' (/',
gate(flags => flags.enableOwnerStacks) ? ' (file:///' : ' (/',
gate(
flags => flags.enableOwnerStacks || flags.enableServerComponentLogs,
)
? ' (file:///'
: ' (/',
); // The eval will end up normalizing these

let sawReactPrefix = false;
Expand Down Expand Up @@ -2974,6 +2991,12 @@ describe('ReactFlight', () => {
'third-party',
'third-party',
]);
} else if (__DEV__ && gate(flags => flags.enableServerComponentLogs)) {
expect(environments.slice(0, 3)).toEqual([
'third-party',
'third-party',
'third-party',
]);
} else {
expect(environments).toEqual([]);
}
Expand Down
Loading