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

Add callback validation to fiber-based renderers #8677

Merged

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Jan 3, 2017

Moved ReactFiberClassComponent validateCallback() helper function into a standalone util used by both fiber and stack implementations. Validation now happens in ReactFiberUpdateQueue so that non-DOM renderers will also benefit from it.

This fixes 2 failing fiber tests.

@gaearon
Copy link
Collaborator

gaearon commented Jan 3, 2017

Nit: can we also change Stack to use it?

@bvaughn
Copy link
Contributor Author

bvaughn commented Jan 3, 2017

Yeah, I was already making that change. 😁 Realized they were super redundant after I pushed the Fiber change.

@acdlite
Copy link
Collaborator

acdlite commented Jan 3, 2017

It's only ever used in ReactFiberUpdateQueue. We should just move the validation to there, like in Stack.

@bvaughn
Copy link
Contributor Author

bvaughn commented Jan 3, 2017

It's only ever used in ReactFiberUpdateQueue. We should just move the validation to there, like in Stack.

I don't understand your comment @acdlite.

@acdlite
Copy link
Collaborator

acdlite commented Jan 3, 2017

To clarify: rather than validating separately in ReactFiberClassComponent and ReactDOMFiber, move the validation to ReactFiberUpdateQueue.

@acdlite
Copy link
Collaborator

acdlite commented Jan 3, 2017

There's nothing renderer specific about validateCallback so we want all renderers to have top-level callback validation, not just the DOM renderer.

@bvaughn bvaughn force-pushed the add-callback-validation-to-dom-render branch from 5559da7 to 8d9a1ad Compare January 3, 2017 19:27
@bvaughn
Copy link
Contributor Author

bvaughn commented Jan 3, 2017

Thanks for clarifying @acdlite. That's a nice improvement since it will also add callback validation for other renderer types.

This PR has been updated with that change.

@bvaughn bvaughn changed the title Add callback validation to ReactDOMFiber.render Add callback validation to fiber-based renderers Jan 3, 2017
@@ -204,7 +205,9 @@ function findInsertionPosition(queue, update) : Update | null {
// we shouldn't make a copy.
//
// If the update is cloned, it returns the cloned update.
function insertUpdate(fiber : Fiber, update : Update, methodName : ?string) : Update | null {
function insertUpdate(fiber : Fiber, update : Update, methodName : string) : Update | null {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since methodName is now always a string, we can remove the typeof check on line 215.

Copy link
Collaborator

@acdlite acdlite left a comment

Choose a reason for hiding this comment

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

👍

@acdlite acdlite added this to the 15-next milestone Jan 3, 2017
@bvaughn bvaughn force-pushed the add-callback-validation-to-dom-render branch from 8d9a1ad to bc05ef1 Compare January 3, 2017 19:33
formatUnexpectedArgument(callback)
);
},
validateCallback: validateCallback,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this indirection useful? Can we just import it directly in the calling file instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It isn't! Good catch. Removed. 😄

Moved ReactFiberClassComponent validateCallback() helper function into a standalone util used by both fiber and stack implementations. Validation now happens in ReactFiberUpdateQueue so that non-DOM renderers will also benefit from it.
@bvaughn bvaughn force-pushed the add-callback-validation-to-dom-render branch from bc05ef1 to 8fbcd49 Compare January 3, 2017 20:10
@bvaughn bvaughn merged commit b27cb2c into facebook:master Jan 3, 2017
@bvaughn bvaughn deleted the add-callback-validation-to-dom-render branch January 3, 2017 22:57
@sebmarkbage
Copy link
Collaborator

Another one we can easily make a warning. Should we do a pass through and see how many of these we can make into warnings to help file size?

@sebmarkbage
Copy link
Collaborator

Nit: Same as #8639 (comment)

@gaearon
Copy link
Collaborator

gaearon commented Jan 11, 2017

Should we do a pass through and see how many of these we can make into warnings to help file size?

Yes, I'll add to umbrella.

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.

5 participants