<p dir="auto">I was wondering how it's the best way to render server-side (without rendering this on the client) AND handle the state changes. What I mean here is how to get the HTML from a server component that has a state changing.</p>
<p dir="auto">Example:</p>
<ol dir="auto">
<li>A server gets a requests to generate an HTML</li>
<li>The server 'requires' a react component, passing some props</li>
<li>The react component renders in the server, but it has to do an Ajax/Socket query to get some info. The event is sent and the response comes later.</li>
<li>The react component changes the state, changing the output</li>
<li>The HMTL generated is ready and with the latest state changes.</li>
</ol>
<p dir="auto">What's happening here is that ReactDOM.renderToStaticMarkup(), as expected, doesn't wait for the component to finish the state changes (in this case, wait for the data and re-render).</p>
<p dir="auto">How can I achieve this? Doing all the queries first and passing all the data as props? Is this the only way?</p>
<p dir="auto">Thanks!</p>
<p dir="auto"><strong>Do you want to request a <em>feature</em> or report a <em>bug</em>?</strong></p>
<p dir="auto">Bug.</p>
<p dir="auto"><strong>What is the current behavior?</strong></p>
<p dir="auto">render() runs immediately only when provided unique props or on initial, main-parent rendering component, in v. 16.4.0.</p>
<p dir="auto"><strong>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 (<a href="https://jsfiddle.net/Luktwrdm/" rel="nofollow">https://jsfiddle.net/Luktwrdm/</a>) or CodeSandbox (<a href="https://codesandbox.io/s/new" rel="nofollow">https://codesandbox.io/s/new</a>) example below:</strong></p>
<p dir="auto">When render() executed immediately after being called, it followed a code path through shouldComponentUpdate(), and when it has delayed execution because of non-unique props, it followed a code path through componentWillMount().</p>
<p dir="auto">When it worked: shouldComponentUpdate() immediately ran after calling ReactDOM.render(childcomponent, parentcomponent);.</p>
<p dir="auto">When it didn't work: componentWillMount() ran after the current function of the parentcomponent had finished executing.</p>
<p dir="auto">Please let me know if this is insufficient info.</p>
<p dir="auto"><strong>What is the expected behavior?</strong></p>
<p dir="auto">In ReactJS, 15.6.2, render() always runs, and runs immediately, whether its props are unique or not.</p>
<p dir="auto"><strong>Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?</strong></p>
<p dir="auto">This was last working in 15.6.2.  It is not working in 16.4.0.</p>