fix: clear copy feedback mounted guards from refs (#3514)

This commit is contained in:
Neil
2026-05-30 00:10:24 -07:00
committed by GitHub
parent 8a0fb0bae2
commit 3f12acf4ea
9 changed files with 20 additions and 74 deletions
@@ -5443,12 +5443,8 @@ export default function GitHubItemDialog({
// Why: clipboard IPC can resolve after the dialog unmounts; skip copied-state
// feedback instead of starting its reset timer on a stale surface.
const linkCopyMountedRef = useRef(false)
useEffect(() => {
linkCopyMountedRef.current = true
return () => {
linkCopyMountedRef.current = false
}
const setLinkCopyButtonRef = useCallback((node: HTMLButtonElement | null) => {
linkCopyMountedRef.current = node !== null
}, [])
useEffect(() => {
@@ -5593,6 +5589,7 @@ export default function GitHubItemDialog({
<Tooltip>
<TooltipTrigger asChild>
<Button
ref={setLinkCopyButtonRef}
type="button"
variant="ghost"
size="icon-sm"
@@ -5735,6 +5732,7 @@ export default function GitHubItemDialog({
<Tooltip>
<TooltipTrigger asChild>
<Button
ref={setLinkCopyButtonRef}
type="button"
variant="ghost"
size="icon-sm"
@@ -5328,12 +5328,8 @@ export default function PullRequestPage({
// Why: clipboard IPC can resolve after the page unmounts; skip copied-state
// feedback instead of starting its reset timer on a stale surface.
const linkCopyMountedRef = useRef(false)
useEffect(() => {
linkCopyMountedRef.current = true
return () => {
linkCopyMountedRef.current = false
}
const setLinkCopyButtonRef = useCallback((node: HTMLButtonElement | null) => {
linkCopyMountedRef.current = node !== null
}, [])
useEffect(() => {
@@ -5484,6 +5480,7 @@ export default function PullRequestPage({
<Tooltip>
<TooltipTrigger asChild>
<Button
ref={setLinkCopyButtonRef}
type="button"
variant="ghost"
size="icon-sm"
+2 -9
View File
@@ -1,5 +1,5 @@
/* oxlint-disable max-lines */
import React, { useCallback, useDeferredValue, useEffect, useMemo, useRef, useState } from 'react'
import React, { useCallback, useDeferredValue, useMemo, useRef, useState } from 'react'
import { AlertTriangle, Check, Copy } from 'lucide-react'
import { useAppStore } from '@/store'
import { useActiveWorktree } from '@/store/selectors'
@@ -80,6 +80,7 @@ function InstallRgGuidance({
const setCopyButtonRef = useCallback(
(node: HTMLButtonElement | null) => {
isMountedRef.current = node !== null
if (node === null) {
clearCopiedResetTimer()
}
@@ -87,14 +88,6 @@ function InstallRgGuidance({
[clearCopiedResetTimer]
)
useEffect(() => {
isMountedRef.current = true
return () => {
isMountedRef.current = false
clearCopiedResetTimer()
}
}, [clearCopiedResetTimer])
const handleCopy = useCallback(() => {
if (!command) {
return
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useRef, useState } from 'react'
import React, { useCallback, useRef, useState } from 'react'
import { Copy, Check } from 'lucide-react'
type CodeBlockCopyButtonProps = React.HTMLAttributes<HTMLPreElement> & {
@@ -24,6 +24,7 @@ export default function CodeBlockCopyButton({
const setCopyButtonRef = useCallback(
(node: HTMLButtonElement | null) => {
isMountedRef.current = node !== null
if (node === null) {
clearCopiedResetTimer()
}
@@ -31,14 +32,6 @@ export default function CodeBlockCopyButton({
[clearCopiedResetTimer]
)
useEffect(() => {
isMountedRef.current = true
return () => {
isMountedRef.current = false
clearCopiedResetTimer()
}
}, [clearCopiedResetTimer])
const handleCopy = useCallback(() => {
// Extract the text content from the nested <code> element rendered by
// react-markdown inside <pre>. We walk the React children tree to grab the
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useRef, useState } from 'react'
import React, { useCallback, useRef, useState } from 'react'
import { NodeViewContent, NodeViewWrapper } from '@tiptap/react'
import type { NodeViewProps } from '@tiptap/react'
import { Copy, Check } from 'lucide-react'
@@ -64,6 +64,7 @@ export function RichMarkdownCodeBlock({
const setCopyButtonRef = useCallback(
(node: HTMLButtonElement | null) => {
isMountedRef.current = node !== null
if (node === null) {
clearCopiedResetTimer()
}
@@ -71,14 +72,6 @@ export function RichMarkdownCodeBlock({
[clearCopiedResetTimer]
)
useEffect(() => {
isMountedRef.current = true
return () => {
isMountedRef.current = false
clearCopiedResetTimer()
}
}, [clearCopiedResetTimer])
const onChange = useCallback(
(e: React.ChangeEvent<HTMLSelectElement>) => {
updateAttributes({ language: e.target.value })
@@ -1,6 +1,6 @@
/* eslint-disable max-lines -- Why: co-locating all checks-panel sub-components (checks list,
conflict sections, threaded PR comments) keeps the shared icon/color maps in one place. */
import React, { useCallback, useEffect, useRef, useState } from 'react'
import React, { useCallback, useRef, useState } from 'react'
import {
CircleCheck,
CircleX,
@@ -370,6 +370,7 @@ function CopyButton({ text }: { text: string }): React.JSX.Element {
const setCopyButtonRef = useCallback(
(node: HTMLButtonElement | null) => {
isMountedRef.current = node !== null
if (node === null) {
clearCopiedResetTimer()
}
@@ -377,14 +378,6 @@ function CopyButton({ text }: { text: string }): React.JSX.Element {
[clearCopiedResetTimer]
)
useEffect(() => {
isMountedRef.current = true
return () => {
isMountedRef.current = false
clearCopiedResetTimer()
}
}, [clearCopiedResetTimer])
const handleCopy = useCallback(
(e: React.MouseEvent) => {
e.stopPropagation()
@@ -66,6 +66,7 @@ export function MobilePane(): React.JSX.Element {
const setPairingCodeButtonRef = useCallback(
(node: HTMLButtonElement | null) => {
isMountedRef.current = node !== null
if (node === null) {
clearCodeCopiedResetTimer()
}
@@ -73,14 +74,6 @@ export function MobilePane(): React.JSX.Element {
[clearCodeCopiedResetTimer]
)
useEffect(() => {
isMountedRef.current = true
return () => {
isMountedRef.current = false
clearCodeCopiedResetTimer()
}
}, [clearCodeCopiedResetTimer])
const loadDevices = useCallback(async () => {
try {
const result = await window.api.mobile.listDevices()
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import { useCallback, useRef, useState } from 'react'
import type { OrcaHooks, Repo, RepoHookSettings } from '../../../../shared/types'
import { getRepoKindLabel, isFolderRepo } from '../../../../shared/repo-kind'
import { Button } from '../ui/button'
@@ -72,6 +72,7 @@ export function RepositoryPane({
const setRepositoryPaneRootRef = useCallback(
(node: HTMLDivElement | null) => {
isMountedRef.current = node !== null
if (node === null) {
clearCopiedTemplateResetTimer()
}
@@ -79,14 +80,6 @@ export function RepositoryPane({
[clearCopiedTemplateResetTimer]
)
useEffect(() => {
isMountedRef.current = true
return () => {
isMountedRef.current = false
clearCopiedTemplateResetTimer()
}
}, [clearCopiedTemplateResetTimer])
const handleRemoveProject = (repoId: string) => {
if (confirmingRemove === repoId) {
removeProject(repoId)
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import { useCallback, useRef, useState } from 'react'
import { toPng } from 'html-to-image'
import { Check, Copy, Share2 } from 'lucide-react'
import { Button } from '../ui/button'
@@ -34,6 +34,7 @@ export function ShareUsageButton(props: ShareUsageButtonProps): React.JSX.Elemen
const setShareButtonRef = useCallback(
(node: HTMLButtonElement | null) => {
isMountedRef.current = node !== null
if (node === null) {
clearCopiedResetTimer()
}
@@ -41,14 +42,6 @@ export function ShareUsageButton(props: ShareUsageButtonProps): React.JSX.Elemen
[clearCopiedResetTimer]
)
useEffect(() => {
isMountedRef.current = true
return () => {
isMountedRef.current = false
clearCopiedResetTimer()
}
}, [clearCopiedResetTimer])
const captureToClipboard = useCallback(async () => {
if (!cardRef.current || capturing) {
return