Skip to content

Commit dea71d1

Browse files
committed
fix(knowledge): guard onCopyId against navigation and use setTimeout for robustness
1 parent 5343bc9 commit dea71d1

File tree

1 file changed

+18
-9
lines changed
  • apps/sim/app/workspace/[workspaceId]/knowledge/components/base-card

1 file changed

+18
-9
lines changed

apps/sim/app/workspace/[workspaceId]/knowledge/components/base-card/base-card.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,35 +133,44 @@ export function BaseCard({
133133
const handleOpenInNewTab = useCallback(() => {
134134
actionTakenRef.current = true
135135
window.open(href, '_blank')
136-
requestAnimationFrame(() => {
136+
setTimeout(() => {
137137
actionTakenRef.current = false
138-
})
138+
}, 0)
139139
}, [href])
140140

141141
const handleViewTags = useCallback(() => {
142142
actionTakenRef.current = true
143143
setIsTagsModalOpen(true)
144-
requestAnimationFrame(() => {
144+
setTimeout(() => {
145145
actionTakenRef.current = false
146-
})
146+
}, 0)
147147
}, [])
148148

149149
const handleEdit = useCallback(() => {
150150
actionTakenRef.current = true
151151
setIsEditModalOpen(true)
152-
requestAnimationFrame(() => {
152+
setTimeout(() => {
153153
actionTakenRef.current = false
154-
})
154+
}, 0)
155155
}, [])
156156

157157
const handleDelete = useCallback(() => {
158158
actionTakenRef.current = true
159159
setIsDeleteModalOpen(true)
160-
requestAnimationFrame(() => {
160+
setTimeout(() => {
161161
actionTakenRef.current = false
162-
})
162+
}, 0)
163163
}, [])
164164

165+
const handleCopyId = useCallback(() => {
166+
if (!id) return
167+
actionTakenRef.current = true
168+
navigator.clipboard.writeText(id)
169+
setTimeout(() => {
170+
actionTakenRef.current = false
171+
}, 0)
172+
}, [id])
173+
165174
const handleConfirmDelete = useCallback(async () => {
166175
if (!id || !onDelete) return
167176
setIsDeleting(true)
@@ -257,7 +266,7 @@ export function BaseCard({
257266
onClose={closeContextMenu}
258267
onOpenInNewTab={handleOpenInNewTab}
259268
onViewTags={handleViewTags}
260-
onCopyId={id ? () => navigator.clipboard.writeText(id) : undefined}
269+
onCopyId={id ? handleCopyId : undefined}
261270
onEdit={handleEdit}
262271
onDelete={handleDelete}
263272
showOpenInNewTab={true}

0 commit comments

Comments
 (0)