Skip to content

(cherry-pick) fix: CSS animations not being removed from the stylesheet on web #7952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

MatiPl01
Copy link
Member

Summary

Cherry-pick of the #7932

## Summary

@m-bert noticed that animations aren't cleaned up from the Reanimated's
CSS stylesheet when components are unmounted. As a result, we ended up
having multiple instances of animations that were no longer used.

## Example recording

### Before

<video
src="https://github.com/user-attachments/assets/9e7d9987-80eb-44b0-8519-ee5a2978f2b0"></video>

### After

<video
src="https://github.com/user-attachments/assets/cb52aaca-7dab-4dfb-bd0a-98fe7e90a09a"></video>

### Test example

<details>
<summary>Code snippet</summary>

```tsx
import { useState } from 'react';
import { Button } from 'react-native';
import Animated from 'react-native-reanimated';

export default function App() {
  const [show, setShow] = useState(false);

  return (
    <>
      <Button title="Show" onPress={() => setShow(!show)} />
      {show && (
        <Animated.View
          style={{
            backgroundColor: 'green',
            flex: 1,
            animationName: {
              from: { backgroundColor: 'red' },
              to: { backgroundColor: 'blue' },
            },
            animationDuration: '1s',
            animationTimingFunction: 'ease-in-out',
            animationDelay: '0s',
            animationIterationCount: 'infinite',
            animationDirection: 'alternate',
            animationFillMode: 'forwards',
            animationPlayState: 'running',
          }}
        />
      )}
    </>
  );
}
```
</details>
@MatiPl01 MatiPl01 changed the base branch from main to 4.0-stable July 31, 2025 09:41
@MatiPl01 MatiPl01 requested a review from m-bert July 31, 2025 09:41
@MatiPl01 MatiPl01 self-assigned this Jul 31, 2025
@MatiPl01 MatiPl01 merged commit 01cd7e5 into 4.0-stable Jul 31, 2025
2 checks passed
@MatiPl01 MatiPl01 deleted the @matipl01/cherry-pick/fix-css-animations-not-cleaned-up branch July 31, 2025 09:54
@MatiPl01 MatiPl01 mentioned this pull request Jul 31, 2025
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants