fix: cancel floating context menu frame (#3409)

This commit is contained in:
Neil
2026-05-29 18:39:37 -07:00
committed by GitHub
parent ff6b66efee
commit 69b3a9d948
@@ -1,4 +1,4 @@
import { useMemo, useState } from 'react'
import { useEffect, useMemo, useRef, useState } from 'react'
import { EyeOff, PanelBottom, PanelTop } from 'lucide-react'
import {
DropdownMenu,
@@ -26,6 +26,17 @@ export function FloatingTerminalIconContextMenu({
const updateSettings = useAppStore((s) => s.updateSettings)
const [open, setOpen] = useState(false)
const [menuPoint, setMenuPoint] = useState({ x: 0, y: 0 })
const reopenFrameRef = useRef<number | null>(null)
useEffect(
() => () => {
if (reopenFrameRef.current !== null) {
window.cancelAnimationFrame(reopenFrameRef.current)
reopenFrameRef.current = null
}
},
[]
)
const moveAction = useMemo(() => {
if (currentLocation === 'floating-button') {
@@ -55,7 +66,13 @@ export function FloatingTerminalIconContextMenu({
event.stopPropagation()
setMenuPoint({ x: event.clientX, y: event.clientY })
setOpen(false)
window.requestAnimationFrame(() => setOpen(true))
if (reopenFrameRef.current !== null) {
window.cancelAnimationFrame(reopenFrameRef.current)
}
reopenFrameRef.current = window.requestAnimationFrame(() => {
reopenFrameRef.current = null
setOpen(true)
})
}}
onContextMenu={(event) => {
event.preventDefault()