Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Fix fast menu dismissal (#10291)

Jonny Burger366793f11696
diff --git a/packages/example/e2e/studio.test.mts b/packages/example/e2e/studio.test.mts
index 0c7983b5c6..db733d498f 100644
--- a/packages/example/e2e/studio.test.mts
+++ b/packages/example/e2e/studio.test.mts
@@ -656,10 +656,17 @@ test.describe('visual mode', () => {
timeout: 15_000,
});
+ await page.evaluate(() => {
+ // Keep the menu tree in the interval before the next animation frame to
+ // exercise a fast user's outside click deterministically.
+ window.requestAnimationFrame = () => 0;
+ });
await page.getByRole('button', {name: 'More actions'}).click();
- await page
- .getByRole('button', {name: 'Playback Rate', exact: true})
- .click();
+ const playbackRate = page.getByRole('button', {
+ name: 'Playback Rate',
+ exact: true,
+ });
+ await playbackRate.click();
await expect(
page.getByRole('button', {name: '1x', exact: true}),
).toBeVisible();
diff --git a/packages/studio/src/state/z-index.tsx b/packages/studio/src/state/z-index.tsx
index 3c7b1b99d0..2d60d3fd20 100644
--- a/packages/studio/src/state/z-index.tsx
+++ b/packages/studio/src/state/z-index.tsx
@@ -130,14 +130,11 @@ export const HigherZIndex: React.FC<{
});
};
- // If a menu is opened, then this component will also still receive the pointerdown event.
- // However we may not interpret it as a outside click, so we need to wait for the next tick
- requestAnimationFrame(() => {
- // The third argument `true` registers a capture-phase listener. Some Studio
- // elements stop pointerdown propagation while still being outside the menu,
- // so bubbling listeners would miss those clicks and keep the menu open.
- window.addEventListener('pointerdown', listener, true);
- });
+ // The capture phase for the pointerdown that opened this layer has already
+ // passed, so installing the listener immediately cannot dismiss the new layer.
+ // Waiting for the next animation frame would leave a window in which a fast
+ // outside click is missed.
+ window.addEventListener('pointerdown', listener, true);
return () => {
endPointerSession?.();
endPointerSession = null;