-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Remove Did not expect server HTML to contain a <style> in <div> from react-dom #16089
Comments
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](https://github.com/kriasoft/isomorphic-style-loader) which puts all the styles in the head. How ever if you want to steam the response the idea of styles in the 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.
The current streaming support isn't very good because you also can't control how content appears. It will just appear in whatever order the bytes happen to come in. It also doesn't deal with things like error handling. We have plans for a new streaming renderer. We plan on adding support directly for this in the new renderer to be able to inject things like data and style injections as first class. In the existing renderer, DOM that doesn't line up is a whole can of worm. We need it to line up perfectly so that we know what the surrounding elements are supposed to do. Without it we'd need too much meta data. We'll likely also want to stop even looking at the tagName for perf reasons (e.g. see #15998). So we couldn't even special case style tags. Code like Is there a reason you can't just render the style tag on the client? |
@sebmarkbage What I'm trying to do is to have SSR, CSS modules and React Render to Stream all together. I can render the style tags on the client but then I have to make sure to remove those style tags when components are removed from the DOM. The problem is that when a component has appeared in multiple places in DOM, I want to keep one single copy of it's styles (for the sake of network and CPU performance). It's easy to do in server cause I add each style only once, but in client users interact with components and they might remove them by taking an action. So keeping track of these style tags is kind of tricky in client. The simpler approach would be to move all styles into the head and keep them in one place after hydration (like isomorphic-style-loader). |
To be clear, you run some code that moves the styles to the You could also consider patching console.error for this specific warning (and patching only before generating the string, and undoing the patch right after), but I don't know what your product requirements are, or whether it'll be efficient for you. We're working on some newer ideas for server rendering, and will share them in the future. I'll close this issue for now, thank you for your question! |
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
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:
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).The text was updated successfully, but these errors were encountered: