New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

async-server-component

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-server-component

A sharable react component for re-rendering the server rendered html initially during the client render.

  • 1.0.2
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

async-server-component

A sharable react component for re-rendering the server rendered html initially during the client render.

This prevents a flash of unstyled content during rendering a dynamically imported component.

Taken from solutions provided in this issue in React.

This component is used for two different use cases:

Suspense on the server

Preserve the server rendered loading state when client component is dynamically imported:

import AsyncServerComponent from "async-server-component";
import { asyncComponent } from "react-async-component";

const Header = asyncComponent({
  resolve: () => import(/* webpackChunkName: 'header' */ "./header"),
  LoadingComponent: () => (
    <AsyncServerComponent asyncLoading={'[data-async-loading="header"]'} />
  ),
});

Server side treeshaking

If its possible to create a server and client version of a component, then <AsyncServerComponent /> can prevent a component from being loaded on the client, potentially reducing bundle size.

The example below conditionally renders the more expensive logged in version, but can it can be safely excluded for logged out users, reducing the bundle size:

const ServerComponent = ({ loggedIn }) => {
  return <div>{loggedIn ? <Header /> : <LoggedoutStaticHeader />}</div>;
};

const ClientComponent = ({ loggedIn }) => {
  return (
    <div>
      {loggedIn ? (
        <Header />
      ) : (
        <AsyncServerComponent asyncLoading={'[data-async-loading="header"]'} />
      )}
    </div>
  );
};

FAQs

Package last updated on 19 Sep 2020

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