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

Display which invalid type was returned #7963

Conversation

davidblurton
Copy link

Fixes #7215

@facebook-github-bot
Copy link

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.

@facebook-github-bot
Copy link

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

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) {
Copy link
Collaborator

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.

@davidblurton davidblurton force-pushed the let-users-know-which-invalid-type-was-returned branch from 1d3b1b7 to 999dc36 Compare October 13, 2016 09:54
@davidblurton
Copy link
Author

Updated with requested changes.

@davidblurton
Copy link
Author

@gaearon updated with your suggestions and tests fixed :)

@@ -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.",
Copy link
Collaborator

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.)

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

@gaearon
Copy link
Collaborator

gaearon commented Oct 15, 2016

Can you please run the docs locally (instructions are in docs folder), and verify that the error decoder correctly decodes the link locally? A screenshot showing this would be nice.

@keyz
Copy link
Contributor

keyz commented Oct 15, 2016

Hi @davidblurton,

Thanks for your contribution. However, the codes.json file is automatically generated and should never be edited manually. Instead, please run ./node_modules/.bin/gulp react:extract-errors to update the json files -- the new/updated errors will be appended to the end of codes.json, which ensures our decoder page stays backwards compatible.

@davidblurton
Copy link
Author

I changed the error message to something better:

Component.render() must return a valid React element (or null). You returned an array.

@davidblurton
Copy link
Author

Here's a screenshot of the generated docs:

screen shot 2016-10-15 at 22 45 39

@davidblurton
Copy link
Author

@gaearon is this good to go?

@keyz
Copy link
Contributor

keyz commented Oct 17, 2016

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 src/isomorphic/hooks are missing/duplicated. It's probably because we only generate the error code when we cut a release, so the one in master doesn't get updated. @davidblurton can you give us some time to resolve this issue first? I'll create a separate issue.

Copy link
Contributor

@aweary aweary left a 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 👍

@aweary aweary assigned aweary and unassigned gaearon Jan 26, 2017
@davidblurton davidblurton force-pushed the let-users-know-which-invalid-type-was-returned branch from d3679d8 to e50e618 Compare January 28, 2017 23:21
@aweary
Copy link
Contributor

aweary commented Mar 2, 2017

@davidblurton sorry about this, looks like some more conflicts. Can you address those?

@davidblurton
Copy link
Author

@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?

 FAIL  src/renderers/dom/__tests__/ReactDOMProduction-test.js
  ● ReactDOMProduction › should throw with an error code in production

    TypeError: process.cwd is not a function
      
      at printActualErrorMessage (node_modules/jest-matchers/build/toThrowMatchers.js:153:26)
      at Object.<anonymous> (src/renderers/dom/__tests__/ReactDOMProduction-test.js:191:8)

@aweary
Copy link
Contributor

aweary commented Mar 2, 2017

@davidblurton can you rebase with master, reinstall node_modules and try again?

@davidblurton davidblurton force-pushed the let-users-know-which-invalid-type-was-returned branch from 8daa72d to b71c6f9 Compare March 2, 2017 21:45
@aweary aweary force-pushed the let-users-know-which-invalid-type-was-returned branch from b71c6f9 to a676b18 Compare April 14, 2017 17:20
"144": "React.PropTypes type checking code is stripped in production.",
Copy link
Collaborator

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.

Copy link
Contributor

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?

Copy link
Collaborator

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.

Copy link
Contributor

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) {
Copy link
Collaborator

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';
Copy link
Collaborator

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.

@gaearon
Copy link
Collaborator

gaearon commented Oct 4, 2017

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.

@gaearon gaearon closed this Oct 4, 2017
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.

7 participants