Skip to content

Will dangerouslySetInnerHTML generate more html element ? #14668

@Zaynex

Description

@Zaynex

Do you want to request a feature or report a bug?
Hi, React Team. Thanks for your awesome work. I have a problem when using
dangerouslySetInnerHTML

What is the current behavior?

My example code like this:

//...  the node.topic is a string
render() {
    const { node, className, style } = this.props;
    return (
      <div
        tabIndex={0}
        contentEditable={true}
        id="editor"
        onKeyDown={this.handleKeyDown}
        spellCheck={false}
        onBlur={this.handleBlur}
        onPaste={this.handlePaste}
        ref={this.containerRef}
        dangerouslySetInnerHTML={{ __html: node.topic }}
        style={style}
      />
    );
  }

But I got unexpected html that looks like
image
image

What is the expected behavior?
It's hard for me to debug what's wrong with it. It's sometimes work, but sometimes will generate a <br/> tag.
Maybe the <br /> tag is generated by my browser ?

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

react 16.7.0
react-dom 16.7.0
OS: macos 10.14.1 Beta (18B73a)
Chrome: 71.0.3578.98

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