From 1ca355a560e1d445c831f9c01d54440ac74016da Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Wed, 28 Oct 2026 12:10:34 +0100 Subject: [PATCH] chore: remove obsolete rehypeAnimate name workaround Follow-up to #702. Before #702 the processor cache keyed plugins by `fn.name`, so `createAnimatePlugin` renamed each `rehypeAnimate` closure to `rehypeAnimate$` to avoid cache collisions. The cache now keys plugins by function identity (`getPluginId`), so each closure already gets its own key. This removes the `instanceId` counter and the `Object.defineProperty` override. The returned plugin object stays the same. Also: - Extends the unreleased `quiet-plugins-render` changeset with a note on the behavior change: plugin functions created during render now produce a new processor on each render. Create them once (module scope or `useMemo`) to keep cache hits. - Adds a patch changeset for this cleanup. --- .changeset/plain-animate-name.md | 5 +++++ .changeset/quiet-plugins-render.md | 2 +- packages/streamdown/lib/animate.ts | 7 ------- 3 files changed, 6 insertions(+), 8 deletions(-) create mode 100644 .changeset/plain-animate-name.md diff --git a/.changeset/plain-animate-name.md b/.changeset/plain-animate-name.md new file mode 100644 index 00000000..c826ff09 --- /dev/null +++ b/.changeset/plain-animate-name.md @@ -0,0 +1,5 @@ +--- +"streamdown": patch +--- + +Remove the obsolete rehypeAnimate name override; processor caching now uses function identity. diff --git a/.changeset/quiet-plugins-render.md b/.changeset/quiet-plugins-render.md index 5ada25f2..7d28c5ec 100644 --- a/.changeset/quiet-plugins-render.md +++ b/.changeset/quiet-plugins-render.md @@ -2,4 +2,4 @@ "streamdown": patch --- -Distinguish remark and rehype plugins by function identity when caching processors, so same-name plugins with different closures do not reuse each other's behavior. +Distinguish remark and rehype plugins by function identity when caching processors, so same-name plugins with different closures do not reuse each other's behavior. Apps that create plugin functions during render now get a new processor on each render. This is slower for that pattern but does not grow memory; create plugins once (module scope or `useMemo`) to keep cache hits. diff --git a/packages/streamdown/lib/animate.ts b/packages/streamdown/lib/animate.ts index 642a2566..ac80861b 100644 --- a/packages/streamdown/lib/animate.ts +++ b/packages/streamdown/lib/animate.ts @@ -590,8 +590,6 @@ const processTextNode = ( return index + nodes.length; }; -let instanceId = 0; - /** * Create an animate rehype plugin. The optional `timeline` is an internal * Streamdown wiring detail — not part of the public `animated` prop surface. @@ -636,7 +634,6 @@ function buildAnimatePlugin( pendingMark: null, }; - const id = instanceId++; const rehypeAnimate = () => (tree: Root) => { const charCounter = { count: 0, newIndex: 0 }; @@ -692,10 +689,6 @@ function buildAnimatePlugin( renderState.prevContentLength = 0; }; - Object.defineProperty(rehypeAnimate, "name", { - value: `rehypeAnimate$${id}`, - }); - return { name: "animate", type: "animate",