-
Notifications
You must be signed in to change notification settings - Fork 47.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReactDOM renderToString adds empty HTML comments #14725
Comments
This is by design and helps React hydrate those text nodes correctly. |
@gaearon Oh, very interesting. Note for folks that somehow land here, if you want to avoid the extra characters, particularly in long lists of things which can add up to thousands of characters can switch from something like: Before
After
Suspicion is this could be a candidate for Had this showing up in two places in a list of 100 things: Gzip does eat this up though for sure, just seemed a bit odd. @gaearon thanks for the clarity! |
@buildbreakdo woah thx mate! Took me ages to find someone with the same problem. I use react as content building tool where the render output is imported into a more or less standardized software solution and those comments killed the upload. |
For future reference: |
is related to facebook/react#14725
It may be by design. It may help hydrate more efficiently. But it's still a bug. HTML doesn't allow for comments in react-dom doesn't use comments to set a <textarea name="example">
Some static text: {someDynamicValue}
</textarea> React tells the developer to use Conversely, the message for The docs for title say
Assuming folks read the docs for such a small, seemingly-obvious element, that should probably read
|
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:
HTML Output:
See it live here: https://codepen.io/anon/pen/mvORKd?editors=0010
What is the expected behavior?
Expected HTML output:
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.
The text was updated successfully, but these errors were encountered: