Skip to content
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

#4441: Improve animations and dynamically import animation libraries to reduce bundle size #4500

Merged
merged 29 commits into from
Aug 23, 2018

Conversation

dancastellon
Copy link
Contributor

@dancastellon dancastellon commented Aug 3, 2018

Resolves #4441
Impact: minor
Type: performance

Issue

We currently have velocity-animate in the client bundle at 94.5kb. We use Velocity for 5 things:

  1. Animate the cart drawer
  2. Flash a green color when input fields change
  3. Animate the sliding out of the admin panel
  4. Animate sliding up & down of admin panel cards
  5. Animating the opacity of the overlay when the orders panel is opened

Solution

Most of the animations are replaceable with CSS. Remove velocity-animate and replace those, using a new component called CSSTransitionGroup and CSS. Animating the height of admin panel cards requires JS. Use the small react-animate-height library for that.

Whether using CSSTransitionGroup or Animate height, the bundle size should not be affected (dynamic imports).

Note: This PR removes velocity-animate and velocity-react from package.json, and adds react-transition-group and react-animate-height - both of which are much smaller then Velocity.

Breaking changes

None

Testing

  1. Visit the homepage and open the cart drawer - confirm improved animation
  2. Click a tag in the nav and confirm cart drawer is still open
  3. Confirm on tag pages you can toggle cart drawer
  4. Change an existing tag's title in the header, confirm that leaving the input after change, or pressing enter after change, the input is flashed green
  5. PDP -> Details - Edit a metafield's key, confirm it flashes green. Confirm same with value
  6. Edit the product's title inline, and confirm it flashes green leaving the input after change, or pressing enter after change
  7. Edit subtitle inline and confirm it flashes green
  8. Edit vendor field inline and confirm it flashes green
  9. Edit a field in the variant form (other than tax code). Confirm it flashes a lighter green color
  10. Confirm admin panel can slide open/closed
  11. Confirm admin panel cards can slide up/down
  12. Click "Orders" and confirm black overlay fades in
  13. Click through to order detail, confirm detail panel slides in
  14. Confirm 10-13 while using an RTL language
  15. Confirm switching from LTR to RTL language, the admin bar is positioned correctly (no empty scrollbar on RTL, no cut-off icons when switching back to LTR)
  16. Confirm double-clicking a product in grid - in edit mode - brings you to PDP without crashing the app or any errors in console.
  17. Confirm none of these packages are in the client bundle: velocity-animate, velocity-react, react-animate-height, react-transition-group. Run with export TOOL_NODE_FLAGS='--max-old-space-size=4096' && METEOR_DISABLE_OPTIMISTIC_CACHING=1 meteor run --production --extra-packages bundle-visualizer

Before

velocity-before

After

velocity-after

@dancastellon dancastellon changed the title WIP #4441: Eliminate Velocity dependency by using CSS animations #4441: Eliminate Velocity dependency by using CSS animations Aug 6, 2018
@dancastellon dancastellon changed the title #4441: Eliminate Velocity dependency by using CSS animations WIP #4441: Eliminate Velocity dependency by using CSS animations Aug 6, 2018
@dancastellon dancastellon changed the title WIP #4441: Eliminate Velocity dependency by using CSS animations #4441: Eliminate Velocity dependency by using CSS animations Aug 6, 2018
@brent-hoover
Copy link
Collaborator

@dancastellon When editing tags I see the green flash when exiting the input but not when entering

@brent-hoover
Copy link
Collaborator

Seeing this error when I double-click on a product logged in as an admin

TypeError: Cannot read property 'add' of undefined
    at highlightInput (animations.js:11)
    at ProductAdmin.animateFieldFlash (productAdmin.js:188)
    at ProductAdmin.UNSAFE_componentWillReceiveProps (productAdmin.js:145)
    at callComponentWillReceiveProps (modules.js?hash=1106023c7619d36eb7b0e0c97f1437b533dbe087:200916)
    at updateClassInstance (modules.js?hash=1106023c7619d36eb7b0e0c97f1437b533dbe087:201105)
    at updateClassComponent (modules.js?hash=1106023c7619d36eb7b0e0c97f1437b533dbe087:202539)
    at beginWork (modules.js?hash=1106023c7619d36eb7b0e0c97f1437b533dbe087:203210)
    at performUnitOfWork (modules.js?hash=1106023c7619d36eb7b0e0c97f1437b533dbe087:205249)
    at workLoop (modules.js?hash=1106023c7619d36eb7b0e0c97f1437b533dbe087:205288)
    at renderRoot (modules.js?hash=1106023c7619d36eb7b0e0c97f1437b533dbe087:205328)

