-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Feature Request] Async framer-motion loading #3340
Comments
Thanks for the info. We're also investigating this issue as well. |
@luzat can you also share what tool you used and how you recorded the size? |
@wingkwong I set up a basic Remix v2 project with Vite and mostly default settings. I manually added NextUI according to the documentation with single components (only I checked the bundles that were generated with I did not test with disabled animations, but in that case the import should have been skipped, given that the animation is included conditionally, and 45 to 150 KB saved. |
@xiaoluoer this is another issue which I've fixed already. See here. The fix will be available in the next bug fix release. |
Is your feature request related to a problem? Please describe.
Just adding a NextUI button increases bundle size a lot.
framer-motion
contributes 212 KB (uncompressed) in a production build here. It would be nice if a that could be reduced or loaded asynchronously.A second problem is, that Framer Motion is also be loaded if animations are disabled with
disableAnimation={true}
.Describe the solution you'd like
According to the framer Motion guide it's possible to load features asynchronously using a dynamic import. For many use cases quick initial loading would be preferable over having animations loaded right away.
#2929 already did most of the work required from what I can tell. In a test, I did replace the
domAnimation
in theripple
effect by a dynamic port and Vite did split the 212 KBframer-motion
chunk into 59 KB to be loaded initially and a large 150 KB (or 45 KB with Brotli) chunk that can be loaded asynchronously. I feel that this is a huge amount. Also, if the dynamic import is never invoked whendisableAnimation={true}
, this code would never have to be downloaded.I do not know if any other components would not work with that pattern or if there are cases when you might want to load the features synchronously. There could be at least two ways to go about this:
domAnimation
as a dynamic/static import and pass that to NextUI?)await import('@nextui/dom-animation')
or similarEven if code splitting won't work in all cases/components, this might be a helpful optimization for some projects.
Describe alternatives you've considered
Screenshots or Videos
No response
The text was updated successfully, but these errors were encountered: