Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/fix-mermaid-hard-dep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"streamdown": patch
---

fix(deps): remove `mermaid` as a hard runtime dependency

`mermaid` was listed in `dependencies` but the core `streamdown` package
only imports it as a type (`import type { MermaidConfig }`). The actual
mermaid runtime is exclusively used by the optional `@streamdown/mermaid`
plugin — pulling ~75 MB into every install unnecessarily.

This patch replaces the type import with a local structural type for
`MermaidConfig` so no type-level coupling to the `mermaid` package remains
in the distributed typings. Users who want fully-typed mermaid config can
still `import type { MermaidConfig } from 'mermaid'` themselves; the
structural type is compatible.

Fixes #501
3 changes: 1 addition & 2 deletions packages/streamdown/__tests__/mermaid.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { render, waitFor } from "@testing-library/react";
import type { MermaidConfig } from "mermaid";
import { act } from "react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { Mermaid } from "../lib/mermaid";
import { MermaidDownloadDropdown } from "../lib/mermaid/download-button";
import { MermaidFullscreenButton } from "../lib/mermaid/fullscreen-button";
import { PluginContext } from "../lib/plugin-context";
import type { DiagramPlugin } from "../lib/plugin-types";
import type { DiagramPlugin, MermaidConfig } from "../lib/plugin-types";

const { saveMock, mockInitialize, mockRender, mockMermaid } = vi.hoisted(() => {
const mockInitialize = vi.fn();
Expand Down
7 changes: 5 additions & 2 deletions packages/streamdown/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";

import type { MermaidConfig } from "mermaid";
import {
type ComponentProps,
type CSSProperties,
Expand Down Expand Up @@ -33,7 +32,11 @@ import { hasIncompleteCodeFence, hasTable } from "./lib/incomplete-code-utils";
import { type ExtraProps, Markdown, type Options } from "./lib/markdown";
import { parseMarkdownIntoBlocks } from "./lib/parse-blocks";
import { PluginContext } from "./lib/plugin-context";
import type { PluginConfig, ThemeInput } from "./lib/plugin-types";
import type {
MermaidConfig,
PluginConfig,
ThemeInput,
} from "./lib/plugin-types";
import { PrefixContext } from "./lib/prefix-context";
import { preprocessCustomTags } from "./lib/preprocess-custom-tags";
import { preprocessLiteralTagContent } from "./lib/preprocess-literal-tag-content";
Expand Down
2 changes: 1 addition & 1 deletion packages/streamdown/lib/mermaid/download-button.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { MermaidConfig } from "mermaid";
import { useContext, useEffect, useRef, useState } from "react";
import { StreamdownContext } from "../../index";
import { useIcons } from "../icon-context";
import { useMermaidPlugin } from "../plugin-context";
import type { MermaidConfig } from "../plugin-types";
import { useCn } from "../prefix-context";
import { useTranslations } from "../translations-context";
import { save } from "../utils";
Expand Down
2 changes: 1 addition & 1 deletion packages/streamdown/lib/mermaid/fullscreen-button.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { MermaidConfig } from "mermaid";
import { type ComponentProps, useContext, useEffect, useState } from "react";
import { createPortal } from "react-dom";
import { StreamdownContext } from "../../index";
import { useIcons } from "../icon-context";
import type { MermaidConfig } from "../plugin-types";
import { useCn } from "../prefix-context";
import { lockBodyScroll, unlockBodyScroll } from "../scroll-lock";
import { useTranslations } from "../translations-context";
Expand Down
2 changes: 1 addition & 1 deletion packages/streamdown/lib/mermaid/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { MermaidConfig } from "mermaid";
import { useContext, useEffect, useState } from "react";
import { useDeferredRender } from "../../hooks/use-deferred-render";
import { StreamdownContext } from "../../index";
import { useMermaidPlugin } from "../plugin-context";
import type { MermaidConfig } from "../plugin-types";
import { useCn } from "../prefix-context";
import { PanZoom } from "./pan-zoom";

Expand Down
10 changes: 9 additions & 1 deletion packages/streamdown/lib/plugin-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import type { MermaidConfig } from "mermaid";
/**
* Structural type for Mermaid configuration.
* Avoids a hard dependency on the "mermaid" package in the core bundle.
* Users who need full type safety can import MermaidConfig from "mermaid"
* directly — it is structurally compatible with this type.
*/
// biome-ignore lint/suspicious/noExplicitAny: structural pass-through for mermaid config
export type MermaidConfig = Record<string, any>;

import type React from "react";
import type {
BundledLanguage,
Expand Down
1 change: 0 additions & 1 deletion packages/streamdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"remend": "workspace:*",
"tailwind-merge": "^3.4.0",
"unified": "^11.0.5",
"mermaid": "^11.12.2",
"unist-util-visit": "^5.0.0",
"unist-util-visit-parents": "^6.0.0"
}
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading