Skip to content

Unexpected JSX Whitespace Handling with Leading and Trailing Tags #4134

Closed
@jmar777

Description

@jmar777

Related (closed) issue: #65

I'm not sure whether this is considered a bug or if it's working as intended, but I'll at least throw in a vote that the behavior is unexpected. Given the following example:

var Test = React.createClass({
  render: function() {
    return (
      <p>
        Demonstration of <span>unexpected</span>
        whitespace handling in
        <span>ReactJS</span>.
      </p>
    );
  }
});

React.render(<Test />, document.body)

[Demonstration on jsbin].

I would suggest that the expected rendered output of the above component would be:

Demonstration of unexpected whitespace handling in ReactJS.

Whereas the actual output is:

Demonstration of unexpectedwhitespace handling inReactJS.

(No whitespace between "unexpected" and "whitespace" or between "in" and "ReactJS").

I would consider this unexpected for two primary reasons:

  • It's inconsistent with HTML's handling of whitespace.
  • Removing the <span> tags (but leaving newlines and indentations unchanged) causes whitespace to be preserved.

If this is simply a bug, then I suppose there's no need to belabor the point. If not, is there some rationale for leading/trailing tags behaving different than leading/trailing plain text?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions