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

Add key to error messages #284

Closed
wants to merge 1 commit into from
Closed

Add key to error messages #284

wants to merge 1 commit into from

Conversation

asbjornh
Copy link

@asbjornh asbjornh commented Aug 6, 2019

Fixes #279

This PR aims to solve the problem of having many failed propTypes checks when rendering a huge list of components. In this case, it can be really hard to determine which warning belongs to which component instance, making debugging tedious and frustrating.

Displaying the key in warnings could help to quickly identify which item(s) in a list of components have type warnings:

Warning: Failed prop type: The prop 'blabla' is marked as required in 'SomeComponent' with key 'abc', but its value is 'null'.

While this would mitigate the issue, I'm not a 100% sure that this is a good idea (see below), but I'm opening this PR in hopes of at least getting some discussion around it.

This solution should work decently when doing array.map, but it comes with at least one side effect that might not be desirable. As far as I know the key prop doesn't hold any special significance outside the case of array.map and might be used as a part of the regular data flow. In those cases it might be weird that the key prop is displayed in warnings. Detecting whether a component was rendered with array.map is likely impossible in prop-types so I don't see a way of avoiding this.

Also, there might be a need for truncating very long keys to avoid destroying the readability of the message?

@asbjornh asbjornh marked this pull request as ready for review August 25, 2019 11:23
@asbjornh
Copy link
Author

Closing this since there hasn't been any activity for a while!

@asbjornh asbjornh closed this Nov 18, 2019
@ljharb
Copy link
Collaborator

ljharb commented Nov 18, 2019

@asbjornh that's not a good reason to close things, but if you're no longer interested in the PR, so be it.

@asbjornh
Copy link
Author

You're right I should've been more clear. I have sort of lost interest because like I wrote in the description I don't think this is such a good idea anymore :)

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

Successfully merging this pull request may close these issues.

Better prop types warnings
3 participants