Skip to content

ReactDOM renderToString adds empty HTML comments #14725

@buildbreakdo

Description

@buildbreakdo

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
ReactDOM.renderToString adds an empty HTML comment.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:

const someVar = 'foo';

const htmlWithVariableAndCharacters = document.createTextNode(
  ReactDOMServer.renderToString(
    <div>{someVar}anyCharacters</div>
  )
);

document.body.appendChild(htmlWithVariableAndCharacters);

HTML Output:

<div data-reactroot="">foo<!-- -->anyCharacters</div>

See it live here: https://codepen.io/anon/pen/mvORKd?editors=0010

What is the expected behavior?
Expected HTML output:

<div data-reactroot="">fooanyCharacters</div>

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Seen in React 16.7.0, do not know behavior in previous versions.


Something to keep in mind is if you open Chrome Development Tools you will not be able to see these HTML comments as Chrome strips them from being viewed in the developer pane. They can be seen in a server side render string output or if you right-click and choose 'Copy Element' and paste into a text editor.

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