Skip to content

Warn if rendering an HTML tag spelled with uppercase letters #2756

Closed

Description

@bmcmahen

If I try running the following code:

var Hello = React.createClass({
    render: function() {
      return React.createElement('BR', null);
    }
});

React.render(<Hello/>, document.body);

I get two <br> tags inserted into the dom, instead of one. I made a quick jsfiddle to show this. http://jsfiddle.net/kb3gN/8662/

I'm running Chrome, if that's at all relevant.

Activity

  1. CodisRedding commented on Dec 20, 2014

    @CodisRedding

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

  2. dashed commented on Dec 20, 2014

    @dashed
  3. CodisRedding commented on Dec 21, 2014

    @CodisRedding

    So in chrome it's got

    <br data-reactid=".0"><br>
    

    and ff has

    <br data-reactid=".0"></br><br></br> 
    

    ?

  4. CodisRedding commented on Dec 21, 2014

    @CodisRedding

    Well since br is a supported tag, there should be a test already.

  5. gaearon commented on Dec 21, 2014

    @gaearon
    Collaborator

    Perhaps React generates <br></br> and browser interprets it as two tags? Interesting.

  6. CodisRedding commented on Dec 21, 2014

    @CodisRedding

    Try

    React.createElement('br');
    

    I get different results with lowercase.

  7. gaearon commented on Dec 21, 2014

    @gaearon
    Collaborator

    Interestingly, it doesn't happen if you type br as lowercase.

    EDIT: beat me to it :-)

  8. gaearon commented on Dec 21, 2014

    @gaearon
    Collaborator

    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.

  9. dashed commented on Dec 21, 2014

    @dashed
  10. gaearon commented on Dec 21, 2014

    @gaearon
    Collaborator

    Ah, yeah. Even if it's a bug, it won't matter after capitalized tags will be disallowed.

  11. dashed commented on Dec 21, 2014

    @dashed

    In addition, the convention is that any tag names beginning with a capital letter should be user-land components.

  12. CodisRedding commented on Dec 21, 2014

    @CodisRedding

    @dashed ++ "All JSX tags that start with a lower-case letter or contain a dash are treated as HTML."

  13. dashed commented on Dec 21, 2014

    @dashed

    Does this convention extend to folks exclusively using React.createElement? (I actually don't know b/c I only use JSX 😅 )

  14. CodisRedding commented on Dec 21, 2014

    @CodisRedding

    Well considering that jsx gets transformed into js, I would think that all rules are the same.

  15. bmcmahen commented on Dec 21, 2014

    @bmcmahen
    Author

    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.createElement which works perfectly -- except for the BR case.

    Anyway, I will use lowercase tags from now on. Thanks!

  16. 10 remaining items

  17. added 2 commits that reference this issue on Jun 25, 2026
    f3f5582
    af96911
  18. added 2 commits that reference this issue on Sep 9, 2026
    9992050
    72fbf3e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions