npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lib-core-mfe/fragment-frontend

v0.2.0

Published

Experimental server-rendered remote fragments for React: Provider streams HTML, Consumer embeds it, the browser hydrates with the Provider's own React.

Readme

@lib-core-mfe/fragment-frontend

Experimental. Server-rendered remote fragments for React micro-frontends.

The Provider renders a fragment on its own server and streams the HTML. The Consumer's server fetches it (server to server) and embeds it in the page. In the browser the fragment is hydrated by the Provider's own React; the Consumer's React never touches it.

Consumer server --GET /fragments/<name>?params--> Provider server
      |  (HTML stream + x-fragment-* headers)            renders with React
      v
page HTML = Consumer markup + fragment markup + serialized props
      |
Browser: Consumer hydrates its tree -> <FragmentSlot> loads the Provider bundle
         -> registry entry hydrates the fragment with the Provider's React

Provider

// server
import { createFragmentHandler } from "@lib-core-mfe/fragment-frontend/server";

app.use(createFragmentHandler({
  appName: "shop", // same as registerFragment
  fragments: {
    cart: {
      Component: Cart,
      clientScript: "/assets/cart.client.js",
      getProps: ({ params }) => ({ entityId: params.get("entityId") ?? "" }),
    },
  },
}));

// client bundle (served from clientScript)
import { registerFragment } from "@lib-core-mfe/fragment-frontend/provider";
registerFragment("cart", Cart, { appName: "shop" });

Props must be JSON-serializable: the same values render on the server and hydrate in the browser.

Consumer

// server: per request
import { fetchFragment } from "@lib-core-mfe/fragment-frontend/server";
const fragment = await fetchFragment({
  host: "https://provider.example.com",
  name: "cart",
  params: { entityId: "42" },
  allowedHosts: ["https://provider.example.com"], // required
});
const html = await fragment.html(); // or stream fragment.body
const { body, html: _h, ...info } = fragment; // `info` is small and JSON-safe

// page (server render passes `html`; the client passes only `info`)
import { FragmentSlot } from "@lib-core-mfe/fragment-frontend/consumer";
<FragmentSlot fragment={info} html={html} allowedHosts={["https://provider.example.com"]} />

Interactivity, failures and client rendering

  • Not clickable before it works. The Provider emits the fragment root with inert, aria-busy="true" and data-fragment-state="pending". FragmentSlot lifts them once the Provider's React has hydrated (data-fragment-state="ready"), so a form in server markup cannot be submitted natively before it is interactive. Opt out with createFragmentHandler({ inertUntilHydrated: false }).
  • Client-render fallback. With no server markup on the page, FragmentSlot renders the fragment in the browser through the bundle's mount, using the props you pass (the same shape getProps returns). A Consumer without a server, or one whose server could not reach the Provider, still shows the fragment.
  • Fallback and retry. A fatal error (script blocked or not registered, contract mismatch, nothing to render) or no attachment within timeoutMs (default 10 s, 0 disables) calls onError and, when fallback is set, renders it. retry starts a new attempt: it hydrates server markup if present, otherwise client-renders from props or the props read from the server markup. Recoverable hydration errors only reach onError: React already recovers.
  • Lifecycle. onHydrated fires after hydration; onReady(mode) fires after hydration ("hydrated") or a client render ("mounted"). Changing fragment.id tears down the old root and attaches the new fragment.
  • Styles. A fragment definition may set styles (URL relative to the Provider). It travels in x-fragment-styles, fetchFragment resolves it against the allowlist, and FragmentSlot places a <link rel="stylesheet"> before the markup, so server HTML is styled before the bundle runs.
<FragmentSlot
  fragment={info}
  html={html}
  props={{ entityId: "42" }}
  allowedHosts={["https://provider.example.com"]}
  timeoutMs={8000}
  fallback={({ retry }) => <button onClick={retry}>Try again</button>}
  onReady={(mode) => console.log("ready via", mode)}
/>

Status

Walking skeleton. Covered by tests: streaming with metadata headers, script-safe props, failures before streaming (500), allowlist, no redirects, contract check, timeout, and hydration without warnings (including StrictMode); inert markup until hydration, client-render fallback, fallback with retry and attach timeout, remount when the fragment changes, and stylesheet delivery inside the allowlist.

Not done: independent React across real bundles, Declarative Shadow DOM isolation, SRI enforcement, event bus, benchmark. See ADR 0001.

Security

A Provider script runs with the page's privileges, and its HTML is injected into the Consumer page. allowedHosts is a trust decision, not a sandbox. The Consumer's server-side fetch never follows redirects and refuses hosts outside the allowlist (SSRF).