<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="172775" data-post-id="172775">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="harmon25" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/harmon25/120/1274_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  harmon25
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Just added release functionality to the repo above, and published it to a 5$ Linode instance to test it out.</p>
<p>Check it out here: <a href="https://nomrah.dev" rel="noopener nofollow ugc">https://nomrah.dev</a></p>
<p>I left the <a href="https://nomrah.dev/dashboard" rel="noopener nofollow ugc">dashboard</a> open in production to let people see that too…</p>
<p>The app is behind HAproxy, so IPs of users are not public. Is that enough? Or should i be worried about something else when leaving the dashboard public?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="172775" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/reactrender-server-side-rendering-for-react-components/14706/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-172775" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="172775"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="173417" data-post-id="173417">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Harrisonl" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Harrisonl/120/11714_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Harrisonl
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/harmon25" rel="nofollow">@harmon25</a> Looks great! is this the same model that NextJS et al use? From looking through the code here, the phoenix side will render an empty html page and then render the <code>&lt;ServerContainer /&gt;</code> component which contains the app, hyrdated with data passed from the server. This is then ‘hydrated’ on the client side using the props passed from the server - is this all correct?</p>
<p>My question is then, when is the <code>&lt;ClientContainer /&gt;</code> rendered?</p>
<p>Also once that initial page is rendered, is it pretty much from then on the same as an SPA?  E.g. routing will all take place client side and no more SSR will occur?</p>
<p>I’m guessing the main benefit here (I usually do SPA + GQL API Phoenix) is that it eliminates the need for the intial page fetch from CDN (e.g. netlify) → render → fetch data from api (show loading states) → then show data</p>
<p>and rather:</p>
<p>page loads directly from server → initial data passed to react component → component rendered already with data ?</p>
<p>Just want to make sure I understand this right - so whilst the actual content is no longer served as a single static JS Bundle (typically to a CDN close to the user), it should be faster because it eliminates the need for CDN call + API call (and most likely CORS) and can instead can all be delivered in a single round trip?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="173417" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/reactrender-server-side-rendering-for-react-components/14706/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-173417" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="173417"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="173486" data-post-id="173486">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="harmon25" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/harmon25/120/1274_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  harmon25
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi <a class="mention" href="/u/harrisonl" rel="nofollow">@Harrisonl</a>,<br>
Thanks for checking it out!</p>
<p>Yea it is pretty similar to NextJS, but NextJS is IMO better suited for something fully static, and served entirely from CDN, or maybe the new serverless idea they are pushing. But deploying NextJS as part of an Express application or the like is not recommended, because of the <a href="https://reactjs.org/docs/react-dom-server.html#reference" rel="noopener nofollow ugc">synchronous rendering</a> of React components to a string in Node.</p>
<p>Thing is, I need/want to reach down to the underlying HTTP constructs for security purposes, like cookies, CSRF, redirects, server side auth etc..</p>
<p>This pattern lets me leverage Phoenix/Plug and its great patterns and structure for managing HTTP/API concerns, and delegating the UI/UX to server rendered + client hydrated React. Which despite its pitfalls, has enormous engineering effort/community behind it…</p>
<p>I currently work on a team that has too much React experience to toss it away. As much as I love the idea of LiveView; I also appreciate the inherent separation between front and back-end code the SPA pattern benefits from, and how it allows for teams that can specialize in say React or Elixir.</p>
<p>To directly answer the questions:<br>
<code>&lt;ClientContainer  /&gt;</code> is used to <a href="https://github.com/harmon25/react_render_demo/blob/react_router/assets/js/app.js#L13" rel="noopener nofollow ugc">hydrate React on the client</a>. This is necessary because certain React provider components, namely react-routers <code>StaticRouter</code> vs <code>BrowserRouter</code>.</p>
<p>The <code>StaticRouter</code> is used for server rendering and pretty much just takes a location(path) as a prop, and figures out what page of the React app to render. The linked example is using a <a href="https://github.com/harmon25/react_render_demo/blob/react_router/lib/react_render_demo_web/router.ex#L42" rel="noopener nofollow ugc">wildcard phoenix route</a>,to pass the <code>conn.request_path</code> into the <code>ServerContainer</code> so it <a href="https://github.com/harmon25/react_render_demo/blob/react_router/lib/react_render_demo_web/controllers/page_controller.ex#L7" rel="noopener nofollow ugc">knows what page to render.</a></p>
<p>The <code>ClientContainer</code> uses BrowserRouter, which is actually hooked up to the browsers push state history stuff and grabs its location from the URL bar.</p>
<p>So yes, the component is rendered on the server with the data you provide it.<br>
During rendering the component on the server, it could also do some data fetching from within the servers node environment.</p>
<p>It is still possible to deliver the <code>app.js</code>, and <code>app.css</code> webpack bundles over CDN, just not the rendered HTML page. And yes, the app can be bootstrapped entirely on the server, removing the need for a initial API call to understand who is on the page or for critical data for example.</p>
<p>The rendered HTML could be cached in Elixir - but depending on the state it is hydrated with - e.g private user information. It might not be a good idea to be naively caching it, it does however have a pretty substantial performance improvement if it was necessary.</p>
<p>Happy to answer any more questions!</p>
<p>Oh, and to clarify phoenix actually returns the rendered react component - so not an empty html page. You can verify this when looking at the data over the network, or the initial page load.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="173486" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/reactrender-server-side-rendering-for-react-components/14706/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-173486" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="173486"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="173492" data-post-id="173492">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Harrisonl" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Harrisonl/120/11714_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Harrisonl
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks for super detailed reply! That definitely cleared it up.</p>
<p>I’m in a very similar boat RE team with a lot of react experience and am actually a big fan of react itself and don’t want to introduce a completely new technology (LiveView) until it’s more battle-tested with a bigger eco-system behind it. Although I do want to find some ways to increase performance and remove some of the pain’s associated with SPA + API’s for a bit faster dev cycle, hence the digging into SSR react.</p>
<p>Just the last question I had is once the server has loaded the app and rendered the front end, is it for all intents and purposes an SPA? E.g. client side routing and not every route goes through the whole server side rendered flow again. Sorry for the basic questions - never actually done SSR react, always been SPA so some of this stuff is quite new to me!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="173492" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/reactrender-server-side-rendering-for-react-components/14706/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-173492" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="173492"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="173495" data-post-id="173495">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="harmon25" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/harmon25/120/1274_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  harmon25
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yes exactly!<br>
Once the client is hydrated, and you are using <code>BrowserRouter</code> or the like, React just picks up from there.</p>
<p>This works pretty well with the phoenix wildcard, because you can still refresh the page and trigger the server render. But a regular user navigating via react router links etc will be back in full spa land pretty much. You can see this by navigating between the / and /profile routes on the demo: <a href="https://nomrah.dev/" rel="noopener nofollow ugc">https://nomrah.dev/</a></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="173495" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/reactrender-server-side-rendering-for-react-components/14706/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-173495" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="173495"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #17"></div>
  </section>
