-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Navigator: use CSS animations instead of framer-motion #56909
Conversation
@tyxla feel free to test this version of the component and let me know if it's worth continuing the work on this PR. |
Flaky tests detected in 6599008. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7192313789
|
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.
Thank you for trying it out, @ciampo 🙌
This looks great in my testing! Here's a demo:
Screen.Recording.2023-12-11.at.15.40.00.mov
While this doesn't resolve all the performance issues on the site editor, it definitely adds a visual improvement since there's no more clunky resizing of the sidebar screen content. cc @draganescu
We'll definitely have to do some further work to improve site editor performance, but in the meantime, I think we should move forward with this approach.
I've left a few questions and some feedback too, let me know what you think!
function UnconnectedNavigatorScreen( | ||
props: Props, | ||
props: WordPressComponentProps< NavigatorScreenProps, 'div', false >, |
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.
Nice simplification of the types 👍
Any backward compatibility concerns? For example, we won't be able to use any of the framer motion animation events like onAnimationStart
/ onAnimationComplete
.
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.
If I recall correctly (and interpret the previous TypeScript code correctly), that shouldn't be a problem because Navigator
was previously not documenting props specific to framer-motion
that would overlap with standard HTML properties (like onAnimationStart
).
So, with the changes from this PR, the component should now accept the default HTML onAnimationStart
etc
…tead of framer motion
25875f8
to
f84568c
Compare
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.
Nothing further from me. Great work 🚀
Performance-wise, the site editor continues to be heavy, so we'll have to continue improving it, but this does fix the visual glitch while navigating between screens that was originally reported in #55892. We'll keep #55892 open anyway because there's a ton we can still improve in that area.
For me this PR in Firefox works a bit weird: navigator-css-animation.mp4
|
Hey @draganescu , I just tested My suspicion is that the site editor is slower in Firefox compared to Chrome, which causes the animations to stutter to the point that it looks like they don't happen at all and/or are glitchy. This is especially true when animating to/from the patterns screen. As explained above, the changes in this PR can only partially improve the perception of smoothness on the |
* Move navigator provider styles to separate file * Move navigator screen styles to separate file, use CSS animations instead of framer motion * Remove unused import * Spacing * Use standard ease-in-out easing function * Remove stale comments * Remove animation-specific tests (as they can't be tested in jsdom) * CHANGELOG * Add comment * Avoid running the `css` function when unnecessary
What?
Related to #55892
Use vanilla CSS animations for the
Navigator
components instead offramer-motion
Why?
This PR doesn't fix the real cause for #55892, but aims at improving a visual side-effect caused by it
framer-motion
animations updated thestyle
attribute of the animating DOM element, setting a new value for every frame. In other words,framer-motion
performed some calculations in every animation frame to interpolate the exact values of the animation (ie. translation). These calculations happen on the main thread, and therefore the animation can get quite janky if the main thread is busy with other tasks (see #55892).Using vanilla CSS allows the animation to run directly on the GPU, running smoothly regardless of how busy the CPU is.
Furthermore, the animations required for this component are simple enough to be written with vanilla CSS, and don't necessarily require the sophisticated orchestration features that
framer-motion
offers.How?
styles.ts
fileframer-motion
with CSS animationscontain: strict
to the provider screen wrapper to further potentially enhance rendering performanceNote: with this PR, navigator screens don't have an exit animation anymore, as it would require a larger refactor (that's because the previous
NavigatorScreen
's wrapper element gets removed from the DOM as soon the selected screenid
changes).Testing Instructions
Navigator
component in Storybook:prefers-reduced-motion
option is enabledtrunk
(see Site Editor: Slow performance with complex block themes #55892)trunk
, especially when navigating across the submenusScreenshots or screencast
Before (
trunk
)Notice the jankiness (even while testing on a high-end machine), especially while navigating to/from the "Patterns" navigator screen
navigator-css-before.mp4
After (this PR)
No jankiness
navigator-css-after.mp4