about summary refs log tree commit diff
path: root/app/javascript
diff options
context:
space:
mode:
authorMaciek Baron <thebezet@gmail.com>2018-07-04 14:34:28 +0100
committerEugen Rochko <eugen@zeonfederated.com>2018-07-04 15:34:28 +0200
commitf3af1a96a8456f6287c827aa96d363c92191024e (patch)
tree55f3d37d54cbbaa7f1bbc475e1d340e567912bfd /app/javascript
parent9dc413b02526f60865f14b7582ac4e89dc6673f3 (diff)
Check if router is injected in media modal (#7941)
Diffstat (limited to 'app/javascript')
-rw-r--r--app/javascript/mastodon/features/ui/components/media_modal.js20
1 files changed, 12 insertions, 8 deletions
diff --git a/app/javascript/mastodon/features/ui/components/media_modal.js b/app/javascript/mastodon/features/ui/components/media_modal.js
index c154da89a..6af0a101c 100644
--- a/app/javascript/mastodon/features/ui/components/media_modal.js
+++ b/app/javascript/mastodon/features/ui/components/media_modal.js
@@ -67,19 +67,23 @@ export default class MediaModal extends ImmutablePureComponent {
 
   componentDidMount () {
     window.addEventListener('keyup', this.handleKeyUp, false);
-    const history = this.context.router.history;
-    history.push(history.location.pathname, previewState);
-    this.unlistenHistory = history.listen(() => {
-      this.props.onClose();
-    });
+    if (this.context.router) {
+      const history = this.context.router.history;
+      history.push(history.location.pathname, previewState);
+      this.unlistenHistory = history.listen(() => {
+        this.props.onClose();
+      });
+    }
   }
 
   componentWillUnmount () {
     window.removeEventListener('keyup', this.handleKeyUp);
-    this.unlistenHistory();
+    if (this.context.router) {
+      this.unlistenHistory();
 
-    if (this.context.router.history.location.state === previewState) {
-      this.context.router.history.goBack();
+      if (this.context.router.history.location.state === previewState) {
+        this.context.router.history.goBack();
+      }
     }
   }