]> cat aescling's git repositories - mastodon.git/commitdiff
Avoid unnecessary Motion components in icon_button.js (#5544)
authorNolan Lawson <nolan@nolanlawson.com>
Fri, 27 Oct 2017 17:08:07 +0000 (10:08 -0700)
committerEugen Rochko <eugen@zeonfederated.com>
Fri, 27 Oct 2017 17:08:07 +0000 (19:08 +0200)
app/javascript/mastodon/components/icon_button.js

index d8e445cefc8fc741cea84ea902d47d87456bb8a9..06f53841d2362cbe28ec60c6e7b54ede58f41ce8 100644 (file)
@@ -72,6 +72,25 @@ export default class IconButton extends React.PureComponent {
       overlayed: overlay,
     });
 
+    if (!animate) {
+      // Perf optimization: avoid unnecessary <Motion> components unless
+      // we actually need to animate.
+      return (
+        <button
+          aria-label={title}
+          aria-pressed={pressed}
+          aria-expanded={expanded}
+          title={title}
+          className={classes}
+          onClick={this.handleClick}
+          style={style}
+          tabIndex={tabIndex}
+        >
+          <i className={`fa fa-fw fa-${icon}`} aria-hidden='true' />
+        </button>
+      );
+    }
+
     return (
       <Motion defaultStyle={{ rotate: active ? -360 : 0 }} style={{ rotate: animate ? spring(active ? -360 : 0, { stiffness: 120, damping: 7 }) : 0 }}>
         {({ rotate }) =>