Skip to content

Commit 6b24228

Browse files
fix(ui): avoid ChatGPT 431 for long Copy for AI prompts (resend#3404)
Co-authored-by: gabriel miranda <gabriel@resend.com>
1 parent bb98565 commit 6b24228

3 files changed

Lines changed: 125 additions & 205 deletions

File tree

.changeset/chatty-parks-rhyme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-email/ui": patch
3+
---
4+
5+
fallback behavior for prompt copying when too long

packages/ui/src/components/toolbar/copy-for-ai.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ function buildChatGPTUrl(prompt: string): string {
222222
return `https://chatgpt.com/?q=${encodeURIComponent(prompt)}`;
223223
}
224224

225+
const MAX_SAFE_CHATGPT_URL_LENGTH = 7500;
226+
225227
function buildCursorUrl(prompt: string): string {
226228
return `cursor://prompt?text=${encodeURIComponent(prompt)}`;
227229
}
@@ -254,7 +256,12 @@ export const CopyForAI = ({
254256
}, [markdown]);
255257

256258
const claudeUrl = buildClaudeUrl(markdown);
257-
const chatGPTUrl = buildChatGPTUrl(markdown);
259+
const directChatGPTUrl = buildChatGPTUrl(markdown);
260+
const isChatGPTPromptTooLong =
261+
directChatGPTUrl.length > MAX_SAFE_CHATGPT_URL_LENGTH;
262+
const chatGPTUrl = isChatGPTPromptTooLong
263+
? 'https://chatgpt.com/'
264+
: directChatGPTUrl;
258265
const cursorUrl = buildCursorUrl(markdown);
259266

260267
return (
@@ -356,6 +363,10 @@ export const CopyForAI = ({
356363
href={chatGPTUrl}
357364
target="_blank"
358365
rel="noreferrer noopener"
366+
onClick={() => {
367+
if (!isChatGPTPromptTooLong) return;
368+
void navigator.clipboard.writeText(markdown);
369+
}}
359370
className="flex items-center gap-2.5 p-2 rounded-lg cursor-pointer outline-none transition-colors hover:bg-white/5"
360371
>
361372
<span
@@ -368,7 +379,11 @@ export const CopyForAI = ({
368379
<span className="text-sm font-medium text-white">
369380
Open in ChatGPT
370381
</span>
371-
<span className="text-xs text-white/40">{linkDescription}</span>
382+
<span className="text-xs text-white/40">
383+
{isChatGPTPromptTooLong
384+
? 'Long prompt: copied to clipboard. Paste with Ctrl+V / Cmd+V'
385+
: linkDescription}
386+
</span>
372387
</div>
373388
<IconArrowUpRight size={16} className="shrink-0 text-white/30" />
374389
</a>

0 commit comments

Comments
 (0)