Skip to content

Commit

Permalink
Show first component stack in context warning
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Jan 29, 2020
1 parent 243003f commit 2cdb693
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/react-reconciler/src/ReactStrictModeWarnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,19 @@ if (__DEV__) {
ReactStrictModeWarnings.flushLegacyContextWarning = () => {
((pendingLegacyContextWarning: any): FiberToFiberComponentsMap).forEach(
(fiberArray: FiberArray, strictRoot) => {
if (fiberArray.length === 0) {
return;
}
const firstFiber = fiberArray[0];

const uniqueNames = new Set();
fiberArray.forEach(fiber => {
uniqueNames.add(getComponentName(fiber.type) || 'Component');
didWarnAboutLegacyContext.add(fiber.type);
});

const sortedNames = setToSortedString(uniqueNames);
const strictRootComponentStack = getStackByFiberInDevAndProd(
strictRoot,
);
const firstComponentStack = getStackByFiberInDevAndProd(firstFiber);

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

0 comments on commit 2cdb693

Please sign in to comment.