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

[Fix] prop-types: className missing in prop validation #3749

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

akulsr0
Copy link
Contributor

@akulsr0 akulsr0 commented May 6, 2024

Closes #3284

@@ -634,6 +634,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
// So we should construct an optional children prop
this.shouldSpecifyOptionalChildrenProps = true;

this.shouldSpecifyClassNameProp = true;
Copy link
Member

Choose a reason for hiding this comment

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

why do we need a class property for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since react generic type would have className too

Copy link
Member

Choose a reason for hiding this comment

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

what i mean is, when is this not always true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So whenever the type is coming from react import reference, then we can have className too (similar to children).
When its not true is: type annotation, type literal, etc...

Copy link
Member

Choose a reason for hiding this comment

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

className is just a prop, though, like any other. I'm a bit confused why it merits special treatment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

className is a react specific prop for HTML elements. class is a vanilla HTML attribute.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, that's all true - but HTML elements don't use propTypes, so we're only talking about custom components here.

Copy link
Member

Choose a reason for hiding this comment

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

@akulsr0 ok so, for custom components, className isn't special and is just like any other prop. For HTML elements, it is special and doesn't need a propType.

What are the next steps?

Copy link

codecov bot commented May 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.60%. Comparing base (a944aa5) to head (21ba4c5).

Current head 21ba4c5 differs from pull request most recent head 9ac517f

Please upload reports for the commit 9ac517f to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3749      +/-   ##
==========================================
+ Coverage   94.47%   97.60%   +3.12%     
==========================================
  Files         134      133       -1     
  Lines        9613     9473     -140     
  Branches     3486     3470      -16     
==========================================
+ Hits         9082     9246     +164     
+ Misses        531      227     -304     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ljharb ljharb force-pushed the akul/prop-types-className-issue branch from 21ba4c5 to 9ac517f Compare June 1, 2024 05:33
@ljharb ljharb marked this pull request as draft June 1, 2024 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Typescript "'className' is missing in props validation" despite being defined
2 participants