New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ReactDebugCurrentFrame.getStackAddendum() in element validator #13198
Conversation
const ReactDebugCurrentFrame = {}; | ||
|
||
let currentlyValidatingElement = (null: null | ReactElement); | ||
|
||
export function setCurrentlyValidatingElement(element: null | ReactElement) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't put it on the ReactDebugCurrentFrame
object because I don't want it to be accessible by the renderers.
Instead of wrapping ReactDebugCurrentFrame.getStackAddendum() call into a custom wrapper inside ReactElementValidator, "teach" the main ReactDebugCurrentFrame.getStackAddendum() to take currently validating element into account.
92267b6
to
4fd8299
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dig it
if (__DEV__) { | ||
// Component that is being worked on | ||
// Stack implementation injected by the current renderer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment took me back to the stack/fiber split days 😅
ReactDebugCurrentFrame.getCurrentStack = (null: null | (() => string)); | ||
|
||
ReactDebugCurrentFrame.getStackAddendum = function(): string { | ||
let stack = ''; | ||
|
||
// Add an extra top frame while an element is being validated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice comment 👍
Doesn't change anything functionally, but moves the logic for tracking the currently validated element into a centralized place instead of amending the stack in an ad hoc way.
This moves us closer to making
warning()
calls append the stack automatically without having to think where that call happens.