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

15.8.0: checkPropTypes sometimes throws: Cannot read properties of undefined (reading 'hasOwnProperty') #369

Closed
kaiyoma opened this issue Jan 4, 2022 · 11 comments · Fixed by #370

Comments

@kaiyoma
Copy link

kaiyoma commented Jan 4, 2022

I tried upgrading from 15.7.2 to 15.8.0 in my project and now I'm getting this error on some of our unit tests:

Warning: Failed prop type: Cannot read properties of undefined (reading 'hasOwnProperty')

I've double-checked that I'm not passing undefined or null to checkPropTypes; all the data is valid and intact. This seems like an error inside checkPropTypes itself.

@ljharb
Copy link
Collaborator

ljharb commented Jan 4, 2022

aha - I do see one incorrect usage of .hasOwnProperty in factoryWithTypeCheckers, added in #198 and included in v15.8.0. I'll get a fix out shortly.

@ljharb
Copy link
Collaborator

ljharb commented Jan 4, 2022

Any chance you could provide the propType code you're using that generates that, so I can write a test case?

@kaiyoma
Copy link
Author

kaiyoma commented Jan 4, 2022

From what I can tell, our unit test code is passing PropTypes.exact(...) as the first argument to checkPropTypes and then passing an object that should validate.

@ljharb
Copy link
Collaborator

ljharb commented Jan 4, 2022

Thanks! I'll see if i can repro it.

@ljharb
Copy link
Collaborator

ljharb commented Jan 4, 2022

hmm, that doesn't seem to do it. Can you perhaps provide the exact code you're using?

@kaiyoma
Copy link
Author

kaiyoma commented Jan 4, 2022

Unfortunately this particular unit test code is kind of convoluted (and proprietary), so extracting a workable example isn't that easy. We're passing a multi-level object to PropTypes.exact and a multi-level object as the data to test. It's very difficult to tell which property at which level is causing the problem.

@ljharb
Copy link
Collaborator

ljharb commented Jan 4, 2022

I was able to reproduce it with a custom propType, but it'd be ideal to use non-contrived code if you can provide it :-)

@kaiyoma
Copy link
Author

kaiyoma commented Jan 4, 2022

It really won't be easy for me to provide it (and would require an investment of time I don't have), so I would suggest using your custom prop-type in the interest of getting out a quick fix.

@ljharb
Copy link
Collaborator

ljharb commented Jan 5, 2022

Filed #370; that should do it. I'll have it released shortly.

@ljharb
Copy link
Collaborator

ljharb commented Jan 5, 2022

v15.8.1 is released.

@kaiyoma
Copy link
Author

kaiyoma commented Jan 5, 2022

Thanks for the quick fix! I just tried it out and my unit tests are passing again. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants