Open Zyclotrop-j opened 5 years ago
This seems like a good enhancement (not a bugfix or a breaking change) - to print out more errors and be more helpful here.
can i take on this issue? also, i'm new here,. if you have a specific implementation in mind.
Setup / Replicate
Have a component with deep propTypes:
Render that component so that the deep propTypes are propType-invalid (eg
<Example test={{}} />
for this example) [tr1
,str2
,str3
andstr4
are all required but not present, so all four are invalid.]Expected
PropTypes warnings for all failed propTypes For the example above this would be:
Actual
For deep propTypes only the first error is logged out, validation stops after that. On the other hand, this is not true for shallow properties (like
str1
andstr2
).For the example above this is:
Note
This doesn't only trigger on
required
, but also on everything else, like.number
,.string
, ...Second example
+
Full code (for copy-and-paste)
Cause of the bug
https://github.com/facebook/prop-types/blob/master/factoryWithTypeCheckers.js#L433 -> Exists on the first find opposed to https://github.com/facebook/prop-types/blob/master/checkPropTypes.js#L44 -> loops through all, no return to be seen [React calls this internally on validation, see https://github.com/facebook/react/blob/master/packages/react/src/ReactElementValidator.js#L218]