Skip to content

v4 passes through unknown HTML attribute to the DOM #2131

Closed

Description

@shiningjason

Environment

npm packages:

  1. react: v16.5.2
  2. react-dom: v16.5.2
  3. styled-components: v4.0.2

Reproduction

https://codesandbox.io/s/zn5vrk0vpm

Expected Behavior

https://codesandbox.io/s/20xlp242pr
There is no unknown-prop warning if I'm using styled(styled.button).attrs({ customProp }) with styled-components v3.4.10.

Actual Behavior

There is unknown-prop warning with styled-components v4.
2018-10-20 11 33 29

If this is not a bug, and there is something missing. Please let me know, thanks!

Activity

  1. Fer0x commented on Oct 20, 2018

    @Fer0x
    Contributor
  2. mxstbr commented on Oct 21, 2018

    @mxstbr
    Member

    This is definitely a bug, any ideas why this broke @probablyup?

  3. Fer0x commented on Oct 21, 2018

    @Fer0x
    Contributor

    @shiningjason @mxstbr

    What's interesting is that [email protected] works much the same but instead of camelCase props are inserted in lowercase and React doesn't warn about this.

    image

  4. mxstbr commented on Oct 21, 2018

    @mxstbr
    Member

    Oh, that's even more strange 🤔

  5. Fer0x commented on Oct 27, 2018

    @Fer0x
    Contributor

    Fixed in #2133
    However, pay attention to #2093. It will add new way to tell which attributes should pass as html attributes

  6. mbrowne commented on Nov 21, 2018

    @mbrowne

    I'm seeing a similar issue with the new as prop, e.g.:

    ...
    import { Link } from 'react-router-dom';
    
    const StyledLink = styled.a`
        ${p => (p.linkStyle === 'upperCase' ? 'text-transform: uppercase' : '')}
    `
    
    <StyledLink as={Link} linkStyle="upperCase" to="/">test link</StyledLink>

    Warning: React does not recognize the linkStyle prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase linkstyle instead. If you accidentally passed it from a parent component, remove it from the DOM element.

    Is this related to an existing issue or should I open a new issue?

  7. quantizor commented on Nov 23, 2018

    @quantizor
    Contributor

    @mbrowne Since Link is a custom component, we don't do prop filtering and pass all props through to it. Until we settle on one of the several prop handling proposals floating around for v5 I don't think we're going to have a good solution for this.

  8. byzyk commented on Mar 14, 2019

    @byzyk

    Is there any ETA on when this can be addressed? Or let me know if I can help with the PR and what the challenge is.

  9. byzyk commented on Mar 14, 2019

    @byzyk

    As a workaround for eliminating React warnings in custom components, I had to make use of data-* attributes.

  10. jarodtaylor commented on Aug 16, 2019

    @jarodtaylor

    Will this be resolved in v5 for the Link (or any other custom components)?

  11. TerrorOnMtHyjal commented on Nov 20, 2019

    @TerrorOnMtHyjal

    Any update on this now that v5 beta is out? I'm attempting to use Formik's Field component with styled-components and want to customize the css if an error is present or not.

  12. srikanthbhamidipalli commented on Dec 27, 2019

    @srikanthbhamidipalli

    Still I'm getting error.. 😢

  13. GuilleDF commented on Jan 15, 2020

    @GuilleDF

    Seeing as this still happens in v5 for custom components, can we reopen this issue? Or create a new one?

  14. quantizor commented on Jan 15, 2020

    @quantizor
    Contributor
  15. ItsMrAkhil commented on Feb 3, 2020

    @ItsMrAkhil

    @probablyup @mxstbr Why can't we filter properties based on some prefix like $, like below?

    <StyledComp $someStyleProp={someValue} />

    The $someStyleProp will not be passed down as the user explicitly wants to ignore the property being passed down?

  16. quantizor commented on Feb 3, 2020

    @quantizor
    Contributor
  17. Maushundb commented on Feb 4, 2020

    @Maushundb

    The top answer here solved it for me

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions