From 68e9e1455b48734eca87b4a2b4cadfbf02e1ea8d Mon Sep 17 00:00:00 2001 From: Youssef Muhamad Date: Thu, 2 Jul 2020 14:10:11 -0300 Subject: [PATCH] [FIX] Handle TypeErrors on navigationRef and draftMessage due to null properties (#2232) Co-authored-by: Diego Mello --- app/AppContainer.js | 2 +- app/containers/InAppNotification/index.js | 2 +- app/containers/MessageBox/index.js | 2 +- app/share.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/AppContainer.js b/app/AppContainer.js index 4242c0cda..4023635f7 100644 --- a/app/AppContainer.js +++ b/app/AppContainer.js @@ -44,7 +44,7 @@ const App = React.memo(({ root, isMasterDetail }) => { const navTheme = navigationTheme(theme); React.useEffect(() => { - const state = Navigation.navigationRef.current.getRootState(); + const state = Navigation.navigationRef.current?.getRootState(); const currentRouteName = getActiveRouteName(state); Navigation.routeNameRef.current = currentRouteName; setCurrentScreen(currentRouteName); diff --git a/app/containers/InAppNotification/index.js b/app/containers/InAppNotification/index.js index 765f16078..fd0ad6368 100644 --- a/app/containers/InAppNotification/index.js +++ b/app/containers/InAppNotification/index.js @@ -11,7 +11,7 @@ export const INAPP_NOTIFICATION_EMITTER = 'NotificationInApp'; const InAppNotification = memo(() => { const show = (notification) => { const { payload } = notification; - const state = Navigation.navigationRef.current.getRootState(); + const state = Navigation.navigationRef.current?.getRootState(); const route = getActiveRoute(state); if (payload.rid) { if (route?.name === 'RoomView' && route.params?.rid === payload.rid) { diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index deb0c6a7f..b07626eac 100644 --- a/app/containers/MessageBox/index.js +++ b/app/containers/MessageBox/index.js @@ -196,7 +196,7 @@ class MessageBox extends Component { console.log('Messagebox.didMount: Thread not found'); } } else if (!sharing) { - msg = this.room.draftMessage; + msg = this.room?.draftMessage; } } catch (e) { log(e); diff --git a/app/share.js b/app/share.js index 8508c7c2d..93840b828 100644 --- a/app/share.js +++ b/app/share.js @@ -150,7 +150,7 @@ class Root extends React.Component { this.setState({ root: 'outside' }); } - const state = Navigation.navigationRef.current.getRootState(); + const state = Navigation.navigationRef.current?.getRootState(); const currentRouteName = getActiveRouteName(state); Navigation.routeNameRef.current = currentRouteName; setCurrentScreen(currentRouteName);