fix(studio): an unsealed recording on an empty timeline records up to the composition's end (#8606)

This commit is contained in:
Miguel Ángel
2026-11-23 17:00:39 +00:00
committed by GitHub
parent 31be52d934
commit 4f863db6d7
2 changed files with 44 additions and 9 deletions
@@ -58,15 +58,21 @@ function startOn(
base: EditingGestureBase | null,
elementEnd?: number,
liveGsap?: Record<string, number>,
emptyTimeline = false,
) {
const iframe = document.createElement("iframe");
document.body.append(iframe);
if (liveGsap)
Object.assign(iframe.contentWindow!, {
gsap: { getProperty: (_element: Element, prop: string) => liveGsap[prop] },
gsap: { getProperty: (_element: Element, prop: string) => liveGsap[prop], set: vi.fn() },
...(emptyTimeline && {
__timelines: { main: { duration: () => 0, seek: vi.fn() } },
__player: { getTime: () => usePlayerStore.getState().currentTime },
}),
});
vi.spyOn(iframe, "getBoundingClientRect").mockReturnValue(new DOMRect(0, 0, 960, 540));
const standIn = document.createElement("div");
standIn.id = "card";
let recording: ReturnType<typeof useGestureRecording> | null = null;
function Harness() {
recording = useGestureRecording();
@@ -182,3 +188,35 @@ describe("a gesture recording on a sealed preview", () => {
expect([scaledBy(false), scaledBy(true)]).toEqual([1.6, 1.6]);
});
});
describe("a recording on a film whose own timeline is empty", () => {
const AT_REST_GSAP = { x: 0, y: 0, opacity: 1, scaleX: 1 };
const recordMove = (sealed: boolean) => {
ticks = [];
nowMs = 0;
frame.sealed = sealed;
frame.stage = { width: 1920, height: 1080 };
usePlayerStore.setState({ currentTime: 2, duration: 10, requestedSeekTime: null });
const { tick, stop } = startOn(sealed ? AT_REST : null, 2.5, AT_REST_GSAP, !sealed);
const move = (clientX: number, ms: number) => {
document.dispatchEvent(new MouseEvent("pointermove", { bubbles: true, clientX }));
tick(ms);
};
move(0, 0);
move(100, 300);
move(100, 900);
return stop().map(({ time, properties }) => ({ time, properties }));
};
// fails without the fix: unsealed capped the recording at its timeline's own length, 0 here, so every sample
// landed at 0 s, the playhead never moved and the recording saved nothing.
it("records over time unsealed, up to the layer's end within the film", () => {
const samples = recordMove(false);
expect(samples.at(-1)?.time).toBe(0.5);
expect(usePlayerStore.getState().currentTime).toBe(2.5);
});
it("records the same samples sealed and unsealed", () => {
expect(recordMove(false)).toEqual(recordMove(true));
});
});
@@ -84,7 +84,7 @@ function readBasePosition(element: HTMLElement, gsap: IframeGsap | null): BasePo
function connectGsapRuntime(
element: HTMLElement,
iframeEl: HTMLIFrameElement,
elementEndTime: number | undefined,
recordingEnd: number,
): GsapRuntime | null {
try {
const win = iframeEl.contentWindow as Window & {
@@ -101,14 +101,12 @@ function connectGsapRuntime(
)?.[1] ?? null)
: null;
if (win?.gsap?.set && tl?.seek && element.id) {
const tlDuration = tl.duration();
return {
timeline: tl,
gsap: win.gsap,
element,
startTime: win.__player?.getTime() ?? 0,
maxSeekTime:
elementEndTime != null && elementEndTime < tlDuration ? elementEndTime : tlDuration,
maxSeekTime: recordingEnd,
savedVisibility: element.style.visibility,
savedTranslate: element.style.getPropertyValue("translate"),
putMarkBack: null,
@@ -354,12 +352,11 @@ export function useGestureRecording() {
r.scale = scale;
// --- Phase 3: Connect to the iframe GSAP runtime ---
r.runtime = connectGsapRuntime(element, iframeEl, elementEndTime);
const { currentTime, duration } = usePlayerStore.getState();
const recordingEnd = Math.min(elementEndTime ?? Infinity, duration);
r.runtime = connectGsapRuntime(element, iframeEl, recordingEnd);
r.drawsOn = sealed ? element : null;
r.playhead = sealed
? { start: currentTime, end: Math.min(elementEndTime ?? Infinity, duration) }
: null;
r.playhead = sealed ? { start: currentTime, end: recordingEnd } : null;
const seekable = r.runtime
? { start: r.runtime.startTime, end: r.runtime.maxSeekTime }
: r.playhead;