Skip to content

Remove Did not expect server HTML to contain a <style> in <div> from react-dom #16089

Closed
@ImanMh

Description

@ImanMh

Do you want to request a feature or report a bug?
I'm requesting to remove a feature

What is the current behavior?
React dom shows warnings when there are style tags in between html responses from server

Warning: Did not expect server HTML to contain a <style> in <div>.

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:
it's not a bug but here is how to reproduce it:

Clone a SSR supported boiler plate like react-starter-kit and add this code in any component's render method:

{!process.env.BROWSER &&
    <style>{'.test { color: red; }'}</style>
}

What is the expected behavior?
not throwing warnings

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React: ^16.5.2
React-dom: ^16.5.2
Browser: FireFox 67.0.4
I think it's always been like this!

I think this warning message should be totally removed from React DOM, How should I stream using ReactDOMServer.renderToNodeStream if I don't put the style tags in between HTML tags?
I've seen many people using packages like isomorphic-style-loader which puts all the styles in the head. However if you want to steam the server response, the idea of styles in head is not possible unless you first renderToString the entire component tree which eliminates the whole purpose of streaming the results.

My suggestion is that ReactDOM does not considers style tags inside html nodes an invalid response from server so it's possible to stream server response easier and remove all these inline styles in client and move them to the head(for the sake of easier DOM manipulations in feature).

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