diff --git a/dev/tests/suspence.tsx b/dev/tests/suspence.tsx new file mode 100644 index 0000000000..0401b31c89 --- /dev/null +++ b/dev/tests/suspence.tsx @@ -0,0 +1,68 @@ +import { Suspense, useEffect, useState } from "react" +import { motion } from "framer-motion" + +const SuspenseTest = ({ shouldSuspend }: { shouldSuspend: boolean }) => { + const [promise, setPromise] = useState>(null) + + useEffect(() => { + let timeoutId = setTimeout(() => { + setPromise( + new Promise((resolve) => { + timeoutId = setTimeout(() => { + resolve() + setPromise(null) + timeoutId = null + }, 1000) + }) + ) + }, 1000) + + return () => { + if (timeoutId != null) { + clearTimeout(timeoutId) + } + } + }, []) + + if (promise && shouldSuspend) { + throw promise + } + + return ( + + {shouldSuspend ? "With suspense" : "Without suspense"} + + ) +} + +export function App() { + const [count, setCount] = useState(0) + + return ( + <> + +
+
+ Suspended
}> + + +
+ {/* */} + +

+ The above animation is the same for both components. One + suspends halfway through and the other does not. Click "Re-mount + components" to run the animations again. Notice how the scale + animation is stuck half way and the opacity animation is reset + in the suspended component. +

+ + ) +}