Skip to content

Commit da8de9e

Browse files
committed
Enable sync stack traces for errors and console replay
1 parent 6c4bbc7 commit da8de9e

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
enableRefAsProp,
4747
enableFlightReadableStream,
4848
enableOwnerStacks,
49+
enableServerComponentLogs,
4950
} from 'shared/ReactFeatureFlags';
5051

5152
import {
@@ -1928,7 +1929,7 @@ function resolveErrorDev(
19281929
}
19291930

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

2466-
if (!enableOwnerStacks) {
2467-
// Printing with stack isn't really limited to owner stacks but
2468-
// we gate it behind the same flag for now while iterating.
2467+
if (!enableOwnerStacks && !enableServerComponentLogs) {
24692468
bindToConsole(methodName, args, env)();
24702469
return;
24712470
}

packages/react-client/src/__tests__/ReactFlight-test.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,10 @@ describe('ReactFlight', () => {
13461346
errors: [
13471347
{
13481348
message: 'This is an error',
1349-
stack: gate(flags => flags.enableOwnerStacks)
1349+
stack: gate(
1350+
flags =>
1351+
flags.enableOwnerStacks || flags.enableServerComponentLogs,
1352+
)
13501353
? expect.stringContaining(
13511354
'Error: This is an error\n' +
13521355
' at eval (eval at testFunction (eval at createFakeFunction (**), <anonymous>:1:35)\n' +
@@ -1378,7 +1381,17 @@ describe('ReactFlight', () => {
13781381
['file:///testing.js', 'Server'],
13791382
[__filename, 'Server'],
13801383
]
1381-
: [],
1384+
: gate(flags => flags.enableServerComponentLogs)
1385+
? [
1386+
// TODO: What should we request here? The outer (<anonymous>) or the inner (inspected-page.html)?
1387+
['inspected-page.html:29:11), <anonymous>', 'Server'],
1388+
[
1389+
'file://~/(some)(really)(exotic-directory)/ReactFlight-test.js',
1390+
'Server',
1391+
],
1392+
['file:///testing.js', 'Server'],
1393+
]
1394+
: [],
13821395
});
13831396
} else {
13841397
expect(errors.map(getErrorForJestMatcher)).toEqual([
@@ -2940,7 +2953,11 @@ describe('ReactFlight', () => {
29402953
.join('\n')
29412954
.replaceAll(
29422955
' (/',
2943-
gate(flags => flags.enableOwnerStacks) ? ' (file:///' : ' (/',
2956+
gate(
2957+
flags => flags.enableOwnerStacks || flags.enableServerComponentLogs,
2958+
)
2959+
? ' (file:///'
2960+
: ' (/',
29442961
); // The eval will end up normalizing these
29452962

29462963
let sawReactPrefix = false;
@@ -2974,6 +2991,12 @@ describe('ReactFlight', () => {
29742991
'third-party',
29752992
'third-party',
29762993
]);
2994+
} else if (__DEV__ && gate(flags => flags.enableServerComponentLogs)) {
2995+
expect(environments.slice(0, 3)).toEqual([
2996+
'third-party',
2997+
'third-party',
2998+
'third-party',
2999+
]);
29773000
} else {
29783001
expect(environments).toEqual([]);
29793002
}

0 commit comments

Comments
 (0)