-
Notifications
You must be signed in to change notification settings - Fork 47.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Warn if the rendered DOM node is HTMLUnknownElement #3596
Comments
We generally treat warnings as "non-fatal errors", meaning that we try to only warn for things "should be fixed". Once upon a time, we enumerated all the "known html attributes", and have been backpedaling that mistake ever since. We allow any lower-case tag, because we can't distinguish it from a valid html tag, and using a new tag that we've never heard of shouldn't be an "error". With regards to warning if there is a variable in scope: It's very common to say Anyway, If you can think of a way to handle the problem of separating "tags" from "components", I'd be interested in hearing your thoughts. |
What about adding warnings only for those local vars that hold a reference to classes that extend React.Component? cc @spicyj doing var div = <div>My content</div>
//usage
<article>{div}</article> makes var centered = class extends React.Component { ... }
<article>
<centered>
<p>content here</p>
</centered>
</article> makes usage of a React.Component subclass, so there is a clear separation between the two. |
Yeah, I could get behind that idea. I'm curious what @spicyj says. |
It could be a bit expensive though. We would probably want to do the check only for unrecognized html tags (ie. have a whitelist). And we'd probably want to avoid the check in production. The logic for when we would warn starts to get a little messy. |
There's nothing to do in production, this is all part of the JSX transform step. Even if we did do something and it ended up in JSXTransformer, that's fine, it's not for production anyway. This is definitely interesting but might really be quite difficult, we would need to track every variable that might be in scope. I don't think that's possible with most transformers and you really need something like Flow to understand how everything is used (imagine passing function Or imagine you have a custom-element called Since there is so much state and intention outside of the transform that we can't capture, I don't think this is realistic to actually do. |
Transforming Now, in development |
I was thinking we could warn if the rendered element is an HTMLUnknownElement: http://ryanmorr.com/determine-html5-element-support-in-javascript/ |
@spicyj that would solve problems beyond this +1. The warning can be suppressed with |
If this works, I think it’s a better solution than transforms especially considering that most people are using Babel today anyway. 👍 |
Thanks @gaearon for the input! I will try to pick this up and solve it next week! |
Hm that's a good point. :( |
…n. Added stack trace and reference to element which causes the warning.
…ctDOMComponentCaseDevtool -> ReactDOMUnknownComponentDevtool
@aweary I wonder if the same would be true for Web Components, Brick, Polymer, etc. |
@kevinSuttle I would guess it would be, there's an issue open for jsdom regarding web components: jsdom/jsdom#1030 |
We do warn now. |
I've just been bit by
and as an after-thought I remembered something about lower-case/upper-case jsx tags. As a good React citizen, I've searched for it on the React site and found it documented here: https://facebook.github.io/react/docs/jsx-in-depth.html
I'm not new to React, but this took me around 10 minutes to trace down. I generally follow the convention, but I just developed a simple
centered
component for a mostly static site, that simply clones it's children and addsmargin: 0 auto; max-width: 900
to each of them. So I thought of this as a simple utility and therefore I lower-cased it.I understand this might not change, but it's worth at least adding a warning on uncommon html tag names, or better yet, on lowercase jsx tags that are also local variables.
The text was updated successfully, but these errors were encountered: