refactor(studio): single-source timeline selection id-resolution

The DOM-selection to timeline sync routes through the canonical resolveTimelineIdForSelection
(source-file, ancestor, active-comp fallback) instead of a narrow domId/id match that
mismatched sub-composition clips.

The preview-sync equality check compares selection as sets both ways and includes the
anchor, so duplicate resolutions no longer mask an unsynced member.
This commit is contained in:
Miguel Angel Simon Sierra
2026-07-09 16:54:34 -04:00
parent 04ddd411ec
commit 0fe38e8cc8
2 changed files with 28 additions and 9 deletions
@@ -11,6 +11,7 @@ import { useCallback, useEffect, useRef } from "react";
import type { DomEditSelection } from "../components/editor/domEditingTypes";
import { STUDIO_GSAP_PANEL_ENABLED } from "../components/editor/manualEditingAvailability";
import { usePlayerStore } from "../player";
import { resolveTimelineIdForSelection } from "../utils/studioHelpers";
import { useDomEditPreviewSync } from "./useDomEditPreviewSync";
import { useGsapAnimationsForElement, usePopulateKeyframeCacheForFile } from "./useGsapTweenCache";
import { useGsapAnimationFetchFallback } from "./useGsapAnimationFetchFallback";
@@ -171,12 +172,12 @@ export function useDomEditWiring({
useEffect(() => {
if (!domEditSelection?.id) return;
const { selectedElementId, elements, setSelectedElementId } = usePlayerStore.getState();
const matchKey = elements.find(
(el) => el.domId === domEditSelection.id || el.id === domEditSelection.id,
);
const key = matchKey ? (matchKey.key ?? matchKey.id) : null;
// Resolve through the canonical resolver (source-file + ancestor + active-comp
// fallback) rather than a narrow domId/id match, so a sub-composition selection
// maps to the same clip the rest of the selection pipeline picks.
const key = resolveTimelineIdForSelection(domEditSelection, elements, activeCompPath);
if (key && key !== selectedElementId) setSelectedElementId(key);
}, [domEditSelection?.id]);
}, [domEditSelection, activeCompPath]);
// ── GSAP cache sync ──