mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(studio): a selected element stays drawn and draggable after a sealed preview reloads (#8081)
* test(studio): a sealed preview's new page keeps the selection drawn and draggable * fix(studio): a selected element stays drawn and draggable after a sealed preview reloads
This commit is contained in:
@@ -4,7 +4,8 @@ import { createElement, act } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { useDomEditPreviewSync } from "./useDomEditPreviewSync";
|
||||
import { sceneSwapFor } from "../player/sceneSwap";
|
||||
import { announcePreviewDocumentLoaded, sceneSwapFor } from "../player/sceneSwap";
|
||||
import type { DomEditSelection } from "../components/editor/domEditing";
|
||||
|
||||
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
||||
|
||||
@@ -51,4 +52,38 @@ describe("useDomEditPreviewSync", () => {
|
||||
act(() => root.unmount());
|
||||
fetchSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("re-resolves the selection when a sealed preview loads a new page", () => {
|
||||
const iframe = document.createElement("iframe");
|
||||
Object.defineProperty(iframe, "contentDocument", { value: null });
|
||||
Object.defineProperty(iframe, "contentWindow", {
|
||||
value: {
|
||||
get document() {
|
||||
throw new DOMException("blocked", "SecurityError");
|
||||
},
|
||||
},
|
||||
});
|
||||
const selection = { selector: "#target", handle: "old-page:1" } as DomEditSelection;
|
||||
const refresh = vi.fn(async () => {});
|
||||
function Harness() {
|
||||
useDomEditPreviewSync({
|
||||
previewIframe: iframe,
|
||||
captionEditMode: false,
|
||||
domEditSelectionRef: { current: selection },
|
||||
domEditSelection: selection,
|
||||
refreshDomEditSelectionFromPreview: refresh,
|
||||
refreshPreviewDocumentVersion: () => {},
|
||||
syncPreviewHotkeys: () => {},
|
||||
applyStudioManualEditsToPreviewRef: { current: async () => {} },
|
||||
});
|
||||
return null;
|
||||
}
|
||||
const root = createRoot(document.createElement("div"));
|
||||
act(() => root.render(createElement(Harness)));
|
||||
refresh.mockClear();
|
||||
|
||||
act(() => announcePreviewDocumentLoaded(iframe));
|
||||
expect(refresh).toHaveBeenCalledWith(selection, iframe);
|
||||
act(() => root.unmount());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ import { reapplyPositionEditsAfterSeek } from "../components/editor/manualEdits"
|
||||
import { useDockLayoutStore } from "../components/dock/dockLayoutStore";
|
||||
import type { PatchTarget } from "../utils/sourcePatcher";
|
||||
import { onPreviewContentReplaced } from "../player/sceneSwap";
|
||||
import { previewFrameOpaque } from "../player/lib/previewChannel";
|
||||
|
||||
interface UseDomEditPreviewSyncParams {
|
||||
previewIframe: HTMLIFrameElement | null;
|
||||
@@ -57,9 +58,8 @@ export function useDomEditPreviewSync({
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
if (!doc) return;
|
||||
|
||||
reapplyPositionEditsAfterSeek(doc);
|
||||
if (doc) reapplyPositionEditsAfterSeek(doc);
|
||||
else if (!previewFrameOpaque(previewIframe)) return;
|
||||
await refreshDomEditSelectionFromPreview(currentSelection, previewIframe);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user