From 8d5863cfb2fc10039f9cf0e775fe49bf77642894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Fri, 20 Nov 2026 21:15:14 +0000 Subject: [PATCH] test(studio): a sealed preview's reload waits for a resize on its stand-in to end (#8222) * fix(studio): a scene edit swaps in place and a far scene mounts for selection in a sealed preview * test(studio): a sealed undo that reloads marks its scenes stale first * fix(studio): a timing drag moves the animation in place in a sealed preview * fix(studio): a sealed timing drag moves the clip's window and the film length with its tweens * test(studio): the sealed retime test checks both requests were sent before comparing them * refactor(studio): the sealed live retime code passes the quality audit * style(core): format the sealed live retime parser * fix(studio): a reload waits for a drag to end in a sealed preview * refactor(studio): manual edit gesture tracking lives in its own module * test(studio): a sealed preview's reload waits for a resize on its stand-in to end --- ...seTimelinePlayer.sealedGestureHold.test.ts | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 packages/studio/src/player/hooks/useTimelinePlayer.sealedGestureHold.test.ts diff --git a/packages/studio/src/player/hooks/useTimelinePlayer.sealedGestureHold.test.ts b/packages/studio/src/player/hooks/useTimelinePlayer.sealedGestureHold.test.ts new file mode 100644 index 0000000000..0b374cf51f --- /dev/null +++ b/packages/studio/src/player/hooks/useTimelinePlayer.sealedGestureHold.test.ts @@ -0,0 +1,72 @@ +// @vitest-environment happy-dom +import { act } from "react"; +import { afterEach, expect, it, vi } from "vitest"; +import { + beginStudioManualEditGesture, + endStudioManualEditGesture, +} from "../../components/editor/manualEdits"; +import { standInFor } from "../../components/editor/previewSelection"; +import { + makeAdapterWindow, + makeFakeIframe, + renderTimelinePlayerHarness, + resetPlayerStore, +} from "./timelinePlayerTestHarness"; + +globalThis.IS_REACT_ACT_ENVIRONMENT = true; + +const sealed = vi.hoisted(() => new Set()); + +vi.mock("../lib/previewChannel", async (importOriginal) => ({ + ...(await importOriginal()), + previewFrameOpaque: (iframe: HTMLIFrameElement) => sealed.has(iframe), +})); + +vi.mock("../../utils/gsapSoftReload", async (importOriginal) => ({ + ...(await importOriginal()), + ensureMotionPathPluginLoaded: vi.fn(), +})); + +afterEach(() => { + sealed.clear(); + document.body.innerHTML = ""; + resetPlayerStore(); +}); + +function previewFrame(query: string): HTMLIFrameElement { + const iframe = makeFakeIframe(makeAdapterWindow().win); + iframe.src = `http://localhost/api/projects/demo/preview${query}`; + return iframe; +} + +it("keeps a sealed preview on screen through a resize on its stand-in, and swaps in the reload once it ends", () => { + const { getApi, root } = renderTimelinePlayerHarness(); + const live = previewFrame(""); + act(() => { + getApi().iframeRef.current = live; + getApi().onIframeLoad(); + }); + sealed.add(live); + const description = { handle: "box", tag: "div", inlineStyles: {}, attributes: [] }; + const standIn = standInFor(live, description as unknown as Parameters[1]); + // As createManualOffsetDragMember starts a resize on the selection's stand-in. + const token = beginStudioManualEditGesture(standIn, "resize"); + + act(() => getApi().refreshPlayer()); + // Not swapped in place under the resize: the reload loads beside the live preview. + const pending = getApi().previewSlots.find((slot) => slot.role === "shadow"); + expect(pending).toBeDefined(); + const gen = pending!.gen; + const shadow = previewFrame("?_t=1"); + act(() => { + getApi().setShadowIframeNode(shadow); + getApi().onShadowIframeLoad(gen); + getApi().onShadowReadyChange(gen, true); + }); + expect(getApi().iframeRef.current).toBe(live); + + act(() => endStudioManualEditGesture(standIn, token)); + expect(getApi().iframeRef.current).toBe(shadow); + + act(() => root.unmount()); +});