Skip to content

Commit 2ac7976

Browse files
committed
Explain why the ConsoleTask is incomplete
1 parent 4334b7e commit 2ac7976

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

packages/react-server/src/ReactFizzThenable.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ function captureSuspendedCallSite(): void {
207207
owner: currentComponentStack.owner,
208208
stack: Error('react-stack-top-frame'),
209209
};
210+
// TODO: If this is used in error handlers, the ConsoleTask stack
211+
// will just be this debugTask + the stack of the abort() call which usually means
212+
// it's just this debugTask.
213+
// Ideally we'd be able to reconstruct the owner ConsoleTask as well.
214+
// The stack of the debugTask would not point to the suspend location anyway.
215+
// The focus is really on callsite which should be used in captureOwnerStack().
210216
suspendedCallSiteDebugTask = currentTask.debugTask;
211217
}
212218
export function getSuspendedCallSiteStackDEV(): ComponentStackNode | null {

packages/react-server/src/__tests__/ReactServer-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
'use strict';
12+
import {AsyncLocalStorage} from 'node:async_hooks';
1213

1314
let act;
1415
let React;
@@ -39,10 +40,21 @@ function normalizeCodeLocInfo(str) {
3940
);
4041
}
4142

43+
const currentTask = new AsyncLocalStorage({defaultValue: null});
44+
4245
describe('ReactServer', () => {
4346
beforeEach(() => {
4447
jest.resetModules();
4548

49+
console.createTask = jest.fn(taskName => {
50+
return {
51+
run: taskFn => {
52+
const parentTask = currentTask.getStore() || '';
53+
return currentTask.run(parentTask + '\n' + taskName, taskFn);
54+
},
55+
};
56+
});
57+
4658
act = require('internal-test-utils').act;
4759
React = require('react');
4860
ReactNoopServer = require('react-noop-renderer/server');
@@ -91,6 +103,7 @@ describe('ReactServer', () => {
91103
let caughtError;
92104
let componentStack;
93105
let ownerStack;
106+
let task;
94107
const result = ReactNoopServer.render(
95108
<Context value="provided">
96109
<App promise={new Promise(() => {})} />
@@ -100,6 +113,7 @@ describe('ReactServer', () => {
100113
caughtError = error;
101114
componentStack = errorInfo.componentStack;
102115
ownerStack = __DEV__ ? React.captureOwnerStack() : null;
116+
task = currentTask.getStore();
103117
},
104118
},
105119
);
@@ -128,5 +142,6 @@ describe('ReactServer', () => {
128142
'\n in App (at **)'
129143
: null,
130144
);
145+
expect(task).toEqual(__DEV__ ? '\n<Component>' : null);
131146
});
132147
});

0 commit comments

Comments
 (0)