Skip to content

πŸŽ₯ Make videos programmatically with React

`docs`: Add troubleshooting page for CSS animations (#6936)

Jonny Burger04abb11f02b1
diff --git a/packages/docs/docs/animating-properties.mdx b/packages/docs/docs/animating-properties.mdx
index 2534bfaa73..7bd1bf2253 100644
--- a/packages/docs/docs/animating-properties.mdx
+++ b/packages/docs/docs/animating-properties.mdx
@@ -100,3 +100,10 @@ The default spring configuration leads to a little bit of overshoot, meaning the
Watch out for flickering issues during rendering that arise if you write animations that are not driven by [`useCurrentFrame()`](/docs/use-current-frame) – for example CSS transitions.
[Read more about how Remotion's rendering works](/docs/flickering) - understanding it will help you avoid issues down the road.
+
+## See also
+
+- [Don't use CSS animations](/docs/troubleshooting/css-animations)
+- [`interpolate()`](/docs/interpolate)
+- [`spring()`](/docs/spring)
+- [Flickering](/docs/flickering)
diff --git a/packages/docs/docs/flickering.mdx b/packages/docs/docs/flickering.mdx
index 3018409529..96c8cc89bb 100644
--- a/packages/docs/docs/flickering.mdx
+++ b/packages/docs/docs/flickering.mdx
@@ -126,3 +126,4 @@ See the list of [third-party integrations](/docs/third-party) to see if there is
## See Also
- [Avoiding flickering in `<Player>`](/docs/troubleshooting/player-flicker)
+- [Don't use CSS animations](/docs/troubleshooting/css-animations)
diff --git a/packages/docs/docs/troubleshooting/css-animations.mdx b/packages/docs/docs/troubleshooting/css-animations.mdx
new file mode 100644
index 0000000000..8aec90516c
--- /dev/null
+++ b/packages/docs/docs/troubleshooting/css-animations.mdx
@@ -0,0 +1,68 @@
+---
+image: /generated/articles-docs-troubleshooting-css-animations.png
+sidebar_label: CSS animations
+title: Don't use CSS animations in Remotion
+crumb: "Common mistakes"
+---
+
+The following code does not work in Remotion:
+
+```tsx twoslash title="❌ Don't do this"
+// ---cut---
+const myMarkup = (
+ <div
+ style={{
+ animation: "fadeIn 1s forwards",
+ }}
+ >
+ Hello World!
+ </div>
+);
+```
+
+Similarly, using `transition`, `@keyframes`, or JavaScript-based timers like `setTimeout` to drive animations is also wrong.
+
+## Problem
+
+Remotion renders each frame independently. Frame 30 might be rendered before frame 10, or frame 50 might be rendered twice.
+Because CSS animations don't know which frame Remotion is currently rendering, the animation state will be wrong and you'll see:
+
+- Flickering or blank frames during rendering
+- Incorrect animation progress
+
+## Solution
+
+Drive all animations using [`useCurrentFrame()`](/docs/use-current-frame). This way, the animation state is derived from the frame number and is deterministic.
+
+Here is an example of a fade-in using [`interpolate()`](/docs/interpolate):
+
+```tsx twoslash title="βœ… Do this"
+// ---cut---
+import { AbsoluteFill, interpolate, useCurrentFrame } from "remotion";
+
+export const FadeIn = () => {
+ const frame = useCurrentFrame();
+ const opacity = interpolate(frame, [0, 30], [0, 1], {
+ extrapolateRight: "clamp",
+ });
+
+ return (
+ <AbsoluteFill
+ style={{
+ justifyContent: "center",
+ alignItems: "center",
+ backgroundColor: "white",
+ fontSize: 80,
+ }}
+ >
+ <div style={{ opacity }}>Hello World!</div>
+ </AbsoluteFill>
+ );
+};
+```
+
+## See also
+
+- [Animating properties](/docs/animating-properties)
+- [`interpolate()`](/docs/interpolate)
+- [Flickering](/docs/flickering)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index 35578ce253..77e9de6fd8 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -1394,6 +1394,7 @@ const sidebars: SidebarsConfig = {
'staticfile-relative-paths',
'staticfile-remote-urls',
'troubleshooting/background-image',
+ 'troubleshooting/css-animations',
'troubleshooting/nextjs-image',
'troubleshooting/rosetta',
'troubleshooting/loading-root-component',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 7b5056e01d..6467e1c39a 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -6475,6 +6475,15 @@ export const articles = [
noAi: false,
slug: 'troubleshooting/could-not-find-executable-to-run',
},
+ {
+ id: 'troubleshooting/css-animations',
+ title: "Don't use CSS animations in Remotion",
+ relativePath: 'docs/troubleshooting/css-animations.mdx',
+ compId: 'articles-docs-troubleshooting-css-animations',
+ crumb: 'Common mistakes',
+ noAi: false,
+ slug: 'troubleshooting/css-animations',
+ },
{
id: 'troubleshooting/debug-failed-render',
title: 'Debugging render failures',
diff --git a/packages/docs/static/generated/articles-docs-troubleshooting-css-animations.png b/packages/docs/static/generated/articles-docs-troubleshooting-css-animations.png
new file mode 100644
index 0000000000..e0699c40d3
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-troubleshooting-css-animations.png differ