Skip to content

Commit b72933b

Browse files
committed
Wrap ChildFiber errors and warnings in Server Component task
1 parent 80f3886 commit b72933b

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

packages/react-reconciler/src/ReactChildFiber.js

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
Thenable,
1414
ReactContext,
1515
ReactDebugInfo,
16+
ReactComponentInfo,
1617
SuspenseListRevealOrder,
1718
} from 'shared/ReactTypes';
1819
import type {Fiber} from './ReactInternalTypes';
@@ -101,6 +102,25 @@ function pushDebugInfo(
101102
return previousDebugInfo;
102103
}
103104

105+
function getCurrentDebugTask(): null | ConsoleTask {
106+
// Get the debug task of the parent Server Component if there is one.
107+
if (__DEV__) {
108+
const debugInfo = currentDebugInfo;
109+
if (debugInfo != null) {
110+
for (let i = debugInfo.length - 1; i >= 0; i--) {
111+
if (debugInfo[i].name != null) {
112+
const componentInfo: ReactComponentInfo = debugInfo[i];
113+
const debugTask: ?ConsoleTask = componentInfo.debugTask;
114+
if (debugTask != null) {
115+
return debugTask;
116+
}
117+
}
118+
}
119+
}
120+
}
121+
return null;
122+
}
123+
104124
let didWarnAboutMaps;
105125
let didWarnAboutGenerators;
106126
let ownerHasKeyUseWarning;
@@ -274,7 +294,7 @@ function coerceRef(workInProgress: Fiber, element: ReactElement): void {
274294
workInProgress.ref = refProp !== undefined ? refProp : null;
275295
}
276296

277-
function throwOnInvalidObjectType(returnFiber: Fiber, newChild: Object) {
297+
function throwOnInvalidObjectTypeImpl(returnFiber: Fiber, newChild: Object) {
278298
if (newChild.$$typeof === REACT_LEGACY_ELEMENT_TYPE) {
279299
throw new Error(
280300
'A React Element from an older version of React was rendered. ' +
@@ -299,7 +319,18 @@ function throwOnInvalidObjectType(returnFiber: Fiber, newChild: Object) {
299319
);
300320
}
301321

302-
function warnOnFunctionType(returnFiber: Fiber, invalidChild: Function) {
322+
function throwOnInvalidObjectType(returnFiber: Fiber, newChild: Object) {
323+
const debugTask = getCurrentDebugTask();
324+
if (__DEV__ && debugTask !== null) {
325+
debugTask.run(
326+
throwOnInvalidObjectTypeImpl.bind(null, returnFiber, newChild),
327+
);
328+
} else {
329+
throwOnInvalidObjectTypeImpl(returnFiber, newChild);
330+
}
331+
}
332+
333+
function warnOnFunctionTypeImpl(returnFiber: Fiber, invalidChild: Function) {
303334
if (__DEV__) {
304335
const parentName = getComponentNameFromFiber(returnFiber) || 'Component';
305336

@@ -336,7 +367,16 @@ function warnOnFunctionType(returnFiber: Fiber, invalidChild: Function) {
336367
}
337368
}
338369

339-
function warnOnSymbolType(returnFiber: Fiber, invalidChild: symbol) {
370+
function warnOnFunctionType(returnFiber: Fiber, invalidChild: Function) {
371+
const debugTask = getCurrentDebugTask();
372+
if (__DEV__ && debugTask !== null) {
373+
debugTask.run(warnOnFunctionTypeImpl.bind(null, returnFiber, invalidChild));
374+
} else {
375+
warnOnFunctionTypeImpl(returnFiber, invalidChild);
376+
}
377+
}
378+
379+
function warnOnSymbolTypeImpl(returnFiber: Fiber, invalidChild: symbol) {
340380
if (__DEV__) {
341381
const parentName = getComponentNameFromFiber(returnFiber) || 'Component';
342382

@@ -364,6 +404,15 @@ function warnOnSymbolType(returnFiber: Fiber, invalidChild: symbol) {
364404
}
365405
}
366406

407+
function warnOnSymbolType(returnFiber: Fiber, invalidChild: symbol) {
408+
const debugTask = getCurrentDebugTask();
409+
if (__DEV__ && debugTask !== null) {
410+
debugTask.run(warnOnSymbolTypeImpl.bind(null, returnFiber, invalidChild));
411+
} else {
412+
warnOnSymbolTypeImpl(returnFiber, invalidChild);
413+
}
414+
}
415+
367416
type ChildReconciler = (
368417
returnFiber: Fiber,
369418
currentFirstChild: Fiber | null,

0 commit comments

Comments
 (0)