fix(studio): open the canvas context menu when a pointer move overtakes its lookup (#7643)

A pointer move superseded by a newer move or a leave returned null, not just
skipped the hover update. The right-click path awaits that same lookup for its
target when nothing is selected, so on a sandboxed preview, where the lookup
crosses the frame's channel, a 1px jitter during the right-click bumped the
counter and the menu never opened. The stale hover is still dropped; the
result is returned either way.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
James Russo
2026-11-13 08:29:42 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent be67089a80
commit d208281091
2 changed files with 23 additions and 2 deletions
@@ -21,6 +21,7 @@ import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness
import { installReactActEnvironment } from "../../hooks/domSelectionTestHarness";
import { useDomSelection } from "../../hooks/useDomSelection";
import { usePreviewInteraction } from "../../hooks/usePreviewInteraction";
import { useCanvasContextMenuState } from "./useCanvasContextMenuState";
import type { TimelineElement } from "../../player";
installReactActEnvironment();
@@ -175,6 +176,7 @@ describe("canvas hit-tests on an opaque frame match same-origin ones", () => {
describe("useDomSelection over an opaque frame's canvas", () => {
type Resolve = ReturnType<typeof useDomSelection>["resolveDomSelectionFromPreviewPoint"];
let interaction: ReturnType<typeof usePreviewInteraction> | null = null;
let menu: ReturnType<typeof useCanvasContextMenuState> | null = null;
function renderSelection(iframe: HTMLIFrameElement, wrapResolve = (resolve: Resolve) => resolve) {
let hook: ReturnType<typeof useDomSelection> | null = null;
function Harness() {
@@ -206,6 +208,14 @@ describe("useDomSelection over an opaque frame's canvas", () => {
updateDomEditHoverSelection: hook.updateDomEditHoverSelection,
setActiveGroupElement: hook.setActiveGroupElement,
});
// The overlay's right-click path, which awaits the same lookup a pointer move runs.
menu = useCanvasContextMenuState({
selection: hook.domEditSelection,
selectionRef: { current: hook.domEditSelection },
hoverSelectionRef: { current: hook.domEditHoverSelection },
onCanvasPointerMoveRef: { current: interaction.handlePreviewCanvasPointerMove },
onSelectionChangeRef: { current: hook.applyDomSelection },
});
return null;
}
const root = createRoot(document.createElement("div"));
@@ -256,6 +266,18 @@ describe("useDomSelection over an opaque frame's canvas", () => {
expect(hook().domEditHoverSelection).toMatchObject({ id: "pair" });
});
it("opens the menu on a right-click whose lookup a pointer move overtook", async () => {
const hook = renderSelection(opaqueFrame());
const [clientX, clientY] = client(60, 60);
const rightClick = { clientX, clientY, preventDefault: () => {} };
const opened = menu!.handleContextMenu(rightClick as React.MouseEvent<HTMLDivElement>);
const jitter = move(1050, 650);
await act(() => Promise.all([opened, jitter]));
expect(hook().domEditSelection).toMatchObject({ id: "title" });
expect(menu!.contextMenu?.sel).toMatchObject({ id: "title" });
expect(hook().domEditHoverSelection).toMatchObject({ id: "pair" });
});
it("takes a hover of the same element from a reloaded frame, whose handle is new", async () => {
const hook = renderSelection(opaqueFrame());
const picked = (await act(() =>
@@ -249,8 +249,7 @@ export function usePreviewInteraction({
preferClipAncestor: options?.preferClipAncestor ?? false,
skipSourceProbe: true,
});
if (seq !== hoverSeqRef.current) return null;
updateDomEditHoverSelection(nextSelection);
if (seq === hoverSeqRef.current) updateDomEditHoverSelection(nextSelection);
return nextSelection;
},
[