Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Observer checks for use of React.memo #720

Merged
merged 4 commits into from
Jul 9, 2019
Merged

Conversation

danielkcz
Copy link
Contributor

@danielkcz danielkcz commented Jun 26, 2019

Fixes #709

The React.memo returns an object which isn't expected and is passed down to observerClass which assumed a class component, but it got a plain object without a prototype present.

The solution works in a similar fashion as the one for React.forwardRef, but it simply removes additional React.memo by accessing a wrapped function component and applying observer to it. And it issues a warning.


I've also installed @testing-library/react and jest-mock-console to start modernizing tests slightly. There was a small hiccup as we have TS 2.6 in here, but the latest peer dep @types/yargs is built on top of TS 3.5 (requiring unknown). I had to force the older version there.

@coveralls
Copy link

coveralls commented Jun 26, 2019

Coverage Status

Coverage decreased (-0.2%) to 90.746% when pulling db95f90 on fix/check-for-memo into fc6eaa8 on master.

@danielkcz danielkcz requested review from xaviergonz and urugator June 26, 2019 17:42
Copy link
Contributor

@urugator urugator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I would prefer it to throw.
Can't comment on deps update.

@danielkcz
Copy link
Contributor Author

I would prefer it to throw.

The throw would probably make sense if it wasn't possible to recover from it.

@urugator
Copy link
Contributor

I don't want to argue about this, but imo either it's a valid use case then it shouldn't warn (at least on production) or it's not and then it should throw (so I am forced to fix it).

@mweststrate
Copy link
Member

Is it allowed to use static members on memo components? Such as defaultProps, propTypes etc? If that is the case, we should throw instead of fixing, as we might accidentally loose those members.

@urugator
Copy link
Contributor

It is facebook/react#14298 (comment)

@danielkcz
Copy link
Contributor Author

Ok, you are right. Changed it to throw. Sadly, the test is worthless in that case, but I kept it there for a future reference when it's possible to properly test errors in React.

@danielkcz
Copy link
Contributor Author

I think it's time to merge :)

@danielkcz danielkcz merged commit caebf77 into master Jul 9, 2019
@danielkcz danielkcz deleted the fix/check-for-memo branch July 9, 2019 21:17
@github-actions github-actions bot mentioned this pull request Oct 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'componentWillReact' of undefined after updating to 6.1.0.
4 participants