-
Notifications
You must be signed in to change notification settings - Fork 47.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Warn in dev if shouldComponentUpdate is defined on PureComponent #9240
Conversation
Hey @misoguy! Thanks for taking this. I'm going to reply to your comment here so we can track the work.
We specifically want to warn when a user defines We can place this warning in For Fiber maybe you can add the warning in |
Do we need a utility? Only should have to check it once |
@acdlite nope, shouldn't need to unless you wanted to dedupe between renderers, but probably not a big deal. I pinged mainly to verify that's where you guys would like the validation to occur 😄 |
@aweary Thanks for the detailed comments! It was easy for me to understand and I have added the implementation as guided. :) Not sure if the warning message is good enough though. |
|
||
if (isPureComponent(Component) && typeof inst.shouldComponentUpdate !== 'undefined') { | ||
warning( | ||
false, |
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.
Make sure it only warns once so we don't spam the user with multiple warnings, and add a test for this behavior.
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.
Just to be clear, does this mean if the app has two different pure components, the warning should only show up once? Or does it mean to only warn once for the same pure component used numerous times in different places?
I'm guessing it's the latter but asking just to be sure :)
warning( | ||
false, | ||
'%s has a method called shouldComponentUpdate(). ' + | ||
'shouldComponentUpdate should not be used when extending React.PureComponent.', |
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.
Maybe include the suggestion to use React.Component
instead? Slightly more actionable.
Make sure you add the warning in Fiber, too. Then run |
@acdlite Thanks for the comments! I'll get on it :)
How should this test be modified? |
@misoguy we need to adjust the test to expect a warning as well. The test breaks because the test suite will fail if an expected warning is logged. You can test warnings by spying on |
@aweary I have adjusted the original test to spy on |
@acdlite I have added the warning in Fiber too, and ran |
@aweary @acdlite I'm not trying to be pushy here but I'm going on my honeymoon starting next saturday and will not be able to track this issue for about 2 weeks. I'd like to finish up with what I started before I go :) It'd be nice to get a feedback on how I can improve this PR to get merged. Thanks! |
That way it warns before the component updates
@misoguy sorry for the delay here!
I believe this was because the warning wasn't being issued until the component needed to update. I went ahead and moved it down to |
@aweary Thank you for the comment and the added commit. It's great to know that my PR can be merged now :) |
I take it it’s no longer WIP? 😄 |
What if somebody uses |
A work in completion 😄 btw @misoguy thanks again for doing this, great work!
I would recommend they use |
Yea fair enough. |
Fix #9239