Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

fix(CodeBlock.tsx): fix copy-to-clipboard functionality. The code has been updated to use the copy function from the copy-to-clipboard library instead of the (#806)

Danny Avila89f260bc7895
diff --git a/client/src/components/Messages/Content/CodeBlock.tsx b/client/src/components/Messages/Content/CodeBlock.tsx
index f1ffca6d00..c61fc65a22 100644
--- a/client/src/components/Messages/Content/CodeBlock.tsx
+++ b/client/src/components/Messages/Content/CodeBlock.tsx
@@ -1,4 +1,5 @@
import React, { useRef, useState, RefObject } from 'react';
+import copy from 'copy-to-clipboard';
import { Clipboard, CheckMark } from '~/components';
import { InfoIcon } from 'lucide-react';
import { cn } from '~/utils/';
@@ -22,10 +23,12 @@ const CodeBar: React.FC<CodeBarProps> = React.memo(({ lang, codeRef, plugin = nu
onClick={async () => {
const codeString = codeRef.current?.textContent;
if (codeString) {
- navigator.clipboard.writeText(codeString).then(() => {
- setIsCopied(true);
- setTimeout(() => setIsCopied(false), 3000);
- });
+ setIsCopied(true);
+ copy(codeString);
+
+ setTimeout(() => {
+ setIsCopied(false);
+ }, 3000);
}
}}
>