Skip to content

Warn and remove when a known attribute of a DOM component receives a Symbol as a value. #10512

Closed
@flarnie

Description

@flarnie

Do you want to request a feature or report a bug?
This is a possibly incorrect corner case which we should correct before finalizing the new behavior of unknown attributes. (See #10399 for more context on the changes to behavior with unknown attributes.)

If this happens with unknown attributes, we want to warn and then remove the attribute. The behavior should be consistent between known and unknown attributes.

What is the current behavior?
We currently throw a generic error when a Symbol is passed to a known attribute which expects a string.

var Hello = React.createClass({
  render: function() {
    return <div className={Symbol('foo')}>Hello {this.props.name}</div>;
  }
});
// rendering this throws "TypeError: can't convert symbol to string  react-dom.js:2028:11"

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: https://jsfiddle.net/84v837e9/).

Example:
https://jsfiddle.net/675gk050/1/

Also happens with spreading of objects in as props:
https://jsfiddle.net/2m985yt1/2/

What is the expected behavior?
We should warn and remove the attribute, since that is not a valid value.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Recent react (15.*) and 16-beta as well.

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