mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(studio): a sealed preview's reload shows in a fraction of a second, not after 8 s (#8015)
* fix(studio): a sealed preview's reload shows in a fraction of a second, not after 8 s * fix(studio): the sealed reload's frame sits under the live one, so clicks stay on the live frame * fix(studio): the sealed reload's frame stays on top but inert, so clicks reach the live frame Under the live frame (z-index -1) the reload's frame was left unpromoted in a traced run; on top and inert it renders and swaps in, and hit testing skips it, its own frame included. * refactor(studio): name the sealed reload's style for what it does, not in comments * fix(studio): the reload code marks a sealed reload's player inert until it is promoted Player keeps main's shape: the hook that owns the reload sets inert on the hidden frame's player element when its frame arrives and clears it at promotion. * test(studio): keep the reload-inert test's comment under the line limit
This commit is contained in:
@@ -590,6 +590,30 @@ describe("NLEPreview", () => {
|
||||
},
|
||||
);
|
||||
|
||||
// Chrome stops rendering a hidden or clipped cross-origin frame, and a sealed one is cross-origin.
|
||||
it.each([
|
||||
["opaque" as const, ["opacity: 0"], ["visibility", "clip-path", "z-index"]],
|
||||
[undefined, ["visibility: hidden", "clip-path: inset(100%)"], ["opacity"]],
|
||||
])(
|
||||
"keeps a reload's preview out of sight, and a sealed one rendering (%s)",
|
||||
(sandboxOrigin, present, absent) => {
|
||||
const view = renderPreview(
|
||||
[
|
||||
{ gen: 0, role: "live" },
|
||||
{ gen: 1, role: "shadow", url: "/api/projects/p/preview?_t=1" },
|
||||
],
|
||||
{ sandboxOrigin },
|
||||
);
|
||||
const shadow = [...view.stage.querySelectorAll('[data-testid="mock-player"]')]
|
||||
.map((player) => player.getAttribute("style") ?? "")
|
||||
.filter((style) => style.includes("pointer-events: none"));
|
||||
expect(shadow).toHaveLength(1);
|
||||
for (const rule of present) expect(shadow[0]).toContain(rule);
|
||||
for (const rule of absent) expect(shadow[0]).not.toContain(rule);
|
||||
view.cleanup();
|
||||
},
|
||||
);
|
||||
|
||||
it("covers the live preview with the cached frame-0 poster until it is ready to show", () => {
|
||||
const view = renderPreview();
|
||||
const poster = () =>
|
||||
|
||||
@@ -29,11 +29,7 @@ import {
|
||||
} from "./previewZoom";
|
||||
import { RULER_GUTTER_PX, usePreviewGuidesStore } from "../editor/previewGuidesStore";
|
||||
import { PreviewZoomOverlay, usePreviewZoomOverlay } from "./PreviewZoomOverlay";
|
||||
import {
|
||||
PREVIEW_STAGE_INSET_PX,
|
||||
resolvePreviewStageSize,
|
||||
SHADOW_IFRAME_STYLE,
|
||||
} from "./previewStage";
|
||||
import { PREVIEW_STAGE_INSET_PX, resolvePreviewStageSize, shadowIframeStyle } from "./previewStage";
|
||||
import { usePreviewFirstFrameTelemetry } from "../../player/hooks/usePreviewFirstFrameTelemetry";
|
||||
import { PreviewPoster, usePreviewPoster } from "./PreviewPoster";
|
||||
interface NLEPreviewProps extends Pick<
|
||||
@@ -534,7 +530,7 @@ export const NLEPreview = memo(function NLEPreview({
|
||||
suppressLoadingOverlay
|
||||
noLoadTimeout
|
||||
sandboxOrigin={sandboxOrigin}
|
||||
style={SHADOW_IFRAME_STYLE}
|
||||
style={shadowIframeStyle(sandboxOrigin)}
|
||||
/>
|
||||
),
|
||||
)}
|
||||
|
||||
@@ -6,7 +6,7 @@ export const PREVIEW_STAGE_INSET_PX = 8;
|
||||
|
||||
// clip-path as well as visibility: the player's loading overlay sets its own
|
||||
// visibility:visible and would otherwise paint over the live frame.
|
||||
export const SHADOW_IFRAME_STYLE: CSSProperties = {
|
||||
const SHADOW_IFRAME_STYLE: CSSProperties = {
|
||||
position: "absolute",
|
||||
inset: 0,
|
||||
visibility: "hidden",
|
||||
@@ -14,6 +14,16 @@ export const SHADOW_IFRAME_STYLE: CSSProperties = {
|
||||
pointerEvents: "none",
|
||||
};
|
||||
|
||||
const RENDERING_SHADOW_IFRAME_STYLE: CSSProperties = {
|
||||
position: "absolute",
|
||||
inset: 0,
|
||||
opacity: 0,
|
||||
pointerEvents: "none",
|
||||
};
|
||||
|
||||
export const shadowIframeStyle = (sandboxOrigin: "opaque" | undefined): CSSProperties =>
|
||||
sandboxOrigin === "opaque" ? RENDERING_SHADOW_IFRAME_STYLE : SHADOW_IFRAME_STYLE;
|
||||
|
||||
export function resolvePreviewStageSize(
|
||||
viewportWidth: number,
|
||||
viewportHeight: number,
|
||||
|
||||
@@ -86,6 +86,11 @@ function shadowPagePhase(iframe: HTMLIFrameElement | null): string {
|
||||
const pageGotTo = (iframe: HTMLIFrameElement | null) =>
|
||||
shadowPlayerReachable(iframe) ? "" : ` Its page had got to: ${shadowPagePhase(iframe)}.`;
|
||||
|
||||
function hyperframesPlayerOf(iframe: HTMLIFrameElement): Element | null {
|
||||
const root = iframe.getRootNode();
|
||||
return root instanceof ShadowRoot ? root.host : null;
|
||||
}
|
||||
|
||||
function isDocumentHidden(): boolean {
|
||||
return typeof document !== "undefined" && document.visibilityState === "hidden";
|
||||
}
|
||||
@@ -293,6 +298,7 @@ export function useShadowPreviewReload({
|
||||
// The store takes the new document's timeline only now that it is the one on screen, and reads it there.
|
||||
const retired = iframeRef.current;
|
||||
iframeRef.current = shadow;
|
||||
hyperframesPlayerOf(shadow)?.toggleAttribute("inert", false);
|
||||
pending.commit();
|
||||
shadowIframeRef.current = null;
|
||||
attachIframeShortcutListeners();
|
||||
@@ -403,6 +409,7 @@ export function useShadowPreviewReload({
|
||||
|
||||
const setShadowIframeNode = useCallback((node: HTMLIFrameElement | null) => {
|
||||
shadowIframeRef.current = node;
|
||||
if (node) hyperframesPlayerOf(node)?.toggleAttribute("inert", true);
|
||||
const gen = budgetGenRef.current;
|
||||
if (!node || !shadowFrameLeftPageRef.current || gen == null || gen !== shadowGenRef.current)
|
||||
return;
|
||||
|
||||
@@ -227,6 +227,26 @@ describe("shadow reload readiness and failure", () => {
|
||||
unmount(root);
|
||||
});
|
||||
|
||||
// The player turns pointer events back on for its frame, so a reload's frame would take the live one's clicks.
|
||||
it("keeps a reload's player out of clicks and focus until it is promoted, then gives them back", () => {
|
||||
const { getApi, gen, root } = beginReload();
|
||||
const shadow = makeShadowWithSpies();
|
||||
const player = document.createElement("hyperframes-player");
|
||||
player.attachShadow({ mode: "open" }).append(shadow.iframe);
|
||||
document.body.append(player);
|
||||
|
||||
act(() => getApi().setShadowIframeNode(shadow.iframe));
|
||||
expect(player.hasAttribute("inert")).toBe(true);
|
||||
|
||||
act(() => {
|
||||
getApi().onShadowIframeLoad(gen);
|
||||
getApi().onShadowReadyChange(gen, true);
|
||||
});
|
||||
expect(getApi().iframeRef.current).toBe(shadow.iframe);
|
||||
expect(player.hasAttribute("inert")).toBe(false);
|
||||
unmount(root);
|
||||
});
|
||||
|
||||
it("keeps a playing film playing through a reload, from where the live frame had reached", () => {
|
||||
const { getApi, root } = renderTimelinePlayerHarness();
|
||||
const { adapter: liveAdapter, win } = makeAdapterWindow();
|
||||
|
||||
Reference in New Issue
Block a user