-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This exposes it to captureOwnerStack(). In this case we install it permanently as we only allow one RSC renderer which then supports async contexts. It also exposes it to component stack addendums that React adds to its own console.errors. At least for now.
- Loading branch information
1 parent
15ca8b6
commit aeffcc2
Showing
4 changed files
with
155 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/react-server/src/flight/ReactFlightComponentStack.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {ReactComponentInfo} from 'shared/ReactTypes'; | ||
|
||
import {describeBuiltInComponentFrame} from 'shared/ReactComponentStackFrame'; | ||
|
||
import {enableOwnerStacks} from 'shared/ReactFeatureFlags'; | ||
|
||
export function getOwnerStackByComponentInfoInDev( | ||
componentInfo: ReactComponentInfo, | ||
): string { | ||
if (!enableOwnerStacks || !__DEV__) { | ||
return ''; | ||
} | ||
try { | ||
let info = ''; | ||
|
||
// The owner stack of the current component will be where it was created, i.e. inside its owner. | ||
// There's no actual name of the currently executing component. Instead, that is available | ||
// on the regular stack that's currently executing. However, if there is no owner at all, then | ||
// there's no stack frame so we add the name of the root component to the stack to know which | ||
// component is currently executing. | ||
if (!componentInfo.owner && typeof componentInfo.name === 'string') { | ||
return describeBuiltInComponentFrame(componentInfo.name); | ||
} | ||
|
||
let owner: void | null | ReactComponentInfo = componentInfo; | ||
|
||
while (owner) { | ||
if (typeof owner.stack === 'string') { | ||
// Server Component | ||
const ownerStack: string = owner.stack; | ||
owner = owner.owner; | ||
if (owner && ownerStack !== '') { | ||
info += '\n' + ownerStack; | ||
} | ||
} else { | ||
break; | ||
} | ||
} | ||
return info; | ||
} catch (x) { | ||
return '\nError generating stack: ' + x.message + '\n' + x.stack; | ||
} | ||
} |