@@ -230,11 +230,14 @@ export default class RightPanelStore extends ReadyWatchingStore {
230230 }
231231
232232 private emitAndUpdateSettings ( ) {
233+ this . filterValidCards ( this . global ) ;
233234 const storePanelGlobal = convertToStorePanel ( this . global ) ;
234235 SettingsStore . setValue ( "RightPanel.phasesGlobal" , null , SettingLevel . DEVICE , storePanelGlobal ) ;
235236
236237 if ( ! ! this . viewedRoomId ) {
237- const storePanelThisRoom = convertToStorePanel ( this . byRoom [ this . viewedRoomId ] ) ;
238+ const panelThisRoom = this . byRoom [ this . viewedRoomId ] ;
239+ this . filterValidCards ( panelThisRoom ) ;
240+ const storePanelThisRoom = convertToStorePanel ( panelThisRoom ) ;
238241 SettingsStore . setValue (
239242 "RightPanel.phases" ,
240243 this . viewedRoomId ,
@@ -245,6 +248,57 @@ export default class RightPanelStore extends ReadyWatchingStore {
245248 this . emit ( UPDATE_EVENT , null ) ;
246249 }
247250
251+ private filterValidCards ( rightPanelForRoom ?: IRightPanelForRoom ) {
252+ if ( ! rightPanelForRoom ?. history ) return ;
253+ rightPanelForRoom . history = rightPanelForRoom . history . filter ( ( card ) => this . isCardStateValid ( card ) ) ;
254+ }
255+
256+ private isCardStateValid ( card : IRightPanelCard ) {
257+ // this function does a sanity check on the card. this is required because
258+ // some phases require specific state properties that might not be available.
259+ // This can be caused on if element is reloaded and the tries to reload right panel data from id's stored in the local storage.
260+ // we store id's of users and matrix events. If are not yet fetched on reload the right panel cannot display them.
261+ // or potentially other errors.
262+ // (A nicer fix could be to indicate, that the right panel is loading if there is missing state data and re-emit if the data is available)
263+ switch ( card . phase ) {
264+ case RightPanelPhases . ThreadView :
265+ if ( ! card . state . threadHeadEvent ) {
266+ console . warn ( "removed card from right panel because of missing threadHeadEvent in card state" ) ;
267+ }
268+ return ! ! card . state . threadHeadEvent ;
269+ case RightPanelPhases . RoomMemberInfo :
270+ case RightPanelPhases . SpaceMemberInfo :
271+ case RightPanelPhases . EncryptionPanel :
272+ case RightPanelPhases . GroupMemberInfo :
273+ if ( ! card . state . member ) {
274+ console . warn ( "removed card from right panel because of missing member in card state" ) ;
275+ }
276+ return ! ! card . state . member ;
277+ case RightPanelPhases . SpaceMemberList :
278+ if ( ! card . state . spaceId ) {
279+ console . warn ( "removed card from right panel because of missing spaceId in card state" ) ;
280+ }
281+ return ! ! card . state . spaceId ;
282+ case RightPanelPhases . Room3pidMemberInfo :
283+ case RightPanelPhases . Space3pidMemberInfo :
284+ if ( ! card . state . memberInfoEvent ) {
285+ console . warn ( "removed card from right panel because of missing memberInfoEvent in card state" ) ;
286+ }
287+ return ! ! card . state . memberInfoEvent ;
288+ case RightPanelPhases . GroupRoomInfo :
289+ if ( ! card . state . groupRoomId ) {
290+ console . warn ( "removed card from right panel because of missing groupRoomId in card state" ) ;
291+ }
292+ return ! ! card . state . groupRoomId ;
293+ case RightPanelPhases . Widget :
294+ if ( ! card . state . widgetId ) {
295+ console . warn ( "removed card from right panel because of missing widgetId in card state" ) ;
296+ }
297+ return ! ! card . state . widgetId ;
298+ }
299+ return true ;
300+ }
301+
248302 private setRightPanelCache ( card : IRightPanelCard , roomId ?: string ) {
249303 const history = [ { phase : card . phase , state : card . state ?? { } } ] ;
250304 this . byRoom [ roomId ?? this . viewedRoomId ] = { history, isOpen : true } ;
0 commit comments