Legacy package for 1.x styletron-server

Downloads in past


2.6.16 years ago7 years agoMinified + gzip package size for styletron-server-legacy in KB


!build statusbuild-badgebuild-href !dependencies statusdeps-badgedeps-href !npm versionnpm-badgenpm-href
A server-rendering helper module for styletron


Extracting "injected" CSS at render-time on the server

const styletronServer = require('styletron-server');

const renderApp = function mockRenderFn() {
   * `renderApp` is some function that renders your app, returning a string of HTML. 
   * This function should also result in `injectOnce` being called at some point.

const {html, css, hydrationSrc} = styletronServer.renderStatic(() => {
  const html = renderApp();
  return html;

 * `html` is simply the return value of the function passed into `renderStatic`.
 * It is passed through for convenience.

 * `css` is a string containing all CSS that was that injected into the buffer
 * during the render.

 * `hydrationSrc` is a string of JS source code to hydrate styletron on the client.
 * This script injects a <style> element containing the server-rendered styles and also 
 * prevents re-injection of server-rendered styles on subsequent client renders.
 * Set this string as the contents of a <script> element in <head> so it is before <body>
 * and your client bundle.