-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Warn if class has a render() method but doesn't extend React.Component #11168
Conversation
Prettier is failing. Have you run |
gosh really embarrassing. Looks like i didnt commit the prettified file. I have resubmitted and it should pass. Jeez I am going to be so embarrassed when I look back on this in a few months |
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.
See changes below + we'll need a test for this.
warning( | ||
!(workInProgress.type.prototype && | ||
workInProgress.type.prototype.render), | ||
'Warning: Using a class with a render method as a function, ' + |
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.
Please remove Warning:
, it gets added automatically.
@@ -481,6 +481,12 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>( | |||
var value; | |||
|
|||
if (__DEV__) { | |||
warning( | |||
!(workInProgress.type.prototype && |
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 a bit hard to follow. Let's just wrap it in an if
block with the real condition, and then pass false
to the warning
call.
!(workInProgress.type.prototype && | ||
workInProgress.type.prototype.render), | ||
'Warning: Using a class with a render method as a function, ' + | ||
'did you forget to extend React.Component?', |
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 would tweak the wording to:
The <%s /> component appears to have a render method, but doesn't extend React.Component. This is likely to cause errors. Change %s to extend React.Component instead.
You’ll need to pass the component name (use getComponentName
).
thanks @gaearon . its not clear to me -where- to add the tests. is there a deeper test guide somewhere other than the 4 page Contributing docs?
|
added the test in |
Sorry the structure is a bit confusing. We haven’t updated the file structure to be sensible yet after deleting the old engine. But I’d put it here. |
Also the test is failing:
Have you tried running it with |
seems i errantly deleted a space when I made the warning multiline. will fix and move as suggested. Yeah is there a separate issue for restructuring the test file structure? "ReactIncremental" doesnt really seem to make sense anymore |
Sorry for the trouble again. We rearranged how files are laid out in the repo. Could you please reapply your changes on top of master? |
merging in fb's changes
I confess I'm not sure what's going on. I thought I could simply |
ok this one looks like it works. Woohoo! |
try { | ||
ReactDOM.render(<ClassWithRenderNotExtended />, container); | ||
} catch (e) { | ||
expect(e).toEqual(new TypeError('Cannot call a class as a function')); |
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 only runs assertions if we get into catch
. But what if we have a bug that causes us not to throw an error? Then the test doesn't assert anything.
I made a few minor tweaks:
I think this is good to go. Thanks! |
facebook#11168) Warn if class has a render() method but doesn't extend React.Component
Hi! adding the fix for #10103. test/prettier/lint/flow all done and passing. (replaces PR #11149)