mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 23:03:09 +00:00
fix(studio): drop stale timeline-select results to stop selection flicker
handleTimelineElementSelect tags each call with a monotonic token and ignores its result if a newer selection started while it was resolving, so a rapid A-to-B clip click can no longer let A's slower async lookup land after B and restore the wrong selection.
This commit is contained in:
@@ -127,6 +127,9 @@ export function useDomSelection({
|
||||
const domEditHoverSelectionRef = useRef<DomEditSelection | null>(domEditHoverSelection);
|
||||
const activeGroupElementRef = useRef<HTMLElement | null>(activeGroupElement);
|
||||
const compositionIdentityRef = useRef({ activeCompPath, projectId });
|
||||
// Monotonic token so a rapid A->B timeline-clip select can't let A's slower async
|
||||
// resolution land after B and restore the wrong selection.
|
||||
const timelineSelectSeqRef = useRef(0);
|
||||
|
||||
// Keep refs in sync with state
|
||||
domEditSelectionRef.current = domEditSelection;
|
||||
@@ -372,12 +375,15 @@ export function useDomSelection({
|
||||
const handleTimelineElementSelect = useCallback(
|
||||
async (element: TimelineElement | null) => {
|
||||
if (!STUDIO_INSPECTOR_PANELS_ENABLED) return;
|
||||
const seq = ++timelineSelectSeqRef.current;
|
||||
if (!element) {
|
||||
applyDomSelection(null, { revealPanel: false });
|
||||
return;
|
||||
}
|
||||
|
||||
const selection = await buildDomSelectionForTimelineElement(element);
|
||||
// A newer selection superseded this one while we were resolving — drop the stale result.
|
||||
if (seq !== timelineSelectSeqRef.current) return;
|
||||
if (selection) applyDomSelection(selection);
|
||||
},
|
||||
[applyDomSelection, buildDomSelectionForTimelineElement],
|
||||
|
||||
Reference in New Issue
Block a user