</div>
    <div class="postbit" id="174742" data-post-id="174742">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Harrisonl" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Harrisonl/120/11714_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Harrisonl
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/harmon25" rel="nofollow">@harmon25</a> Thanks for all the answers! Trying this out on a sideproject and ran into a few issues (mainly with console.log but saw your comment thread on the original repo and that worked a charm) - just wondering if you have any ideas on using WebSockets in the app? Since <code>WebSocket</code> <a href="https://stackoverflow.com/questions/43311238/javascript-referenceerror-websocket-is-not-defined" rel="noopener nofollow ugc">is only included in the client side </a> I am getting an <code>Cannot read property 'WebSocket' of undefined</code> which makes sense. I’m not so familiar with the hyrdation flow, but would it be trivial to say delay the execution of the webhook logic until the client side hydration begins?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="174742" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/reactrender-server-side-rendering-for-react-components/14706/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-174742" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="174742"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="174744" data-post-id="174744">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="harmon25" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/harmon25/120/1274_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  harmon25
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I actually just responded in the original repo with some thoughts on that: <a href="https://github.com/revelrylabs/elixir_react_render/issues/44" class="inline-onebox" rel="noopener nofollow ugc">Some Questions + running in a release/production · Issue #44 · revelrylabs/elixir_react_render · GitHub</a></p>
<p>Here is an example of how i was able to get the node ssr process to connect back to the phoenix socket.<br>
It only required an isomorphic WebSocket in the right place for phoenix to know how to instantiate the phoenix channel socket.</p>
<p>In looking closer at the phoenix source it looks like <code>WebSocket</code> could be passed into the phoenix socket constructor as the <code>transport</code> option - rather than hacking global like i did <img src="https://forum.elixirforum.com/images/emoji/apple/stuck_out_tongue.png?v=15" title=":stuck_out_tongue:" class="emoji" alt=":stuck_out_tongue:" loading="lazy" width="20" height="20"></p>
<aside class="onebox githubblob" data-onebox-src="https://github.com/harmon25/react_render_demo/blob/channel_logger/assets/render_server.js">
  <header class="source">

      <a href="https://github.com/harmon25/react_render_demo/blob/channel_logger/assets/render_server.js" target="_blank" rel="noopener nofollow ugc">github.com/harmon25/react_render_demo</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://github.com/harmon25/react_render_demo/blob/channel_logger/assets/render_server.js" target="_blank" rel="noopener nofollow ugc">assets/render_server.js</a></h4>

<div class="git-blob-info">
  <a href="https://github.com/harmon25/react_render_demo/blob/channel_logger/assets/render_server.js" rel="noopener nofollow ugc"><code>channel_logger</code></a>
</div>


      <pre><code class="lang-js">const WebSocket = require("isomorphic-ws");
