segmentio / evergreen

🌲 Evergreen React UI Framework by Segment
https://evergreen.segment.com
MIT License
12.39k stars 832 forks source link

Non-Next.js SSR Example #1505

Closed avin-kavish closed 2 years ago

avin-kavish commented 2 years ago

How do I write SSR in just plain node.js?

renderToPipeableStream(createElement(App).
 {
    onShellReady() {
      res.statusCode = 200
      res.setHeader('Content-type', 'text/html')
      stream.pipe(res);
    }
)

I guess styles have to built somewhere here? Should I use the non-stream version instead? i.e. renderToString

brandongregoryscott commented 2 years ago

Hey @avin-kavish, I can't say I am super familiar with SSR but I think you'll still need to render the css string in a <style> tag in the head of the page, and render the hydration script in the body (both supplied by extractStyles), similar to the NextJS example. The hydration script is a React component instance, so you'll probably need to call renderToString on it when returning the HTML to the client.