Skip to content

Wire onCopy/onError on default code-block copy controls - #612

Open
ShobhanKarthish wants to merge 1 commit into
vercel:mainfrom
ShobhanKarthish:fix/streamdown-default-copy-callbacks
Open

Wire onCopy/onError on default code-block copy controls#612
ShobhanKarthish wants to merge 1 commit into
vercel:mainfrom
ShobhanKarthish:fix/streamdown-default-copy-callbacks

Conversation

@ShobhanKarthish

Copy link
Copy Markdown

Summary

  • Extend ControlsConfig with CopyControlConfig so controls.code.copy / controls.mermaid.copy can be { onCopy, onError } (still accepts boolean).
  • Thread those callbacks into the default-rendered CodeBlockCopyButton via getCopyCallbacks.
  • Add unit and integration coverage for callback extraction and default control wiring.

Hosts using default controls can now surface copy failures and hook success events without re-owning the full code composition:

<Streamdown
  controls={{
    code: {
      copy: {
        onCopy: () => announce("Copied"),
        onError: (error) => toast.error(error.message),
      },
    },
  }}
>
  {markdown}
</Streamdown>

Closes #557

Test plan

  • vitest run controls.test.ts show-controls.test.tsx
  • vitest run code-block.test.tsx
  • Click default code copy button with controls.code.copy.onCopy and confirm callback fires
  • Confirm clipboard-unavailable path calls onError
  • Confirm copy: false still hides the button and object config still shows it

Extend ControlsConfig so hosts can pass copy callbacks via
controls.code.copy and controls.mermaid.copy, and thread them into
the default-rendered CodeBlockCopyButton.

Closes vercel#557
@vercel

vercel Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

@ShobhanKarthish is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

onCopy/onError are not wired on the DEFAULT-rendered code-block controls

1 participant