-
-
Notifications
You must be signed in to change notification settings - Fork 812
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
Reducing canvas memory usage #1026
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit ab68333:
|
@@ -98,6 +98,7 @@ export function resolveVariant( | |||
export function checkIfControllingVariants(props: MotionProps) { | |||
return ( | |||
typeof (props.animate as AnimationControls)?.start === "function" || | |||
isVariantLabel(props.initial) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a drive by fix?
dev/tests/svg.tsx
Outdated
@@ -21,7 +21,7 @@ export const App = () => { | |||
data-testid="rotate" | |||
style={{ rotate: 45 }} | |||
/> | |||
<motion.rect | |||
{/* <motion.rect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This need to stay commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Aside from the clear problem it solves I think the solution of passing the visualState into useVisualElement is quite elegant 👌
This PR makes it possible for a
motion
component to render in static mode without instantiating aVisualElement
, significantly reducing memory consumption.A
VisualElement
is an abstraction around the renderer, by default the DOM. It enables us to performantly interact with the renderer and to communicate throughout the tree, away from React and its lifecycles. We create one for everymotion
component.Static mode is a flag we can switch on in the Framer canvas and in server rendering where
motion
components behave more like normal elements in that a newstyle
tag is created every render and no animations/gestures are mounted.This PR changes the architecture slightly so that the initial map of values is created externally from the
VisualElement
and can itself either be used to render themotion
component via React in static mode or to instantiate theVisualElement
in normal mode.This will save hundreds of megabytes of memory consumption from the Framer canvas in large prototypes. In a future refactor I'll change the
VisualElement
factory function to aclass
which will cut memory consumption in normal mode also.This architecture also gets us pretty close to allowing the
VisualElement
itself to be lazy loaded, so we can bring them
component down from 13kb to something closer to 5.