Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@emotion/server

Package Overview
Dependencies
Maintainers
4
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@emotion/server

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

  • 11.11.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created

What is @emotion/server?

@emotion/server is a library that provides server-side rendering (SSR) utilities for Emotion, a popular CSS-in-JS library. It allows you to extract and inline critical CSS for your React components during server-side rendering, ensuring that styles are available immediately when the page loads.

What are @emotion/server's main functionalities?

renderStylesToString

This function takes the HTML string generated by React's renderToString and adds the necessary style tags to it. This ensures that the critical CSS is inlined in the HTML, improving the initial load performance.

const { renderStylesToString } = require('@emotion/server');
const React = require('react');
const { renderToString } = require('react-dom/server');
const App = require('./App');

const html = renderStylesToString(renderToString(<App />));
console.log(html);

renderStylesToNodeStream

This function works similarly to renderStylesToString but is designed for streaming. It takes a Node.js stream of HTML and adds the necessary style tags to it, allowing for more efficient server-side rendering in streaming scenarios.

const { renderStylesToNodeStream } = require('@emotion/server');
const React = require('react');
const { renderToNodeStream } = require('react-dom/server');
const App = require('./App');
const { PassThrough } = require('stream');

const stream = renderToNodeStream(<App />).pipe(renderStylesToNodeStream());
stream.pipe(process.stdout);

Other packages similar to @emotion/server

Keywords

FAQs

Package last updated on 06 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc