1. Read the FAQs 👇
✅
2. Describe the bug
Animations interrupted with suspense are not resumed when the React Compiler is enabled.
Fairly simply:
<Suspense>
<ComponentThatSuspends />
<motion.div initial={{ opacity: 0 }} exit={{ opacity: 1 }} />
</Suspense>
When the React Compiler is enabled will cause the animation to stop and not re-play on re-mount.
This happens when the reference to motion.div is stable across re-renders (which the compiler enables) - so motion.div does not re-render. The test suite doesn't use the compiler, it just keeps the reference to motion.div stable.
3. IMPORTANT: Provide a CodeSandbox reproduction of the bug
https://stackblitz.com/edit/node-rczx2erx?file=suspense.test.tsx
The repro is AI-generated
4. Steps to reproduce
Run npm install and npm test in the Stackblitz link
5. Expected behavior
The re-mounted component ends up with opacity: 1 (all the tests pass)
Extra context
Adding this layout effect to useVisualElement appears to fix the issue with all tests passing
const hasConnectedOnce = useRef(false);
useIsomorphicLayoutEffect(() => {
if (!hasConnectedOnce.current) {
hasConnectedOnce.current = true;
return;
}
visualElement.animationState?.animateChanges();
visualElement.enteringChildren = undefined;
}, []);
Because layout effects re-run when suspense ends. I'm not confident enough with the internals to know whether this is OK or not.
This is a very similar bug to: #2269
1. Read the FAQs 👇
✅
2. Describe the bug
Animations interrupted with suspense are not resumed when the React Compiler is enabled.
Fairly simply:
When the React Compiler is enabled will cause the animation to stop and not re-play on re-mount.
This happens when the reference to
motion.divis stable across re-renders (which the compiler enables) - somotion.divdoes not re-render. The test suite doesn't use the compiler, it just keeps the reference tomotion.divstable.3. IMPORTANT: Provide a CodeSandbox reproduction of the bug
https://stackblitz.com/edit/node-rczx2erx?file=suspense.test.tsx
The repro is AI-generated
4. Steps to reproduce
Run
npm installandnpm testin the Stackblitz link5. Expected behavior
The re-mounted component ends up with opacity: 1 (all the tests pass)
Extra context
Adding this layout effect to useVisualElement appears to fix the issue with all tests passing
Because layout effects re-run when suspense ends. I'm not confident enough with the internals to know whether this is OK or not.
This is a very similar bug to: #2269