Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix right panel soft crashes chat rooms #7479

Merged
merged 4 commits into from
Jan 7, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion src/stores/right-panel/RightPanelStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,19 @@ export default class RightPanelStore extends ReadyWatchingStore {
}

private emitAndUpdateSettings() {
if (this.global?.history) {
toger5 marked this conversation as resolved.
Show resolved Hide resolved
this.global.history = this.global?.history.filter((card)=>this.isCardStateValid(card));
toger5 marked this conversation as resolved.
Show resolved Hide resolved
}
const storePanelGlobal = convertToStorePanel(this.global);
SettingsStore.setValue("RightPanel.phasesGlobal", null, SettingLevel.DEVICE, storePanelGlobal);

if (!!this.viewedRoomId) {
const storePanelThisRoom = convertToStorePanel(this.byRoom[this.viewedRoomId]);
const panelThisRoom = this.byRoom[this.viewedRoomId];
if (panelThisRoom?.history) {
// remove all right panel cards that would fail to render (result in a soft crash)
panelThisRoom.history = panelThisRoom?.history.filter((card)=>this.isCardStateValid(card));
toger5 marked this conversation as resolved.
Show resolved Hide resolved
}
const storePanelThisRoom = convertToStorePanel(panelThisRoom);
SettingsStore.setValue(
"RightPanel.phases",
this.viewedRoomId,
Expand All @@ -245,6 +253,52 @@ export default class RightPanelStore extends ReadyWatchingStore {
this.emit(UPDATE_EVENT, null);
}

private isCardStateValid(card: IRightPanelCard) {
// this function does a sanity check on the card. this is required because
// some phases require specific state properties that might not be available.
// 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.
// we store id's of users and matrix events. If are not yet fetched on reload the right panel cannot display them.
// or potentially other errors.
// (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)
switch (card.phase) {
case RightPanelPhases.ThreadView:
if ( !card.state.threadHeadEvent) {
console.warn("removed card from right panel because of missing threadHeadEvent in card state");
}
return !!card.state.threadHeadEvent;
case RightPanelPhases.RoomMemberInfo:
case RightPanelPhases.SpaceMemberInfo:
case RightPanelPhases.EncryptionPanel:
case RightPanelPhases.GroupMemberInfo:
if ( !card.state.member) {
toger5 marked this conversation as resolved.
Show resolved Hide resolved
console.warn("removed card from right panel because of missing member in card state");
}
return !!card.state.member;
case RightPanelPhases.SpaceMemberList:
if ( !card.state.spaceId) {
toger5 marked this conversation as resolved.
Show resolved Hide resolved
console.warn("removed card from right panel because of missing spaceId in card state");
}
return !!card.state.spaceId;
case RightPanelPhases.Room3pidMemberInfo:
case RightPanelPhases.Space3pidMemberInfo:
if ( !card.state.memberInfoEvent) {
toger5 marked this conversation as resolved.
Show resolved Hide resolved
console.warn("removed card from right panel because of missing memberInfoEvent in card state");
}
return !!card.state.memberInfoEvent;
case RightPanelPhases.GroupRoomInfo:
if ( !card.state.groupRoomId) {
toger5 marked this conversation as resolved.
Show resolved Hide resolved
console.warn("removed card from right panel because of missing groupRoomId in card state");
}
return !!card.state.groupRoomId;
case RightPanelPhases.Widget:
if ( !card.state.widgetId) {
toger5 marked this conversation as resolved.
Show resolved Hide resolved
console.warn("removed card from right panel because of missing widgetId in card state");
}
return !!card.state.widgetId;
}
return true;
}

private setRightPanelCache(card: IRightPanelCard, roomId?: string) {
const history = [{ phase: card.phase, state: card.state ?? {} }];
this.byRoom[roomId ?? this.viewedRoomId] = { history, isOpen: true };
Expand Down