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

v4 passes through unknown HTML attribute to the DOM #2131

Closed
shiningjason opened this issue Oct 20, 2018 · 17 comments
Closed

v4 passes through unknown HTML attribute to the DOM #2131

shiningjason opened this issue Oct 20, 2018 · 17 comments
Labels

Comments

@shiningjason
Copy link

shiningjason commented Oct 20, 2018

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!

@Fer0x
Copy link
Contributor

Fer0x commented Oct 20, 2018

Don't think that it is expected behavior.

Also example from docs https://www.styled-components.com/docs/basics#attaching-additional-props works in similar way:

image

@mxstbr
Copy link
Member

mxstbr commented Oct 21, 2018

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

@Fer0x
Copy link
Contributor

Fer0x commented Oct 21, 2018

@shiningjason @mxstbr

What's interesting is that styled-components@3.x works much the same but instead of camelCase props are inserted in lowercase and React doesn't warn about this.

image

@mxstbr
Copy link
Member

mxstbr commented Oct 21, 2018

Oh, that's even more strange 🤔

@Fer0x
Copy link
Contributor

Fer0x commented Oct 27, 2018

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

@Fer0x Fer0x closed this as completed Oct 27, 2018
@mbrowne
Copy link

mbrowne commented Nov 21, 2018

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?

@quantizor
Copy link
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.

@byzyk
Copy link

byzyk commented Mar 14, 2019

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.

@byzyk
Copy link

byzyk commented Mar 14, 2019

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

@jarodtaylor
Copy link

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

@TerrorOnMtHyjal
Copy link

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.

@srikanthbhamidipalli
Copy link

Still I'm getting error.. 😢

@GuilleDF
Copy link

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

@quantizor
Copy link
Contributor

quantizor commented Jan 15, 2020 via email

@ItsMrAkhil
Copy link

@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?

@quantizor
Copy link
Contributor

quantizor commented Feb 3, 2020 via email

@Maushundb
Copy link

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
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.