Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(studio): a failed preview reload says which step it was still waiting for (#5700)
Miguel Ángel72666462647c
diff --git a/packages/studio/src/player/hooks/useShadowPreviewReload.ts b/packages/studio/src/player/hooks/useShadowPreviewReload.tsindex ea9e3a7199..7233c2a6c6 100644--- a/packages/studio/src/player/hooks/useShadowPreviewReload.ts+++ b/packages/studio/src/player/hooks/useShadowPreviewReload.ts@@ -35,6 +35,14 @@ function restoreSeekPainted(iframe: HTMLIFrameElement | null): Promise<void> | ureturn win?.__hfWaitForSeekCompletion?.().catch(() => {});}+function shadowPlayerReachable(iframe: HTMLIFrameElement | null): boolean {+ try {+ return Boolean((iframe?.contentWindow as IframeWindow | null | undefined)?.__player);+ } catch {+ return false;+ }+}+function isDocumentHidden(): boolean {return typeof document !== "undefined" && document.visibilityState === "hidden";}@@ -104,6 +112,11 @@ export function useShadowPreviewReload({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";shadowGenRef.current += 1;stopPendingShadow();shadowIframeRef.current = null;@@ -111,8 +124,8 @@ export function useShadowPreviewReload({pendingSeekRef.current = null;setPreviewSlots(planShadowDiscard);setPreviewReloading(false);- const message = `The preview did not reload (${cause}). The previous preview is still showing.`;- logReload("shadow-failed", { cause });+ const message = `The preview did not reload (${cause}). It was still waiting for ${waitingFor}. The previous preview is still showing.`;+ logReload("shadow-failed", { cause, waitingFor });console.error(`[studio] ${message}`);onReloadFailedRef.current?.(message);},diff --git a/packages/studio/src/player/hooks/useTimelinePlayer.shadowReload.test.ts b/packages/studio/src/player/hooks/useTimelinePlayer.shadowReload.test.tsindex 55e93d0e0f..a1006cafe8 100644--- a/packages/studio/src/player/hooks/useTimelinePlayer.shadowReload.test.ts+++ b/packages/studio/src/player/hooks/useTimelinePlayer.shadowReload.test.ts@@ -371,6 +371,9 @@ describe("shadow reload readiness and failure", () => {expect(getApi().iframeRef.current).toBe(live);expect(live.style.visibility).toBe("");expect(onPreviewReloadFailed).toHaveBeenCalledWith(expect.stringContaining("too long"));+ expect(onPreviewReloadFailed).toHaveBeenCalledWith(+ expect.stringContaining("still waiting for the page and its runtime to load"),+ );expect(consoleError).toHaveBeenCalled();unmount(root);});@@ -395,6 +398,48 @@ describe("shadow reload readiness and failure", () => {act(() => void vi.advanceTimersByTime(1));expect(getApi().previewSlots).toEqual([{ gen: 0, role: "live" }]);expect(onPreviewReloadFailed).toHaveBeenCalledWith(expect.stringContaining("too long"));+ expect(onPreviewReloadFailed).toHaveBeenCalledWith(+ expect.stringContaining("still waiting for the page and its runtime to load"),+ );+ unmount(root);+ });++ it("names the timeline when a shadow's runtime runs but never reports a length", () => {+ vi.useFakeTimers();+ vi.spyOn(console, "error").mockImplementation(() => {});+ const onPreviewReloadFailed = vi.fn();+ const { getApi, gen, root } = beginReload({ onPreviewReloadFailed });+ const lengthless = makeFakeIframe(makeAdapterWindow({ duration: 0 }).win);+ act(() => {+ getApi().setShadowIframeNode(lengthless);+ getApi().onShadowIframeLoad(gen);+ getApi().onShadowReadyChange(gen, true);+ });++ act(() => void vi.advanceTimersByTime(FULL_WAIT_MS));++ expect(onPreviewReloadFailed).toHaveBeenCalledWith(+ expect.stringContaining("still waiting for its timeline to be ready"),+ );+ unmount(root);+ });++ it("names the loaders when a shadow with a ready timeline never clears them", () => {+ vi.useFakeTimers();+ vi.spyOn(console, "error").mockImplementation(() => {});+ const onPreviewReloadFailed = vi.fn();+ const { getApi, gen, root } = beginReload({ onPreviewReloadFailed });+ const shadow = makeShadowWithSpies();+ act(() => {+ getApi().setShadowIframeNode(shadow.iframe);+ getApi().onShadowIframeLoad(gen);+ });++ act(() => void vi.advanceTimersByTime(FULL_WAIT_MS));++ expect(onPreviewReloadFailed).toHaveBeenCalledWith(+ expect.stringContaining("still waiting for its loaders to clear"),+ );unmount(root);});@@ -475,6 +520,31 @@ describe("shadow reload readiness and failure", () => {unmount(root);});+ it("still drops and reports a shadow whose window throws on access", () => {+ vi.spyOn(console, "error").mockImplementation(() => {});+ const onPreviewReloadFailed = vi.fn();+ const { getApi, live, gen, root } = beginReload({ onPreviewReloadFailed });+ const crossOrigin = makeFakeIframe(+ Object.defineProperty({}, "__player", {+ get: () => {+ throw new DOMException("Blocked a frame", "SecurityError");+ },+ }),+ );+ act(() => getApi().setShadowIframeNode(crossOrigin));++ act(() => getApi().onShadowError(gen, "Composition timeline not found after 8s"));++ expect(getApi().previewSlots).toEqual([{ gen: 0, role: "live" }]);+ expect(getApi().iframeRef.current).toBe(live);+ expect(isPreviewChanging()).toBe(false);+ expect(onPreviewReloadFailed).toHaveBeenCalledTimes(1);+ expect(onPreviewReloadFailed).toHaveBeenCalledWith(+ expect.stringContaining("still waiting for the page and its runtime to load"),+ );+ unmount(root);+ });+it("drops a shadow whose document reports an error and reports the cause", () => {vi.spyOn(console, "error").mockImplementation(() => {});const onPreviewReloadFailed = vi.fn();