Skip to content

Commit c819e57

Browse files
committed
[Fizz] Add Owner Stacks when render is aborted
1 parent 4d769be commit c819e57

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

Diff for: packages/react-server/src/ReactFizzServer.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -4151,6 +4151,27 @@ function abortTask(task: Task, request: Request, error: mixed): void {
41514151
}
41524152
}
41534153

4154+
function abortTaskDEV(task: Task, request: Request, error: mixed): void {
4155+
if (__DEV__) {
4156+
const prevTaskInDEV = currentTaskInDEV;
4157+
const prevGetCurrentStackImpl = ReactSharedInternals.getCurrentStack;
4158+
setCurrentTaskInDEV(task);
4159+
ReactSharedInternals.getCurrentStack = getCurrentStackInDEV;
4160+
try {
4161+
abortTask(task, request, error);
4162+
} finally {
4163+
setCurrentTaskInDEV(prevTaskInDEV);
4164+
ReactSharedInternals.getCurrentStack = prevGetCurrentStackImpl;
4165+
}
4166+
} else {
4167+
// These errors should never make it into a build so we don't need to encode them in codes.json
4168+
// eslint-disable-next-line react-internal/prod-error-codes
4169+
throw new Error(
4170+
'abortTaskDEV should never be called in production mode. This is a bug in React.',
4171+
);
4172+
}
4173+
}
4174+
41544175
function safelyEmitEarlyPreloads(
41554176
request: Request,
41564177
shellComplete: boolean,
@@ -5373,7 +5394,11 @@ export function abort(request: Request, reason: mixed): void {
53735394
// This error isn't necessarily fatal in this case but we need to stash it
53745395
// so we can use it to abort any pending work
53755396
request.fatalError = error;
5376-
abortableTasks.forEach(task => abortTask(task, request, error));
5397+
if (__DEV__) {
5398+
abortableTasks.forEach(task => abortTaskDEV(task, request, error));
5399+
} else {
5400+
abortableTasks.forEach(task => abortTask(task, request, error));
5401+
}
53775402
abortableTasks.clear();
53785403
}
53795404
if (request.destination !== null) {

Diff for: packages/react-server/src/__tests__/ReactServer-test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ describe('ReactServer', () => {
8383
expect(normalizeCodeLocInfo(componentStack)).toEqual(
8484
'\n in Component (at **)' + '\n in App (at **)',
8585
);
86-
// FIXME: Should have a stack.
87-
expect(normalizeCodeLocInfo(ownerStack)).toEqual(null);
86+
expect(normalizeCodeLocInfo(ownerStack)).toEqual('\n in App (at **)');
8887
});
8988
});

0 commit comments

Comments
 (0)