From 156f985fb0908f9e6d99ae5cc5f0c1d1360603e4 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Mon, 6 Oct 2025 15:41:57 -0400 Subject: [PATCH] fix(site): update `useClipboard` to work better with effect logic (#20183) ## Changes made - Updated `useClipboard` API to require passing the text in via the `copyToClipboard` function, rather than requiring that the text gets specified in render logic - Ensured that the `copyToClipboard` function always stays stable across all React lifecycles - Updated all existing uses to use the new function signatures - Updated all tests and added new cases --- site/src/components/CopyButton/CopyButton.tsx | 6 +- .../CopyableValue/CopyableValue.tsx | 6 +- site/src/hooks/useClickable.ts | 4 +- site/src/hooks/useClipboard.test.tsx | 110 +++++++++++++++--- site/src/hooks/useClipboard.ts | 75 ++++++------ .../src/pages/CliAuthPage/CliAuthPageView.tsx | 15 +-- site/src/pages/TaskPage/TaskTopbar.tsx | 7 +- .../TemplateEmbedPage/TemplateEmbedPage.tsx | 17 +-- .../TemplateEmbedPageExperimental.tsx | 18 +-- 9 files changed, 172 insertions(+), 86 deletions(-) diff --git a/site/src/components/CopyButton/CopyButton.tsx b/site/src/components/CopyButton/CopyButton.tsx index 9110bb4cd6..c00b9360e4 100644 --- a/site/src/components/CopyButton/CopyButton.tsx +++ b/site/src/components/CopyButton/CopyButton.tsx @@ -19,9 +19,7 @@ export const CopyButton: FC = ({ label, ...buttonProps }) => { - const { showCopiedSuccess, copyToClipboard } = useClipboard({ - textToCopy: text, - }); + const { showCopiedSuccess, copyToClipboard } = useClipboard(); return ( @@ -30,7 +28,7 @@ export const CopyButton: FC = ({ diff --git a/site/src/pages/TaskPage/TaskTopbar.tsx b/site/src/pages/TaskPage/TaskTopbar.tsx index 1ad9ca5f0f..989e1b6473 100644 --- a/site/src/pages/TaskPage/TaskTopbar.tsx +++ b/site/src/pages/TaskPage/TaskTopbar.tsx @@ -81,14 +81,11 @@ export const TaskTopbar: FC = ({ task }) => { type CopyPromptButtonProps = { prompt: string }; const CopyPromptButton: FC = ({ prompt }) => { - const { copyToClipboard, showCopiedSuccess } = useClipboard({ - textToCopy: prompt, - }); - + const { copyToClipboard, showCopiedSuccess } = useClipboard(); return (