Skip to content

The open-source full-stack studio for Opus 5.5 motion video. Reverse engineering for any video. Code video with HTML: recreate, edit and render. BYOA + BYOK · Motion.md · Images, Video, Music & Voice.

fix(studio): refresh thumbnails after same-path media changes

罗高0038d1cb3e22
diff --git a/studio/src/hooks/useRenderClipContent.test.ts b/studio/src/hooks/useRenderClipContent.test.ts
index 53794f93..6b92f8af 100644
--- a/studio/src/hooks/useRenderClipContent.test.ts
+++ b/studio/src/hooks/useRenderClipContent.test.ts
@@ -24,7 +24,7 @@ import { useRenderClipContent } from "./useRenderClipContent";
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
afterEach(() => {
- usePlayerStore.setState({ thumbnailMode: "hidden", elements: [] });
+ usePlayerStore.setState({ thumbnailMode: "hidden", elements: [], thumbnailRevisions: {} });
document.body.innerHTML = "";
});
@@ -424,6 +424,43 @@ describe("useRenderClipContent", () => {
}
});
+ it.each(["img", "video"])("refreshes a mounted %s thumbnail after a same-path asset change", (tag) => {
+ usePlayerStore.setState({ thumbnailMode: "adaptive", thumbnailRevisions: {} });
+ const host = document.createElement("div");
+ const root = createRoot(host);
+ const source = `${window.location.origin}/api/projects/my-project/preview/assets/clip.${tag === "img" ? "svg" : "mp4"}?v=original#frame`;
+ let content: ReactNode = null;
+ function Harness() {
+ const render = useRenderClipContent({
+ projectIdRef: { current: "my-project" }, compIdToSrc: new Map(),
+ activePreviewUrl: null, effectiveTimelineDuration: 7,
+ });
+ content = render({ id: "clip", tag, src: source, start: 0, duration: 7, track: 0 }, { clip: "#222", label: "#fff" });
+ return null;
+ }
+ const src = () => isValidElement<{ imageSrc?: string; videoSrc?: string }>(content)
+ ? content.props.imageSrc ?? content.props.videoSrc : undefined;
+ try {
+ act(() => root.render(React.createElement(Harness)));
+ expect(src()).toBe(source);
+ act(() => usePlayerStore.getState().bumpThumbnailRevisions(null));
+ const updated = new URL(src()!);
+ expect(updated.searchParams.get("revision")).toBe("1");
+ expect(updated.searchParams.get("v")).toBe("original");
+ expect(updated.hash).toBe("#frame");
+ act(() => usePlayerStore.getState().bumpThumbnailRevisions(null));
+ expect(new URL(src()!).searchParams.get("revision")).toBe("2");
+ } finally { act(() => root.unmount()); }
+ });
+
+ it.each(["https://cdn.example.com/clip.png?signature=keep", "data:image/png;base64,eA==", "blob:http://localhost/asset"])(
+ "preserves non-project thumbnail source %s after a local edit", (src) => {
+ usePlayerStore.setState({ thumbnailMode: "adaptive", thumbnailRevisions: { "*": 3 } });
+ const content = renderClipContent({ id: "clip", tag: "img", src, start: 0, duration: 7, track: 0 }, null);
+ expect(isValidElement(content) && content.props).toMatchObject({ imageSrc: src });
+ },
+ );
+
it("finds the revision of a composition mounted with a ./ path", () => {
usePlayerStore.setState({
thumbnailMode: "adaptive",
diff --git a/studio/src/hooks/useRenderClipContent.ts b/studio/src/hooks/useRenderClipContent.ts
index 21479d2d..b523aca0 100644
--- a/studio/src/hooks/useRenderClipContent.ts
+++ b/studio/src/hooks/useRenderClipContent.ts
@@ -219,11 +219,22 @@ export function useRenderClipContent({
const htmlPreviewEligible = el.duration > 0 && effectiveTimelineDuration > 0;
if ((el.tag === "video" || el.tag === "img") && el.src) {
- const mediaSrc = resolveMediaPreviewUrl(
+ let mediaSrc = resolveMediaPreviewUrl(
authoredSrcPath(el.src),
pid,
window.location.origin,
);
+ const revision = thumbnailRevisionOf(thumbnailRevisions, "index.html");
+ const previewPrefix = buildProjectApiPath(pid, "/preview/");
+ if (
+ revision > 0 &&
+ (mediaSrc.startsWith(previewPrefix) ||
+ mediaSrc.startsWith(window.location.origin + previewPrefix))
+ ) {
+ const mediaUrl = new URL(mediaSrc, window.location.origin);
+ mediaUrl.searchParams.set("revision", String(revision));
+ mediaSrc = mediaUrl.href;
+ }
// Still images can't be decoded by VideoThumbnail's <video> extractor
// (the error event fires and the shimmer never resolves) — render the
// image itself as the strip.