Skip to main content

Mantle Icons Migration Guide

@ngrok/mantle no longer takes @phosphor-icons/react as a peer dependency. Its icons now come from @ngrok/mantle-icons, a fork of Phosphor Icons. Each icon is a plain SVG component with no React context and no "use client", so it renders in a React Server Component and ships no JavaScript to the browser. Each weight is its own component and module: CheckBoldIcon from @ngrok/mantle-icons/CheckBold replaces <CheckIcon weight="bold" />. There is no weight prop and no IconContext. This guide moves a codebase from @phosphor-icons/react to @ngrok/mantle-icons.

TL;DR: Change each @phosphor-icons/react/<Name> import to @ngrok/mantle-icons/<Name>, and each import type from @phosphor-icons/react to @ngrok/mantle-icons. Replace <CheckIcon weight="bold" /> with <CheckBoldIcon />, imported from @ngrok/mantle-icons/CheckBold, and delete weight="regular". Then replace @phosphor-icons/react with @ngrok/mantle-icons in package.json.

Codemod

From a mantle checkout:

pnpm -w run migrate mantle-icons <path>

In a project that installs @ngrok/mantle:

npx --yes --package=@ast-grep/cli@0.51.3 ast-grep scan --rule node_modules/@ngrok/mantle/dist/migrations/mantle-icons.yml --update-all <path>

The rules apply steps 2 to 4. They move each icon import and each import type from the barrel. On an icon with a literal weight ("bold", 'bold', or {"bold"}), they rename the element to the weight component, add its import, and delete the prop. They delete weight="regular". The rules read an icon through its import, under its own *Icon name. An aliased import (import { CheckIcon as Check }), a computed weight, an icon passed as a value with a weight, a value import from the barrel, and IconContext stay manual: steps 5 to 7. The rules keep the import of an icon whose every element took a weight, so step 8 removes the imports the linter reports unused. The codemod can run again: a migrated icon has no weight to match. Pass --dry-run to print the rewrites first, and run your formatter after the rewrite.


You are an agent migrating a codebase. Do this:

  1. Find every import from @phosphor-icons/react: the icon modules (@phosphor-icons/react/Check), the barrel (@phosphor-icons/react), and the ssr and dist paths.
  2. Change each icon import to the same name under @ngrok/mantle-icons: import { CheckIcon } from "@phosphor-icons/react/Check" becomes import { CheckIcon } from "@ngrok/mantle-icons/Check". The ssr and dist/csr paths become the same @ngrok/mantle-icons/<Name> path.
  3. Change each import type { Icon, IconProps, IconWeight } from "@phosphor-icons/react" to @ngrok/mantle-icons. The names stay.
  4. For each icon element with a literal weight, render the weight component: <CheckIcon weight="bold" /> becomes <CheckBoldIcon />, imported from @ngrok/mantle-icons/CheckBold. The suffixes are Thin, Light, Bold, Fill, and Duotone. Delete weight="regular": the component without a suffix is the regular weight.
  5. For a computed weight, render one component for each weight: <MicrophoneIcon weight={on ? "fill" : "regular"} /> becomes {on ? <MicrophoneFillIcon /> : <MicrophoneIcon />}. For an icon passed as a value and rendered with a weight (<item.icon weight="fill" />), pass the weight component as the value and delete the prop.
  6. Rename an aliased import by hand, the same as steps 2 and 4: import { WarningIcon as Warning } with <Warning weight="fill" /> becomes import { WarningFillIcon as Warning } from "@ngrok/mantle-icons/WarningFill" with <Warning />.
  7. Delete each IconContext.Provider, and set its weight on each icon inside it (step 4), its size and color with className (size-4, text-muted) or the size and color props, and its mirrored with the mirrored prop. Replace a value import from the barrel (import { CheckIcon } from "@phosphor-icons/react") with the icon's own module, as in step 2.
  8. Replace @phosphor-icons/react with @ngrok/mantle-icons in package.json (pnpm add -E @ngrok/mantle-icons). Remove @phosphor-icons/react from package.json, and from any bundler setting that names it, such as Vite's ssr.noExternal or optimizeDeps. Remove mantlePhosphorPrunePlugin() from the Vite config: each weight is its own module, so a bundle holds only the weights it renders.
  9. In tests:
    • A test that renders an icon with weight renders the weight component, the same as step 4: <CheckIcon weight="bold" /> becomes <CheckBoldIcon />.
    • A test that reads the rendered <svg> reads the same markup: the paths, viewBox, width, height, and fill are the same as @phosphor-icons/react rendered.
  10. After editing, run the project's formatter, linter (which removes the imports left unused by step 4), type checker, and tests.

Why a component for each weight? Each @phosphor-icons/react icon holds the paths of all six weights and reads IconContext, a React context, so a bundle ships every weight and the icon can only render as client code. A component for each weight holds one set of paths and reads no context, so a bundle holds only what a page renders, and the icon renders in a React Server Component with no client JavaScript.


Before → after

An icon at the regular weight

// BEFORE
import { GearIcon } from "@phosphor-icons/react/Gear";
 
<GearIcon className="size-4" />;
// AFTER
import { GearIcon } from "@ngrok/mantle-icons/Gear";
 
<GearIcon className="size-4" />;

An icon with a weight

// BEFORE
import { CheckIcon } from "@phosphor-icons/react/Check";
 
<CheckIcon weight="bold" className="size-4" />;
// AFTER
import { CheckBoldIcon } from "@ngrok/mantle-icons/CheckBold";
 
<CheckBoldIcon className="size-4" />;

A computed weight

// BEFORE
import { MicrophoneIcon } from "@phosphor-icons/react/Microphone";
 
<MicrophoneIcon weight={listening ? "fill" : "regular"} />;
// AFTER
import { MicrophoneIcon } from "@ngrok/mantle-icons/Microphone";
import { MicrophoneFillIcon } from "@ngrok/mantle-icons/MicrophoneFill";
 
{
	listening ? <MicrophoneFillIcon /> : <MicrophoneIcon />;
}

A prop that takes an icon

// BEFORE
import type { Icon } from "@phosphor-icons/react";
import { GearIcon } from "@phosphor-icons/react/Gear";
 
type NavItem = { label: string; icon: Icon };
const items: NavItem[] = [{ label: "Settings", icon: GearIcon }];
// AFTER
import type { Icon } from "@ngrok/mantle-icons";
import { GearIcon } from "@ngrok/mantle-icons/Gear";
 
type NavItem = { label: string; icon: Icon };
const items: NavItem[] = [{ label: "Settings", icon: GearIcon }];

Edge cases & gotchas

  • The ref, className, alt, color, size, and mirrored props stay. Each icon takes every <svg> attribute.
  • An icon in a server component stays server code. A module that imports an icon no longer needs "use client" for it. Keep the directive when the module has its own hooks or event handlers.
  • Mantle's own icons ignore IconContext. A IconContext.Provider around mantle parts changed nothing you can rely on before, and changes nothing now.

How to verify

Search the codebase for @phosphor-icons/react and weight= on icons: nothing should remain. Run the formatter, the linter, the type checker, and the tests (see step 9).