Fix right panel soft crashes due to missing room prop (#7923)

This commit is contained in:
Michael Telatynski 2022-03-01 11:15:23 +00:00 committed by GitHub
parent 36adba101c
commit 7a32a68a0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 39 deletions

View file

@ -92,10 +92,23 @@ export default class RightPanel extends React.Component<IProps, IState> {
}
public static getDerivedStateFromProps(props: IProps): Partial<IState> {
const currentCard = RightPanelStore.instance.currentCardForRoom(props.room.roomId);
let currentCard: IRightPanelCard;
if (props.room) {
currentCard = RightPanelStore.instance.currentCardForRoom(props.room.roomId);
}
if (props.groupId) {
currentCard = RightPanelStore.instance.currentGroup;
}
if (currentCard?.phase && !RightPanelStore.instance.isPhaseValid(currentCard.phase, !!props.room)) {
// XXX: We can probably get rid of this workaround once GroupView is dead, it's unmounting happens weirdly
// late causing the app to soft-crash due to lack of a room object being passed to a RightPanel
return null; // skip this update, we're about to be unmounted and don't have the appropriate props
}
return {
cardState: currentCard.state,
phase: currentCard.phase,
cardState: currentCard?.state,
phase: currentCard?.phase,
};
}
@ -116,11 +129,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
};
private onRightPanelStoreUpdate = () => {
const currentCard = RightPanelStore.instance.currentCardForRoom(this.props.room.roomId);
this.setState({
cardState: currentCard.state,
phase: currentCard.phase,
});
this.setState({ ...RightPanel.getDerivedStateFromProps(this.props) as IState });
};
private onClose = () => {
@ -137,7 +146,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
});
} else if (
this.state.phase === RightPanelPhases.EncryptionPanel &&
this.state.cardState.verificationRequest && this.state.cardState.verificationRequest.pending
this.state.cardState.verificationRequest?.pending
) {
// When the user clicks close on the encryption panel cancel the pending request first if any
this.state.cardState.verificationRequest.cancel();
@ -152,7 +161,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
public render(): JSX.Element {
let card = <div />;
const roomId = this.props.room ? this.props.room.roomId : undefined;
const roomId = this.props.room?.roomId;
const phase = this.props.overwriteCard?.phase ?? this.state.phase;
const cardState = this.props.overwriteCard?.state ?? this.state.cardState;
switch (phase) {