-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Use JSX.IntrinsicElements instead of custom HTMLTags and SVGTags #1084
Use JSX.IntrinsicElements instead of custom HTMLTags and SVGTags #1084
Conversation
Waaaaiiiitttt can we use that in the JavaScript somehow too so we don't have to maintain our own whitelist? |
@mxstbr I don't think so, since I went searching for a physical whitelist within React's repo, but as best I can tell React itself hasn't kept a whitelist of elements since ~0.14 — maybe even earlier (see facebook/react#2746). I was about to ask why style-components enforces a whitelist, but I guess it doesn't really look like it does. Instead it just has a list used to support the |
@mxstbr you guys don't actually need to implement a whitelist. Could implement a getter on the default |
@probablyup We can't just define a getter for arbitrary input. That requires proxies and their support is not far spread enough. The polyfill requires a list of possible keys which brings us full circle. We've discussed this before and decided against it. @mxstbr We've also discussed this point before. We could use an internal file in React with a list of all elements, but they might remove it at any time ( I think the only sane and realistic solution is to add it to our v3 babel plugin. I already have an idea on how to structure it so that preprocessing and non-preprocessing SC code can be used at the same time. We can then also remove the tag list from the SC code for preprocessing. |
cc @styled-components/typers |
Looks good to me, the only issue I can see is that if the react.d.ts list gets updated but we don't update styled-components to support the new tags (or remove one) there can be some discrepancies between the typings and the actual implementation, but I don't see this happening often (also, we'd need to update our elements list when, and if, we do change the list of elements we support). So for me it's +1 PS. When I did the initial typings I didn't know about the existence of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So good 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it, I wanted to have this some time ago but didn't have time to address it.
@patrick91 your concern is legit, but, to me, it is acceptable risk. Moreover, it would push people to file issues if something is not supported from the list of jsx elements. 😃 |
Thanks @devrelm for contributing and thanks @Igorbek and @patrick91 for reviewing it this quickly 👍 |
This replaces the use of `React.HTMLProps` and `React.SVGAttributes` with `JSX.IntrinsicElements`. Inspired by styled-components/styled-components#1084
I'm not sure if there's a good reason we're maintaining our own list of element tags, but from what I can tell, we should be able to just use the
JSX.IntrinsicElements
types straight from the react type defs.This PR kills
tags.d.ts
in favor of usingJSX.IntrinsicElements
, which contains both HTML and SVG elements (and thus replaces both ourHTMLTags
andSVGTags
.)JSX.IntrinsicElements
also maps from element names to prop-types, rather than from names to element-types. This means that we will output the actual detailed props used by each individual html component rather thanHTMLProps
, which contains all props for all elements (i.e.href
ondiv
, which shouldn't be there.)