Repository navigation
[Web LA] Adjust animation cleanup to slower devices - #7933
Merged
Merged
Conversation
m-bert
added this pull request to the merge queue
Jul 29, 2025
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Jul 30, 2025
… already (#7940) ## Summary Follows up #7933 Currently when the web animation is removed in the timeout (scheduleAnimationCleanup) before it has started, neither of the end/cancel events are fired, and so the callback is never called. The PR also ensures the callback is called always exactly once. ## Test plan 20x CPU throttling, check if the callback is called every time. also I'd recommend setting timeoutScale to a lower value temporarily to help reproducing the issue (the timeout has to run before the animation is started by the browser) <details> <summary>Code</summary> ```tsx import { useState } from 'react'; import { Button, View } from 'react-native'; import Animated, { Keyframe, Easing } from 'react-native-reanimated'; function Square() { const [visible, setVisible] = useState(false); const easing = Easing.bezier(0.76, 0.0, 0.24, 1.0).factory(); const animation = new Keyframe({ from: { transform: [{ translateX: '0%' }] }, to: { transform: [{ translateX: '100%' }], easing, }, }); return ( <View style={{ padding: 20, flex: 1, flexDirection: 'row', alignItems: 'center', }}> <Button title="Toggle" onPress={() => setVisible((visible) => !visible)} /> {visible && ( <Animated.View style={{ backgroundColor: 'red', width: 200, height: 200, flexDirection: 'row', flexWrap: 'wrap', }} exiting={animation .duration(300) .withCallback(() => console.log('callback!'))}> {Array(10000) .fill(0) .map((_, i) => ( <View key={i} style={{ backgroundColor: 'yellow', width: 2, height: 2 }} /> ))} </Animated.View> )} </View> ); } export default function App() { return ( <View style={{ flex: 1 }}> <Square /> </View> ); } ``` </details>
49 tasks done
10 tasks done
MatiPl01
pushed a commit
that referenced
this pull request
Aug 5, 2025
## Summary
Turns out that on slower devices when animation lags, it can be removed
from DOM before it finishes. This results in callbacks not being called
and `dummy` being left instead of removed.
This PR:
1. Adjusts timeout value for slower devices,
2. Removes dummy elements when their animation is removed from DOM
## Test plan
<details>
<summary>Tested on the following code, with 20x throttling enabled in
chrome dev tools:</summary>
```jsx
import { useState } from 'react';
import { Button, View } from 'react-native';
import Animated, { Keyframe, Easing } from 'react-native-reanimated';
function Square() {
const [visible, setVisible] = useState(false);
const easing = Easing.bezier(0.76, 0.0, 0.24, 1.0).factory();
const animation = new Keyframe({
from: { transform: [{ translateX: '0%' }] },
to: {
transform: [{ translateX: '100%' }],
easing,
},
});
return (
<View
style={{
padding: 20,
flex: 1,
flexDirection: 'row',
alignItems: 'center',
}}>
<Button
title="Toggle"
onPress={() => setVisible((visible) => !visible)}
/>
{visible && (
<Animated.View
style={{
backgroundColor: 'red',
width: 200,
height: 200,
flexDirection: 'row',
flexWrap: 'wrap',
}}
exiting={animation
.duration(300)
.withCallback(() => console.log('callback!'))}>
{Array(10000)
.fill(0)
.map((_, i) => (
<View
key={i}
style={{ backgroundColor: 'yellow', width: 2, height: 2 }}
/>
))}
</Animated.View>
)}
</View>
);
}
export default function App() {
return (
<View style={{ flex: 1 }}>
<Square />
</View>
);
}
```
</details>
MatiPl01
pushed a commit
that referenced
this pull request
Aug 5, 2025
… already (#7940) ## Summary Follows up #7933 Currently when the web animation is removed in the timeout (scheduleAnimationCleanup) before it has started, neither of the end/cancel events are fired, and so the callback is never called. The PR also ensures the callback is called always exactly once. ## Test plan 20x CPU throttling, check if the callback is called every time. also I'd recommend setting timeoutScale to a lower value temporarily to help reproducing the issue (the timeout has to run before the animation is started by the browser) <details> <summary>Code</summary> ```tsx import { useState } from 'react'; import { Button, View } from 'react-native'; import Animated, { Keyframe, Easing } from 'react-native-reanimated'; function Square() { const [visible, setVisible] = useState(false); const easing = Easing.bezier(0.76, 0.0, 0.24, 1.0).factory(); const animation = new Keyframe({ from: { transform: [{ translateX: '0%' }] }, to: { transform: [{ translateX: '100%' }], easing, }, }); return ( <View style={{ padding: 20, flex: 1, flexDirection: 'row', alignItems: 'center', }}> <Button title="Toggle" onPress={() => setVisible((visible) => !visible)} /> {visible && ( <Animated.View style={{ backgroundColor: 'red', width: 200, height: 200, flexDirection: 'row', flexWrap: 'wrap', }} exiting={animation .duration(300) .withCallback(() => console.log('callback!'))}> {Array(10000) .fill(0) .map((_, i) => ( <View key={i} style={{ backgroundColor: 'yellow', width: 2, height: 2 }} /> ))} </Animated.View> )} </View> ); } export default function App() { return ( <View style={{ flex: 1 }}> <Square /> </View> ); } ``` </details>
MatiPl01
added a commit
that referenced
this pull request
Aug 5, 2025
) Cherry-pick of the #7933 Co-authored-by: Michał Bert <63123542+m-bert@users.noreply.github.com>
MatiPl01
pushed a commit
that referenced
this pull request
Aug 5, 2025
… already (#7940) ## Summary Follows up #7933 Currently when the web animation is removed in the timeout (scheduleAnimationCleanup) before it has started, neither of the end/cancel events are fired, and so the callback is never called. The PR also ensures the callback is called always exactly once. ## Test plan 20x CPU throttling, check if the callback is called every time. also I'd recommend setting timeoutScale to a lower value temporarily to help reproducing the issue (the timeout has to run before the animation is started by the browser) <details> <summary>Code</summary> ```tsx import { useState } from 'react'; import { Button, View } from 'react-native'; import Animated, { Keyframe, Easing } from 'react-native-reanimated'; function Square() { const [visible, setVisible] = useState(false); const easing = Easing.bezier(0.76, 0.0, 0.24, 1.0).factory(); const animation = new Keyframe({ from: { transform: [{ translateX: '0%' }] }, to: { transform: [{ translateX: '100%' }], easing, }, }); return ( <View style={{ padding: 20, flex: 1, flexDirection: 'row', alignItems: 'center', }}> <Button title="Toggle" onPress={() => setVisible((visible) => !visible)} /> {visible && ( <Animated.View style={{ backgroundColor: 'red', width: 200, height: 200, flexDirection: 'row', flexWrap: 'wrap', }} exiting={animation .duration(300) .withCallback(() => console.log('callback!'))}> {Array(10000) .fill(0) .map((_, i) => ( <View key={i} style={{ backgroundColor: 'yellow', width: 2, height: 2 }} /> ))} </Animated.View> )} </View> ); } export default function App() { return ( <View style={{ flex: 1 }}> <Square /> </View> ); } ``` </details>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Turns out that on slower devices when animation lags, it can be removed from DOM before it finishes. This results in callbacks not being called and
dummybeing left instead of removed.This PR:
Test plan
Tested on the following code, with 20x throttling enabled in chrome dev tools: