From f3af1a96a8456f6287c827aa96d363c92191024e Mon Sep 17 00:00:00 2001 From: Maciek Baron Date: Wed, 4 Jul 2018 14:34:28 +0100 Subject: [PATCH] Check if router is injected in media modal (#7941) --- .../features/ui/components/media_modal.js | 20 +++++++++++-------- 1 file 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(); + } } }