Skip to content

Commit a423c93

Browse files
committed
refactor(studio): read animation cache keys through their owner
The timeline-element animation lookup rebuilt the three cache-key variants by hand. elementCacheKeys already owns that list for the writers, so this reader takes it from there instead of drifting from it.
1 parent 8f66b06 commit a423c93

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

packages/studio/src/components/nle/useTimelineEditCallbacks.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "../../contexts/DomEditContext";
1212
import { resolveTweenStart, resolveTweenDuration } from "../../utils/globalTimeCompiler";
1313
import { resolveClipTimingBasis } from "../../hooks/useGsapTweenCache";
14+
import { elementCacheKeys } from "../../hooks/gsapKeyframeCacheHelpers";
1415
import { resolveKeyframeRetime } from "../editor/keyframeRetime";
1516
import type { DomEditSelection } from "../editor/domEditingTypes";
1617
import type { TimelineMoveOperation } from "../../hooks/timelineMoveAdapter";
@@ -121,12 +122,13 @@ export function useTimelineEditCallbacks({
121122
const { gsapAnimations } = usePlayerStore.getState();
122123
const { sourceFile, domId } = splitTimelineElementKey(elementKey);
123124
const scope = sourceFile ?? activeCompPath ?? "index.html";
124-
return (
125-
gsapAnimations.get(`${scope}#${domId}`) ??
126-
gsapAnimations.get(`index.html#${domId}`) ??
127-
gsapAnimations.get(domId) ??
128-
[]
129-
);
125+
// elementCacheKeys owns the key-variant list the writers use; reading it
126+
// back by hand here is how the two sides drift.
127+
for (const key of elementCacheKeys(scope, domId)) {
128+
const animations = gsapAnimations.get(key);
129+
if (animations) return animations;
130+
}
131+
return [];
130132
},
131133
[activeCompPath],
132134
);

packages/studio/src/hooks/gsapKeyframeCacheHelpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ export function clearKeyframeCacheForFile(sourceFile: string): void {
113113
}
114114
}
115115

116-
function elementCacheKeys(sourceFile: string, elementId: string): string[] {
116+
/** Every cache key a write for this element sets, in read-preference order. */
117+
export function elementCacheKeys(sourceFile: string, elementId: string): string[] {
117118
return sourceFile === "index.html"
118119
? [`index.html#${elementId}`, elementId]
119120
: [`${sourceFile}#${elementId}`, `index.html#${elementId}`, elementId];

0 commit comments

Comments
 (0)