Skip to content
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

Merged
merged 1 commit into from Jul 12, 2018

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Jul 12, 2018

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.

const ReactDebugCurrentFrame = {};

let currentlyValidatingElement = (null: null | ReactElement);

export function setCurrentlyValidatingElement(element: null | ReactElement) {
Copy link
Collaborator Author

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.
Copy link
Contributor

@bvaughn bvaughn left a 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.
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice comment 👍

@gaearon gaearon merged commit 1c89cb6 into facebook:master Jul 12, 2018
@gaearon gaearon deleted the refactor-el-valid branch July 12, 2018 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants