import { ClientConfig, Renderer } from '@rondo.dev/client' import React from 'react' import { renderToNodeStream } from 'react-dom/server' import { Provider } from 'react-redux' import { StaticRouterContext } from 'react-router' import { StaticRouter } from 'react-router-dom' import ssrPrepass from 'react-ssr-prepass' import { Store } from 'redux' import { ServerStyleSheet } from 'styled-components' interface ComponentWithFetchData { fetchData(): Promise } export class ServerRenderer implements Renderer { constructor( readonly RootComponent: React.ComponentType, ) {} async render( url: string, store: Store, props: Props, config: ClientConfig, ) { const {RootComponent} = this // TODO set cookie in headers here... const context: StaticRouterContext = {} const sheet = new ServerStyleSheet() const element = sheet.collectStyles( , ) await ssrPrepass(element, async (el, component) => { if (component && 'fetchData' in component) { await (component as ComponentWithFetchData).fetchData() } }) const stream = sheet.interleaveWithNodeStream(renderToNodeStream(element)) return stream } }