Skip to content

Commit aa6a8da

Browse files
committed
Evaluate keyframe keys lazily in fallback of commitStyles
1 parent 60cbc48 commit aa6a8da

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

src/hooks/core.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const createHandle = () => {
7474
_commit: (
7575
animation: Animation | undefined,
7676
el: HTMLElement,
77-
keys: string[]
77+
getKeys: () => string[]
7878
) => {
7979
if (!animation) return;
8080
if (animation.commitStyles) {
@@ -83,7 +83,7 @@ export const createHandle = () => {
8383
}
8484
// Fallback for commitStyles
8585
const computedStyle = getComputedStyle(el);
86-
keys.forEach((k) => {
86+
getKeys().forEach((k) => {
8787
(el.style as any)[k] = (computedStyle as any)[k];
8888
});
8989
},

src/hooks/useAnimation.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ export const useAnimation = (
9696
return externalHandle;
9797
},
9898
commit: () => {
99-
handle._commit(
100-
getAnimation(),
101-
getTarget()!,
99+
handle._commit(getAnimation(), getTarget()!, () =>
102100
getKeyframeKeys(getKeyframes())
103101
);
104102
return externalHandle;

src/hooks/useAnimations.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ export const useAnimations = <ID extends string>(
9898
return externalHandle;
9999
},
100100
commit: (name) => {
101-
handle._commit(
102-
getAnimation(name),
103-
getTarget()!,
101+
handle._commit(getAnimation(name), getTarget()!, () =>
104102
getKeyframeKeys(toArray(getKeyframesAndOptions(name)[0]))
105103
);
106104
return externalHandle;

0 commit comments

Comments
 (0)