Skip to content

Commit 1fa57c6

Browse files
committed
[Fizz] Add Owner Stacks when render is aborted
1 parent bed4a73 commit 1fa57c6

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

packages/react-server/src/ReactFizzServer.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4762,6 +4762,27 @@ function abortTask(task: Task, request: Request, error: mixed): void {
47624762
}
47634763
}
47644764

4765+
function abortTaskDEV(task: Task, request: Request, error: mixed): void {
4766+
if (__DEV__) {
4767+
const prevTaskInDEV = currentTaskInDEV;
4768+
const prevGetCurrentStackImpl = ReactSharedInternals.getCurrentStack;
4769+
setCurrentTaskInDEV(task);
4770+
ReactSharedInternals.getCurrentStack = getCurrentStackInDEV;
4771+
try {
4772+
abortTask(task, request, error);
4773+
} finally {
4774+
setCurrentTaskInDEV(prevTaskInDEV);
4775+
ReactSharedInternals.getCurrentStack = prevGetCurrentStackImpl;
4776+
}
4777+
} else {
4778+
// These errors should never make it into a build so we don't need to encode them in codes.json
4779+
// eslint-disable-next-line react-internal/prod-error-codes
4780+
throw new Error(
4781+
'abortTaskDEV should never be called in production mode. This is a bug in React.',
4782+
);
4783+
}
4784+
}
4785+
47654786
function safelyEmitEarlyPreloads(
47664787
request: Request,
47674788
shellComplete: boolean,
@@ -6111,7 +6132,11 @@ export function abort(request: Request, reason: mixed): void {
61116132
// This error isn't necessarily fatal in this case but we need to stash it
61126133
// so we can use it to abort any pending work
61136134
request.fatalError = error;
6114-
abortableTasks.forEach(task => abortTask(task, request, error));
6135+
if (__DEV__) {
6136+
abortableTasks.forEach(task => abortTaskDEV(task, request, error));
6137+
} else {
6138+
abortableTasks.forEach(task => abortTask(task, request, error));
6139+
}
61156140
abortableTasks.clear();
61166141
}
61176142
if (request.destination !== null) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ describe('ReactServer', () => {
8282
expect(normalizeCodeLocInfo(componentStack)).toEqual(
8383
'\n in Component (at **)' + '\n in App (at **)',
8484
);
85-
// FIXME: Should have a stack.
86-
expect(normalizeCodeLocInfo(ownerStack)).toEqual(null);
85+
expect(normalizeCodeLocInfo(ownerStack)).toEqual(
86+
__DEV__ ? '\n in App (at **)' : null,
87+
);
8788
});
8889
});

0 commit comments

Comments
 (0)