Skip to content

Commit d1a3291

Browse files
committed
Move error logging to update callback
This prevents double logging for gDSFE boundaries with createRoot.
1 parent 8dc9c27 commit d1a3291

File tree

3 files changed

+15
-29
lines changed

3 files changed

+15
-29
lines changed

packages/react-dom/src/__tests__/ReactDOMConsoleErrorReporting-test.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,6 @@ describe('ReactDOMConsoleErrorReporting', () => {
260260
message: 'Boom',
261261
}),
262262
],
263-
[
264-
// Addendum by React:
265-
expect.stringContaining(
266-
'The above error occurred in the <Foo> component',
267-
),
268-
],
269263
[
270264
// TODO: This is duplicated only with createRoot. Why?
271265
expect.stringContaining('Error: Uncaught [Error: Boom]'),
@@ -274,7 +268,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
274268
}),
275269
],
276270
[
277-
// TODO: This is duplicated only with createRoot. Why?
271+
// Addendum by React:
278272
expect.stringContaining(
279273
'The above error occurred in the <Foo> component',
280274
),
@@ -291,12 +285,6 @@ describe('ReactDOMConsoleErrorReporting', () => {
291285
message: 'Boom',
292286
}),
293287
],
294-
[
295-
// TODO: This is duplicated only with createRoot. Why?
296-
expect.objectContaining({
297-
message: 'Boom',
298-
}),
299-
],
300288
]);
301289
}
302290

packages/react-reconciler/src/ReactFiberThrow.new.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,14 @@ function createClassErrorUpdate(
108108
if (typeof getDerivedStateFromError === 'function') {
109109
const error = errorInfo.value;
110110
update.payload = () => {
111-
logCapturedError(fiber, errorInfo);
112111
return getDerivedStateFromError(error);
113112
};
113+
update.callback = () => {
114+
if (__DEV__) {
115+
markFailedErrorBoundaryForHotReloading(fiber);
116+
}
117+
logCapturedError(fiber, errorInfo);
118+
};
114119
}
115120

116121
const inst = fiber.stateNode;
@@ -119,16 +124,14 @@ function createClassErrorUpdate(
119124
if (__DEV__) {
120125
markFailedErrorBoundaryForHotReloading(fiber);
121126
}
127+
logCapturedError(fiber, errorInfo);
122128
if (typeof getDerivedStateFromError !== 'function') {
123129
// To preserve the preexisting retry behavior of error boundaries,
124130
// we keep track of which ones already failed during this batch.
125131
// This gets reset before we yield back to the browser.
126132
// TODO: Warn in strict mode if getDerivedStateFromError is
127133
// not defined.
128134
markLegacyErrorBoundaryAsFailed(this);
129-
130-
// Only log here if componentDidCatch is the only error boundary method defined
131-
logCapturedError(fiber, errorInfo);
132135
}
133136
const error = errorInfo.value;
134137
const stack = errorInfo.stack;
@@ -150,10 +153,6 @@ function createClassErrorUpdate(
150153
}
151154
}
152155
};
153-
} else if (__DEV__) {
154-
update.callback = () => {
155-
markFailedErrorBoundaryForHotReloading(fiber);
156-
};
157156
}
158157
return update;
159158
}

packages/react-reconciler/src/ReactFiberThrow.old.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,14 @@ function createClassErrorUpdate(
108108
if (typeof getDerivedStateFromError === 'function') {
109109
const error = errorInfo.value;
110110
update.payload = () => {
111-
logCapturedError(fiber, errorInfo);
112111
return getDerivedStateFromError(error);
113112
};
113+
update.callback = () => {
114+
if (__DEV__) {
115+
markFailedErrorBoundaryForHotReloading(fiber);
116+
}
117+
logCapturedError(fiber, errorInfo);
118+
};
114119
}
115120

116121
const inst = fiber.stateNode;
@@ -119,16 +124,14 @@ function createClassErrorUpdate(
119124
if (__DEV__) {
120125
markFailedErrorBoundaryForHotReloading(fiber);
121126
}
127+
logCapturedError(fiber, errorInfo);
122128
if (typeof getDerivedStateFromError !== 'function') {
123129
// To preserve the preexisting retry behavior of error boundaries,
124130
// we keep track of which ones already failed during this batch.
125131
// This gets reset before we yield back to the browser.
126132
// TODO: Warn in strict mode if getDerivedStateFromError is
127133
// not defined.
128134
markLegacyErrorBoundaryAsFailed(this);
129-
130-
// Only log here if componentDidCatch is the only error boundary method defined
131-
logCapturedError(fiber, errorInfo);
132135
}
133136
const error = errorInfo.value;
134137
const stack = errorInfo.stack;
@@ -150,10 +153,6 @@ function createClassErrorUpdate(
150153
}
151154
}
152155
};
153-
} else if (__DEV__) {
154-
update.callback = () => {
155-
markFailedErrorBoundaryForHotReloading(fiber);
156-
};
157156
}
158157
return update;
159158
}

0 commit comments

Comments
 (0)