-
Notifications
You must be signed in to change notification settings - Fork 48k
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 warning in server renderer if class doesn't extend React.Component #11993
Changes from 3 commits
6499aba
0ed0dae
2aaabea
5a06117
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,9 +60,11 @@ import { | |
import {NoWork, Never} from './ReactFiberExpirationTime'; | ||
|
||
let warnedAboutStatelessRefs; | ||
let didWarnAboutBadClass; | ||
|
||
if (__DEV__) { | ||
warnedAboutStatelessRefs = {}; | ||
didWarnAboutBadClass = {}; | ||
} | ||
|
||
export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>( | ||
|
@@ -459,13 +461,17 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>( | |
if (__DEV__) { | ||
if (fn.prototype && typeof fn.prototype.render === 'function') { | ||
const componentName = getComponentName(workInProgress); | ||
warning( | ||
false, | ||
"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.', | ||
componentName, | ||
componentName, | ||
); | ||
|
||
if (componentName !== null && !didWarnAboutBadClass[componentName]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's null we still want to show the message. Let's just say There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added that to make Flow happy, but your solution is better. I should do the same default on the server side warning too, correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, thanks! |
||
warning( | ||
false, | ||
"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.', | ||
componentName, | ||
componentName, | ||
); | ||
didWarnAboutBadClass[componentName] = true; | ||
} | ||
} | ||
ReactCurrentOwner.current = workInProgress; | ||
value = fn(props, context); | ||
|
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 should make sure we don't trigger this warning for the same component more than once.
If the client-side code doesn't deduplicate them, we also need to add deduplication there too.
Something like