Copy link
Collaborator

@brent-hoover brent-hoover left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing a complete crash of the app when double-clicking on a product. Also it looks like we are only partially eliminating Velocity?

/**
* @name composer
* @private
* @summary Reactive Tracker wrapped function
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem like a very good description of this function

@@ -407,6 +405,7 @@ class ActionView extends Component {

renderDetailView() {
const { actionView } = this.props;
const { VelocityTransitionGroup } = this.state;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't understand why this is still here if we are eliminating Velocity. Do we need to just rename this?

@@ -47,6 +51,21 @@ class CardBody extends Component {
}

render() {
const { VelocityTransitionGroup } = this.state;
if (VelocityTransitionGroup === undefined) {
import("velocity-react")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't eliminating this as well?

@dancastellon dancastellon changed the title #4441: Eliminate Velocity dependency by using CSS animations WIP #4441: Eliminate Velocity dependency by using CSS animations Aug 9, 2018
@dancastellon
Copy link
Contributor Author

@zenweasel I originally left the <VelocityTransitionGroup /> component in because it had animations that triggered when components mounted/unmounted - something I thought would be tricky to replace with pure JS & CSS. After some research I found <ReactCSSTransitionGroup />, which allows me to use CSS animations on mount/unmount. It worked for all but 1 animation, the slide up/down on the dashboard panels. For that, I found <AnimateHeight />, and it works smoothly.

The downside is that while this would let us remove velocity-animate and velocity-react from package.json, we'd be adding 2 more libs - react-transition-group and animate-height. I'm wondering if you think it's worth it, or if we should revert back to keeping just velocity-react for the <VelocityTransitionGroup /> which we'd dynamically import (so the client bundle size isn't affected).

@dancastellon dancastellon changed the title WIP #4441: Eliminate Velocity dependency by using CSS animations WIP #4441: Improve animations and dynamically import animation libraries to reduce bundle size Aug 10, 2018
@dancastellon dancastellon changed the title WIP #4441: Improve animations and dynamically import animation libraries to reduce bundle size #4441: Improve animations and dynamically import animation libraries to reduce bundle size Aug 10, 2018
@aldeed
Copy link
Contributor

aldeed commented Aug 14, 2018

I vote for switching to react-transition-group and react-animate-height. They seem small and specific compared to using velocity. If you were to try to achieve the same thing, you'd essentially rebuild them.

@dancastellon
Copy link
Contributor Author

@aldeed I agree, done. react-animate-height is much smaller (7.7kb) than velocity-react (94.5kb).

@dancastellon dancastellon changed the title #4441: Improve animations and dynamically import animation libraries to reduce bundle size WIP #4441: Improve animations and dynamically import animation libraries to reduce bundle size Aug 16, 2018
@brent-hoover
Copy link
Collaborator

@dancastellon What's the status on this? Can we quickly make the changes that @aldeed requested?

@dancastellon dancastellon changed the title WIP #4441: Improve animations and dynamically import animation libraries to reduce bundle size #4441: Improve animations and dynamically import animation libraries to reduce bundle size Aug 17, 2018
@dancastellon
Copy link
Contributor Author

@zenweasel This one's ready to go. This morning I fixed a Can't call setState on an unmounted component error and ran through the testing instructions.

@aldeed aldeed changed the base branch from release-1.15.0 to release-1.16.0 August 23, 2018 19:24
@aldeed aldeed merged commit 201a154 into release-1.16.0 Aug 23, 2018
@aldeed aldeed deleted the perf-4441-dancastellon-eliminate-velocity branch August 23, 2018 19:25
@spencern
Copy link
Contributor

@dancastellon is there a specific reason you chose to go with v1.2.1 of react-transition-group instead of the latest v2.4.0?
As a result of this, we're loading two versions of this lib right now, v2.4.0 which is required by recompose one of our other dependencies and 1.2.1 which is required because of this PR.

Additionally, we're loading chain-function which is only a dependency of the older v1.2.1 version. I'd like to eliminate this older version unless there's a great reason to keep it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants