How to use the emotion-server.extractCritical function in emotion-server

To help you get started, we’ve selected a few emotion-server examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wp-pwa / wp-pwa / core / pwa / server / index.js View on Github external
packages: activatedPackages,
      }),
    );
    store.dispatch(settingsModule.actions.settingsUpdated({ settings }));

    // Run and wait until all the server sagas have run.
    const startSagas = new Date();
    const sagaPromises = Object.values(serverSagas).map(saga => store.runSaga(saga).done);
    store.dispatch(buildModule.actions.serverSagasInitialized());
    await Promise.all(sagaPromises);
    store.dispatch(buildModule.actions.serverFinished({ timeToRunSagas: new Date() - startSagas }));

    // Generate React SSR.
    app = renderToString();

    const { html, ids, css } = extractCritical(app);

    // Get static helmet strings.
    const helmet = Helmet.renderStatic();

    // Flush chunk names and extract scripts, css and css<->scripts object.
    const chunkNames = flushChunkNames();
    const { cssHashRaw, scripts, stylesheets } = flushChunks(clientStats, { chunkNames });

    const publicPath = req.query.static
      ? `${req.query.static.replace(/\/$/g, '')}/static/`
      : '/static/';
    const cssHash = JSON.stringify(mapValues(cssHashRaw, cssPath => `${publicPath}${cssPath}`));
    const scriptsWithoutBootstrap = scripts.filter(script => !/bootstrap/.test(script));
    const chunksForArray = scriptsWithoutBootstrap.map(script => `'${script}'`).join(',');
    const bootstrapFileName = scripts.filter(script => /bootstrap/.test(script));
    const bootstrapString = await readFile(
github gatsbyjs / gatsby / packages / gatsby-plugin-emotion / src / gatsby-ssr.js View on Github external
export const replaceRenderer = ({
  bodyComponent,
  replaceBodyHTMLString,
  setHeadComponents,
}) => {
  const { html, ids, css } = extractCritical(
    renderToString(wrapElement(bodyComponent))
  )

  setHeadComponents([
    // eslint-disable-next-line react/jsx-key
    <style data-emotion-css="{ids.join(`">,
  ])

  replaceBodyHTMLString(html)
}
</style>
github cloudflare / color / pages / _document.js View on Github external
static getInitialProps({ renderPage }) {
    const page = renderPage()
    const styles = extractCritical(page.html)
    return { ...page, ...styles }
  }
github timberio / gitdocs / src / core / template.js View on Github external
function templateForProduction (entrypoints, props, route) {
  process.env.NODE_ENV = 'production'

  const hijacked = hijackConsole()
  const serverEntry = babelRequire('../../themes/server.js')
  const app = serverEntry.default(props, route)
  const rendered = extractCritical(renderToString(app))

  hijacked.restore()

  const helmet = Helmet.renderStatic()
  const template = `
    
    
      
        ${helmet.title.toString()}
        ${helmet.base.toString()}
        ${helmet.meta.toString()}
        ${helmet.link.toString()}
        ${helmet.style.toString()}
        ${helmet.script.toString()}

        <style type="text/css">${rendered.css}</style>
github O-clock-Alumni / DeviensDev / gatsby-ssr.js View on Github external
export const replaceRenderer = ({
  bodyComponent,
  replaceBodyHTMLString,
  setHeadComponents,
}) =&gt; {
  const ConnectedBody = () =&gt; &lt;&gt;{bodyComponent};

  const { html, ids, css } = extractCritical(renderToString());
  const criticalStyle =
github primer / design / pages / _document.js View on Github external
static getInitialProps({renderPage}) {
    const sheet = new ServerStyleSheet()
    const page = renderPage(App =&gt; props =&gt; sheet.collectStyles())
    return {
      ...page,
      styles: (
        &lt;&gt;
          
          
          {sheet.getStyleElement()}
        
      )
    }
  }
github jimmylee / next-express-emotion / pages / _document.js View on Github external
static getInitialProps({ renderPage }) {
    const page = renderPage();
    const styles = extractCritical(page.html);
    return { ...page, ...styles };
  }
github saltyshiomix / react-ssr / packages / express / entry.js View on Github external
const hydrateByEmotion = (html) => {
  const { hydrate } = require('emotion');
  const { extractCritical } = require('emotion-server');
  const { ids } = extractCritical(html);
  hydrate(ids);
};
github expo / expo-cli / packages / dev-tools / pages / _document.js View on Github external
static getInitialProps({ renderPage }) {
    const page = renderPage();
    const styles = extractCritical(page.html);
    return { ...page, ...styles };
  }
github ChristopherBiscardi / gatsby-mdx / examples / kitchen-sink / gatsby-ssr.js View on Github external
export const wrapRootElement = ({ element } /*, options*/) =&gt; {
  const string = renderToString({element});
  emotionSSR = extractCritical(string);
  return {element};
};

emotion-server

Extract and inline critical css with emotion for server side rendering.

MIT
Latest version published 4 years ago

Package Health Score

72 / 100
Full package analysis