about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorunarist <m.unarist@gmail.com>2017-07-09 21:52:03 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-07-09 14:52:03 +0200
commitcaf938562ef0d0fdb03bf57f15bbab8d76c5b4c0 (patch)
treede89430947428e0b4b917a78d5cf37cbda58b62c /app
parentce3a371eeeaae35e49f1938ede5eb6105c764fbc (diff)
Avoid async import if the component is previously loaded (#4127)
Diffstat (limited to 'app')
-rw-r--r--app/javascript/mastodon/features/ui/components/bundle.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/app/javascript/mastodon/features/ui/components/bundle.js b/app/javascript/mastodon/features/ui/components/bundle.js
index 3eed446fe..72798f690 100644
--- a/app/javascript/mastodon/features/ui/components/bundle.js
+++ b/app/javascript/mastodon/features/ui/components/bundle.js
@@ -26,6 +26,8 @@ class Bundle extends React.Component {
     onFetchFail: noop,
   }
 
+  static cache = {}
+
   state = {
     mod: undefined,
     forceRender: false,
@@ -58,8 +60,17 @@ class Bundle extends React.Component {
       this.timeout = setTimeout(() => this.setState({ forceRender: true }), renderDelay);
     }
 
+    if (Bundle.cache[fetchComponent.name]) {
+      const mod = Bundle.cache[fetchComponent.name];
+
+      this.setState({ mod: mod.default });
+      onFetchSuccess();
+      return Promise.resolve();
+    }
+
     return fetchComponent()
       .then((mod) => {
+        Bundle.cache[fetchComponent.name] = mod;
         this.setState({ mod: mod.default });
         onFetchSuccess();
       })