mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
fix(studio): a sealed preview's failed reload says only what the preview reported (#8194)
* test(studio): a sealed shadow's failed reload says only what it reported * fix(studio): a sealed preview's failed reload no longer blames a page that never loaded * fix(studio): a failed reload names the restore seek when the timeline already arrived * test(studio): keep the restore seek test's comment under 120 characters
This commit is contained in:
@@ -137,6 +137,7 @@ export function useShadowPreviewReload({
|
||||
// Invalidation counter, separate from the live slot's key: bumping it never remounts the live Player.
|
||||
const shadowGenRef = useRef(0);
|
||||
const pendingCommitRef = useRef<{ gen: number; commit: () => void } | null>(null);
|
||||
const acceptedTimelineGenRef = useRef<number | null>(null);
|
||||
const visuallyReadyGenRef = useRef<number | null>(null);
|
||||
const onPromotedRef = useRef(onPromoted);
|
||||
onPromotedRef.current = onPromoted;
|
||||
@@ -198,18 +199,26 @@ export function useShadowPreviewReload({
|
||||
cancelPendingLoadRef.current();
|
||||
stopHoldRef.current();
|
||||
pendingCommitRef.current = null;
|
||||
acceptedTimelineGenRef.current = null;
|
||||
visuallyReadyGenRef.current = null;
|
||||
}, []);
|
||||
|
||||
const failShadow = useCallback(
|
||||
(gen: number, cause: string) => {
|
||||
if (gen !== shadowGenRef.current) return;
|
||||
const waitingFor = !shadowPlayerReachable(shadowIframeRef.current)
|
||||
? "the page and its runtime to load"
|
||||
: pendingCommitRef.current?.gen !== gen
|
||||
? "its timeline to be ready"
|
||||
: "its loaders to clear";
|
||||
const got = pageGotTo(shadowIframeRef.current);
|
||||
const shadow = shadowIframeRef.current;
|
||||
const sealed = shadow !== null && previewFrameOpaque(shadow);
|
||||
const waitingFor =
|
||||
!sealed && !shadowPlayerReachable(shadow)
|
||||
? "the page and its runtime to load"
|
||||
: pendingCommitRef.current?.gen === gen
|
||||
? "its loaders to clear"
|
||||
: acceptedTimelineGenRef.current === gen
|
||||
? "its restore seek to paint"
|
||||
: sealed
|
||||
? "its runtime to report a timeline"
|
||||
: "its timeline to be ready";
|
||||
const got = sealed ? "" : pageGotTo(shadow);
|
||||
shadowGenRef.current += 1;
|
||||
const failedGen = shadowGenRef.current;
|
||||
stopPendingShadow();
|
||||
@@ -328,6 +337,7 @@ export function useShadowPreviewReload({
|
||||
const markAdapterReady = useCallback(
|
||||
(iframe: HTMLIFrameElement | null, gen: number | undefined, commit: () => void) => {
|
||||
if (gen == null || gen !== shadowGenRef.current) return;
|
||||
acceptedTimelineGenRef.current = gen;
|
||||
const register = () => {
|
||||
if (gen !== shadowGenRef.current) return;
|
||||
pendingCommitRef.current = { gen, commit };
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
renderTimelinePlayerHarness,
|
||||
resetPlayerStore,
|
||||
} from "./timelinePlayerTestHarness";
|
||||
import { sealedPreviewFrame } from "../lib/sealedPreviewFrame.test-helpers";
|
||||
|
||||
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
||||
|
||||
@@ -476,6 +477,49 @@ describe("shadow reload readiness and failure", () => {
|
||||
unmount(root);
|
||||
});
|
||||
|
||||
// fails without the fix: a sealed shadow refuses every read, so it was always reported as a page that never loaded.
|
||||
it("says only what a sealed shadow reported when it fails to reload", () => {
|
||||
vi.useFakeTimers();
|
||||
vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
const onPreviewReloadFailed = vi.fn();
|
||||
const { getApi, gen, root } = beginReload({ onPreviewReloadFailed });
|
||||
const sealed = sealedPreviewFrame().iframe;
|
||||
Object.defineProperty(sealed, "isConnected", { value: true });
|
||||
act(() => {
|
||||
getApi().setShadowIframeNode(sealed);
|
||||
getApi().onShadowIframeLoad(gen);
|
||||
});
|
||||
|
||||
act(() => void vi.advanceTimersByTime(FULL_WAIT_MS));
|
||||
|
||||
const [message] = onPreviewReloadFailed.mock.calls[0]!;
|
||||
expect(message).toContain("still waiting for its runtime to report a timeline");
|
||||
expect(message).not.toContain("Its page had got to");
|
||||
unmount(root);
|
||||
});
|
||||
|
||||
// fails without the fix: a timeline accepted but not yet committed (restore seek painting) read as none.
|
||||
it("names the restore seek when a shadow's timeline arrived but its seek never painted", () => {
|
||||
vi.useFakeTimers();
|
||||
vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
const onPreviewReloadFailed = vi.fn();
|
||||
const { getApi, gen, root } = beginReload({ onPreviewReloadFailed });
|
||||
const shadow = makeShadowWithSpies();
|
||||
Object.assign(shadow.iframe.contentWindow!, {
|
||||
__hfWaitForSeekCompletion: () => new Promise<void>(() => {}),
|
||||
});
|
||||
act(() => {
|
||||
getApi().setShadowIframeNode(shadow.iframe);
|
||||
getApi().onShadowIframeLoad(gen);
|
||||
});
|
||||
|
||||
act(() => void vi.advanceTimersByTime(FULL_WAIT_MS));
|
||||
|
||||
const [message] = onPreviewReloadFailed.mock.calls[0]!;
|
||||
expect(message).toContain("still waiting for its restore seek to paint");
|
||||
unmount(root);
|
||||
});
|
||||
|
||||
it("names the loaders when a shadow with a ready timeline never clears them", () => {
|
||||
vi.useFakeTimers();
|
||||
vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
|
||||
Reference in New Issue
Block a user