@devries-cameron20 / t3code Mirror · read-only / commits / 6293119f83
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 08:00 UTC

perf(web): useCopyToClipboard reads its options through useStableCallback (#20460)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 16, 2026 at 18:46 UTC 6293119f83e90062001c622e17841dc189efe1b7
2 files changed +10 -19
apps/web/reactCompiledFiles.ts
+1
@@ -35,4 +35,5 @@ export const REACT_COMPILED_FILES = [
35 "apps/web/src/components/settings/ProjectFaviconPickerDialog.tsx",
36 "apps/web/src/components/settings/ThemeEditorPanel.tsx",
37 "apps/web/src/panelAnimations.ts",
38 + "apps/web/src/hooks/useCopyToClipboard.ts",
39 ] as const;
apps/web/src/hooks/useCopyToClipboard.ts
+9 -19
@@ -4,6 +4,7 @@ import {
4 COMPOSER_CONTEXT_CLIPBOARD_MIME,
5 encodeComposerContextClipboardHtml,
6 } from "@t3tools/shared/composerContextClipboard";
7 +import { useStableCallback } from "./useStableCallback";
8
9 export class ClipboardApiUnavailableError extends Schema.TaggedError<ClipboardApiUnavailableError>()(
10 "ClipboardApiUnavailableError",
@@ -206,20 +207,9 @@ export function useCopyToClipboard<TContext = void>({
207 } = {}): { copyToClipboard: (value: string, ctx: TContext) => void; isCopied: boolean } {
208 const [isCopied, setIsCopied] = React.useState(false);
209 const timeoutIdRef = React.useRef<NodeJS.Timeout | null>(null);
209 - const onCopyRef = React.useRef(onCopy);
210 - const onErrorRef = React.useRef(onError);
211 - const targetRef = React.useRef(target);
212 - const timeoutRef = React.useRef(timeout);
213 -
214 - onCopyRef.current = onCopy;
215 - onErrorRef.current = onError;
216 - const extraFlavorsRef = React.useRef(extraFlavors);
217 - targetRef.current = target;
218 - timeoutRef.current = timeout;
219 - extraFlavorsRef.current = extraFlavors;
220 -
221 - const copyToClipboard = React.useCallback((value: string, ctx: TContext): void => {
222 - void writeTextToClipboard(value, targetRef.current, extraFlavorsRef.current).then(
210 + // Callers pass inline onCopy/onError but key callbacks and effects on this function.
211 + const copyToClipboard = useStableCallback((value: string, ctx: TContext): void => {
212 + void writeTextToClipboard(value, target, extraFlavors).then(
213 (didCopy) => {
214 if (!didCopy) return;
215 if (timeoutIdRef.current) {
@@ -227,21 +217,21 @@ export function useCopyToClipboard<TContext = void>({
217 }
218 setIsCopied(true);
219
230 - onCopyRef.current?.(ctx);
220 + onCopy?.(ctx);
221
232 - if (timeoutRef.current !== 0) {
222 + if (timeout !== 0) {
223 timeoutIdRef.current = setTimeout(() => {
224 setIsCopied(false);
225 timeoutIdRef.current = null;
236 - }, timeoutRef.current);
226 + }, timeout);
227 }
228 },
229 (error) => {
230 console.error(error);
241 - onErrorRef.current?.(error, ctx);
231 + onError?.(error, ctx);
232 },
233 );
244 - }, []);
234 + });
235
236 React.useEffect(() => {
237 return (): void => {