@@ -94,10 +94,23 @@ export default class RightPanel extends React.Component<IProps, IState> {
94
94
}
95
95
96
96
public static getDerivedStateFromProps ( props : IProps ) : Partial < IState > {
97
- const currentCard = RightPanelStore . instance . currentCardForRoom ( props . room . roomId ) ;
97
+ let currentCard : IRightPanelCard ;
98
+ if ( props . room ) {
99
+ currentCard = RightPanelStore . instance . currentCardForRoom ( props . room . roomId ) ;
100
+ }
101
+ if ( props . groupId ) {
102
+ currentCard = RightPanelStore . instance . currentGroup ;
103
+ }
104
+
105
+ if ( currentCard ?. phase && ! RightPanelStore . instance . isPhaseValid ( currentCard . phase , ! ! props . room ) ) {
106
+ // XXX: We can probably get rid of this workaround once GroupView is dead, it's unmounting happens weirdly
107
+ // late causing the app to soft-crash due to lack of a room object being passed to a RightPanel
108
+ return null ; // skip this update, we're about to be unmounted and don't have the appropriate props
109
+ }
110
+
98
111
return {
99
- cardState : currentCard . state ,
100
- phase : currentCard . phase ,
112
+ cardState : currentCard ? .state ,
113
+ phase : currentCard ? .phase ,
101
114
} ;
102
115
}
103
116
@@ -118,11 +131,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
118
131
} ;
119
132
120
133
private onRightPanelStoreUpdate = ( ) => {
121
- const currentCard = RightPanelStore . instance . currentCardForRoom ( this . props . room . roomId ) ;
122
- this . setState ( {
123
- cardState : currentCard . state ,
124
- phase : currentCard . phase ,
125
- } ) ;
134
+ this . setState ( { ...RightPanel . getDerivedStateFromProps ( this . props ) as IState } ) ;
126
135
} ;
127
136
128
137
private onClose = ( ) => {
@@ -139,7 +148,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
139
148
} ) ;
140
149
} else if (
141
150
this . state . phase === RightPanelPhases . EncryptionPanel &&
142
- this . state . cardState . verificationRequest && this . state . cardState . verificationRequest . pending
151
+ this . state . cardState . verificationRequest ? .pending
143
152
) {
144
153
// When the user clicks close on the encryption panel cancel the pending request first if any
145
154
this . state . cardState . verificationRequest . cancel ( ) ;
@@ -154,7 +163,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
154
163
155
164
public render ( ) : JSX . Element {
156
165
let card = < div /> ;
157
- const roomId = this . props . room ? this . props . room . roomId : undefined ;
166
+ const roomId = this . props . room ?. roomId ;
158
167
const phase = this . props . overwriteCard ?. phase ?? this . state . phase ;
159
168
const cardState = this . props . overwriteCard ?. state ?? this . state . cardState ;
160
169
switch ( phase ) {
0 commit comments