mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-10 22:20:14 +00:00
fix(studio): re-sync soft-reloaded timelines to the studio's own scrub time
Dragging a motion-path keyframe node committed correctly, but the soft reload that refreshes the preview re-seeked the freshly rebuilt GSAP timeline using the iframe's raw __player.getTime(), which can lag the studio's authoritative currentTime right after a keyframe drag parks the playhead. The stale seek left the element (and its selection/motion-path overlay) rendered at an unrelated position after the edit. applySoftReload now takes the caller's currentTime instead of trusting the iframe's own clock, and the re-seek runs before __hfForceTimelineRebind so its internal force-render picks up the correct time.
This commit is contained in:
@@ -175,6 +175,7 @@ export function applySoftReload(
|
||||
iframe: HTMLIFrameElement | null,
|
||||
scriptText: string,
|
||||
onAsyncFailure?: () => void,
|
||||
currentTimeOverride?: number,
|
||||
): SoftReloadResult {
|
||||
if (!iframe || !scriptText) return "cannot-soft-reload";
|
||||
|
||||
@@ -210,7 +211,14 @@ export function applySoftReload(
|
||||
// rather than killing the target timeline and appending an orphan script.
|
||||
if (gsapScripts.length > 1 && staleScripts.length === 0) return "cannot-soft-reload";
|
||||
|
||||
const currentTime = win.__player?.getTime?.() ?? 0;
|
||||
// Prefer the caller-supplied scrub position (the studio's own authoritative
|
||||
// currentTime, e.g. usePlayerStore) over the iframe's raw `__player.getTime()`:
|
||||
// the two can desync (a keyframe-node drag parks the playhead via the store
|
||||
// BEFORE this reload's async commit resolves, and the iframe's own GSAP clock
|
||||
// doesn't reliably reflect that yet), which re-seeks the freshly rebuilt
|
||||
// timeline to the wrong frame and leaves the element (and its overlay)
|
||||
// rendered at a stale/unrelated position.
|
||||
const currentTime = currentTimeOverride ?? win.__player?.getTime?.() ?? 0;
|
||||
|
||||
// Track whether the MotionPath async path was taken. When it is, the script
|
||||
// executes inside pluginScript.onload — after applySoftReload has already
|
||||
@@ -300,8 +308,13 @@ export function applySoftReload(
|
||||
const s = doc.createElement("script");
|
||||
s.textContent = `(function(){${scriptText}\n})();`;
|
||||
doc.body.appendChild(s);
|
||||
win.__hfForceTimelineRebind?.();
|
||||
// Seek BEFORE rebind: __hfForceTimelineRebind's own internal force-render
|
||||
// (see init.ts) renders the freshly-created timeline at whatever the
|
||||
// runtime's internal scrub position already is, not at whatever we pass
|
||||
// here afterward — a redundant seek() call after rebind can be a GSAP
|
||||
// no-op if the timeline already reports being at that time internally.
|
||||
win.__player?.seek?.(currentTime);
|
||||
win.__hfForceTimelineRebind?.();
|
||||
win.__hfStudioManualEditsApply?.();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user