// inject websocket into global, so phoenix can use it.
global.window = { WebSocket };
const { Socket } = require("phoenix");

let socket = new Socket("http://localhost:4000/logger-socket", {
  params: { token: "atoken?" },
});

socket.connect();

// Now that you are connected, you can join channels with a topic:
let channel = socket.channel("ssr_logs:all", {});
channel
  .join()
  .receive("ok", (resp) =&gt; {
    // console.log("Joined successfully", resp);
  })
  .receive("error", (resp) =&gt; {
    // console.log("Unable to join", resp);
</code></pre>



  This file has been truncated. <a href="https://github.com/harmon25/react_render_demo/blob/channel_logger/assets/render_server.js" target="_blank" rel="noopener nofollow ugc">show original</a>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>To more directly answer your question:<br>
I think a conscious decision should be made on what data you want to have available for the SSR, and thus rendered on the server vs the data that will be fetched async once the client bootstraps.</p>
<p>I would also separate out the phoenix socket/channel logic from the content being server rendered via some indirection through redux or something similar. This would allow you to not include that client code when you SSR, and maybe just hydrate redux state or something on the server, and not have to worry about how it got there.</p>
<p>In your app.js file is where you have the socket code, and maybe add extra redux middleware to manage channel data when running in the browser vs on the the static server render.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="174744" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/reactrender-server-side-rendering-for-react-components/14706/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-174744" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="174744"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #19"></div>
  </section>
</div>
    <div class="postbit" id="174941" data-post-id="174941">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Harrisonl" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Harrisonl/120/11714_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Harrisonl
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Can’t seem to edit my post, but I did find a solution. The above bug occurs because it the <code>phoenix.js</code> library attempts to call <code>location</code> which I am assuming is not defined in the node runtime and is browser specific.</p>
<p>You can replicate this <a class="mention" href="/u/harmon25" rel="nofollow">@harmon25</a> by adding a test channel in your app, and then importing the <code>socket.js</code> file in your index page.</p>
<p>The solution, is quite simple, but basically you need to change:</p>
<pre data-code-wrap="js"><code class="lang-js">const socket = new Socket("/socket", {});
</code></pre>
<pre data-code-wrap="js"><code class="lang-js">let socket = new Socket("ws://localhost:4000/socket", {});
</code></pre>
<p>Which then bypasses the <code>location</code> calls and the app will compile correctly.</p>
<p>My only concern is that this will be an ongoing theme where the react app expects there to be a browser runtime present (e.g. through libraries etc.) and cause these issues.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="174941" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/reactrender-server-side-rendering-for-react-components/14706/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-174941" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="174941"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #21"></div>
  </section>
</div>
    <div class="postbit" id="174950" data-post-id="174950">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="harmon25" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/harmon25/120/1274_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  harmon25
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Started writing this in the AM, and then got busy with work…</p>
<p>If you are not using redux or some global state thing, the right approach would be a context in the ClientContainer.</p>
<p><a href="https://gist.github.com/harmon25/e94bafe546002ad1379d2f6f8f3259fa" rel="noopener nofollow ugc">Here is a gist of what that might look like.</a></p>
<p>Not tested, but should work.</p>
<p>You could combine the above with a ChannelContext that was responsible for managing and communicating the channel data/status to child components.</p>
<p>This should be imported on the client container, or maybe app.js, but not in components down the tree that end up on the server render. Which is the problem I think you are having… this websocket stuff will not work in the context of node without some help - like the channel logger I linked above.</p>
<p>It can be done for sure - but if you have an authenticated socket, that authentication would need to be considered when connected back to localhost from the server render node process..</p>
<p>Take a look at the kinda hoops are required for hydrating state in apollo for example:</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://www.apollographql.com/docs/react/performance/server-side-rendering">
  <header class="source">
      <img src="https://www.apollographql.com/docs/favicon.svg" class="site-icon" alt="" width="238" height="238">

      <a href="https://www.apollographql.com/docs/react/performance/server-side-rendering" target="_blank" rel="noopener nofollow ugc">Apollo GraphQL Docs</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/360;"><img src="https://res.cloudinary.com/apollographql/image/upload/w_1280,h_669,c_fill,q_auto,f_auto/w_1020,c_fit,co_rgb:FFEADB,g_south_west,x_90,y_300,l_text:odyssey:fonts:AeonikBold.otf_80:Server-side%20rendering/docs-og-image_bgfoyk" class="thumbnail" alt="" width="690" height="360"></div>

<h3><a href="https://www.apollographql.com/docs/react/performance/server-side-rendering" target="_blank" rel="noopener nofollow ugc">Server-side rendering</a></h3>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>As you point out, this is a bit challenging if you are doing stuff with sockets all over your tree..this is why i suggest very carefully locating the socket related code - and you probably will need to use something like redux to hook it up with react properly - or else you will have re-renders all over the place…</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="174950" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/reactrender-server-side-rendering-for-react-components/14706/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-174950" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="174950"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>