about summary refs log tree commit diff
path: root/app/javascript
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>2018-02-25 03:10:57 +0900
committerEugen Rochko <eugen@zeonfederated.com>2018-02-24 19:10:57 +0100
commit7cb49eaa3aad03b60a1e1620d2f700d6ed2b3ea0 (patch)
tree21101f9ce659163fac0fa07c0b1ea5c847e7a075 /app/javascript
parent4d8c0d995981d580fa774950fa93c17b0004246e (diff)
Do not use function name to track components (#6542)
UglifyJS2 is allowed to mangle function names, and function names can also
be duplicate if they are from different scopes. Therefore function names
are not reliable as identifiers.

Functions as keys for Map object is a cheaper and more reliable
alternative.
Diffstat (limited to 'app/javascript')
-rw-r--r--app/javascript/mastodon/features/ui/components/bundle.js11
1 files changed, 5 insertions, 6 deletions
diff --git a/app/javascript/mastodon/features/ui/components/bundle.js b/app/javascript/mastodon/features/ui/components/bundle.js
index fc88e0c70..06a6c9cdd 100644
--- a/app/javascript/mastodon/features/ui/components/bundle.js
+++ b/app/javascript/mastodon/features/ui/components/bundle.js
@@ -26,7 +26,7 @@ class Bundle extends React.Component {
     onFetchFail: noop,
   }
 
-  static cache = {}
+  static cache = new Map
 
   state = {
     mod: undefined,
@@ -51,13 +51,12 @@ class Bundle extends React.Component {
 
   load = (props) => {
     const { fetchComponent, onFetch, onFetchSuccess, onFetchFail, renderDelay } = props || this.props;
+    const cachedMod = Bundle.cache.get(fetchComponent);
 
     onFetch();
 
-    if (Bundle.cache[fetchComponent.name]) {
-      const mod = Bundle.cache[fetchComponent.name];
-
-      this.setState({ mod: mod.default });
+    if (cachedMod) {
+      this.setState({ mod: cachedMod.default });
       onFetchSuccess();
       return Promise.resolve();
     }
@@ -71,7 +70,7 @@ class Bundle extends React.Component {
 
     return fetchComponent()
       .then((mod) => {
-        Bundle.cache[fetchComponent.name] = mod;
+        Bundle.cache.set(fetchComponent, mod);
         this.setState({ mod: mod.default });
         onFetchSuccess();
       })