You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Warn if rendering an HTML tag spelled with uppercase letters #2756
I had no idea that using capital letters was something that should be avoided / would be disallowed. I'm actually using this within a context of parsing a limited number of tags in a contentEditable container, and the parser records the tagName as it does natively -- with capital letters. These are then passed into React.createElement which works perfectly -- except for the BR case.
Anyway, I will use lowercase tags from now on. Thanks!
Activity
CodisRedding commentedon Dec 20, 2014
@bmcmahen I'm looking at the elements created in the Chrome dev tools but I only see a single
. Can you screen shot the 2 br's you're seeing?
dashed commentedon Dec 20, 2014
I can confirm in Chrome
Version 40.0.2214.45 beta (64-bit)and Firefox34.0.5.Here's a jsbin:
http://jsbin.com/hiqiva/1/edit?html,js,output
CodisRedding commentedon Dec 21, 2014
So in chrome it's got
and ff has
?
CodisRedding commentedon Dec 21, 2014
Well since br is a supported tag, there should be a test already.
gaearon commentedon Dec 21, 2014
Perhaps React generates
<br></br>and browser interprets it as two tags? Interesting.CodisRedding commentedon Dec 21, 2014
Try
I get different results with lowercase.
gaearon commentedon Dec 21, 2014
Interestingly, it doesn't happen if you type
bras lowercase.EDIT: beat me to it :-)
gaearon commentedon Dec 21, 2014
Relevant check in source code: https://github.com/facebook/react/blob/master/src/browser/ui/ReactDOMComponent.js#L183
Seems like
this._tag.toLowerCase()should instead be checked. I wonder how React does it in other places though.dashed commentedon Dec 21, 2014
@gaearon's right.
I use JSX, so I do something like:
It may be an implied convention: http://facebook.github.io/react/blog/2014/10/16/react-v0.12-rc1.html#jsx-lower-case-convention
gaearon commentedon Dec 21, 2014
Ah, yeah. Even if it's a bug, it won't matter after capitalized tags will be disallowed.
dashed commentedon Dec 21, 2014
In addition, the convention is that any tag names beginning with a capital letter should be user-land components.
CodisRedding commentedon Dec 21, 2014
@dashed ++ "All JSX tags that start with a lower-case letter or contain a dash are treated as HTML."
dashed commentedon Dec 21, 2014
Does this convention extend to folks exclusively using
React.createElement? (I actually don't know b/c I only use JSX 😅 )CodisRedding commentedon Dec 21, 2014
Well considering that jsx gets transformed into js, I would think that all rules are the same.
bmcmahen commentedon Dec 21, 2014
Whoops. Sorry -- just read all of this now.
I had no idea that using capital letters was something that should be avoided / would be disallowed. I'm actually using this within a context of parsing a limited number of tags in a contentEditable container, and the parser records the tagName as it does natively -- with capital letters. These are then passed into
React.createElementwhich works perfectly -- except for the BR case.Anyway, I will use lowercase tags from now on. Thanks!
10 remaining items
Warn if upper-case tags are used
Warn if upper-case tags are used
Warn if upper-case tags are used
Prevent creating invalid closing tags
Warn if upper-case tags are used
Prevent creating invalid closing tags
Warn if upper-case tags are used