Skip to content

Commit 2cdb693

Browse files
committed
Show first component stack in context warning
1 parent 243003f commit 2cdb693

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/react-reconciler/src/ReactStrictModeWarnings.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,19 @@ if (__DEV__) {
324324
ReactStrictModeWarnings.flushLegacyContextWarning = () => {
325325
((pendingLegacyContextWarning: any): FiberToFiberComponentsMap).forEach(
326326
(fiberArray: FiberArray, strictRoot) => {
327+
if (fiberArray.length === 0) {
328+
return;
329+
}
330+
const firstFiber = fiberArray[0];
331+
327332
const uniqueNames = new Set();
328333
fiberArray.forEach(fiber => {
329334
uniqueNames.add(getComponentName(fiber.type) || 'Component');
330335
didWarnAboutLegacyContext.add(fiber.type);
331336
});
332337

333338
const sortedNames = setToSortedString(uniqueNames);
334-
const strictRootComponentStack = getStackByFiberInDevAndProd(
335-
strictRoot,
336-
);
339+
const firstComponentStack = getStackByFiberInDevAndProd(firstFiber);
337340

338341
console.error(
339342
'Legacy context API has been detected within a strict-mode tree.' +
@@ -343,7 +346,7 @@ if (__DEV__) {
343346
'\n\nLearn more about this warning here: https://fb.me/react-legacy-context' +
344347
'%s',
345348
sortedNames,
346-
strictRootComponentStack,
349+
firstComponentStack,
347350
);
348351
},
349352
);

0 commit comments

Comments
 (0)