-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Display which invalid type was returned #7963
Display which invalid type was returned #7963
Conversation
Thank you for your pull request. As you may know, we require contributors to sign our Contributor License Agreement, and we don't seem to have you on file and listed as active anymore. In order for us to review and merge your code, please email cla@fb.com with your details so we can update your status. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
return 'null'; | ||
} | ||
if (Array.isArray(element)) { | ||
return 'array'; |
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.
Can you return 'an array'
so that the error message sounds less awkward?
@@ -47,13 +47,24 @@ StatelessComponent.prototype.render = function() { | |||
return element; | |||
}; | |||
|
|||
function getTypeof(element) { |
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.
Let's call this getElementTypeForWarning
.
1d3b1b7
to
999dc36
Compare
Updated with requested changes. |
@gaearon updated with your suggestions and tests fixed :) |
scripts/error-codes/codes.json
Outdated
@@ -104,11 +104,11 @@ | |||
"102": "EventPluginRegistry: Cannot inject two different event plugins using the same name, `%s`.", | |||
"103": "executeDirectDispatch(...): Invalid `event`.", | |||
"104": "ReactCompositeComponent: injectEnvironment() can only be called once.", | |||
"105": "%s(...): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.", | |||
"105": "%s(...): A valid React element (or null) must be returned, but you returned %s.", |
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.
English nit: comma before but
is not necessary? (I'm not actually a native speaker so correct me if I'm wrong.)
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.
If the two clauses joined by but are independent (test: can they stand alone and make sense as a sentence?) a comma is appropriate. So a comma is correct here
Can you please run the docs locally (instructions are in |
Hi @davidblurton, Thanks for your contribution. However, the |
I changed the error message to something better:
|
@gaearon is this good to go? |
Sorry, I just noticed that the error code in the 15-dev branch (https://github.com/facebook/react/blob/15-dev/scripts/error-codes/codes.json) is not in sync with the one here or in master. Specifically some invariants in |
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.
@davidblurton can you resolve the merge conflicts please? I'll make sure this gets merged if we can do it cleanly 👍
d3679d8
to
e50e618
Compare
@davidblurton sorry about this, looks like some more conflicts. Can you address those? |
@aweary I'm getting strange errors like this and I don't know how to fix them. Do you know what the cause of this is?
|
@davidblurton can you rebase with master, reinstall |
8daa72d
to
b71c6f9
Compare
b71c6f9
to
a676b18
Compare
"144": "React.PropTypes type checking code is stripped in production.", |
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.
We shouldn't update error codes in a PR.
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 almost removed it when I rebased for @davidblurton, but it wasn't clear if this should be excluded. There is a test that relies on testing the new error (and error code) in ReactDOMProduction
, won't that test potentially fail if codes.json
isn't updated now since the code will potentially change?
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.
If the test doesn't pass, can you amend the test instead? If it specifically tests for "error codes" then we can change it to trigger some other invariant whose code didn't change.
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.
Oh I see now, it's not testing this specific invariant it's just testing any production invariant. That makes sense, we should definitely change it.
@@ -73,7 +73,20 @@ const { | |||
Deletion, | |||
} = ReactTypeOfSideEffect; | |||
|
|||
function coerceRef(current: Fiber | null, element: ReactElement) { | |||
function getElementTypeForWarning(element) { |
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 is not a warning though, it's an error.
return 'null'; | ||
} | ||
if (element === undefined) { | ||
return 'undefined'; |
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.
Can we avoid strings in these two cases? Seems like return '' + element
would be enough. Minor thing but minifies better.
Really sorry about how we handled this. We were in the middle of a rewrite of the whole reconciler, and it wasn't clear which features will be supported by the time we finish. In the end we support both strings, numbers, and arrays, that we don't really need this change. I really appreciate the effort you put into it, and I hope this doesn't discourage you from contributing in the future. |
Fixes #7215