Fix tight-loop update issue caused by a broken shouldComponentUpdate

pull/21833/head
Michael Telatynski 2021-06-16 12:04:37 +01:00
parent deb2e8d679
commit e3a6ce13cd
1 changed files with 4 additions and 9 deletions

View File

@ -80,7 +80,6 @@ import { objectHasDiff } from "../../utils/objects";
import SpaceRoomView from "./SpaceRoomView"; import SpaceRoomView from "./SpaceRoomView";
import { IOpts } from "../../createRoom"; import { IOpts } from "../../createRoom";
import { replaceableComponent } from "../../utils/replaceableComponent"; import { replaceableComponent } from "../../utils/replaceableComponent";
import { omit } from 'lodash';
import UIStore from "../../stores/UIStore"; import UIStore from "../../stores/UIStore";
const DEBUG = false; const DEBUG = false;
@ -572,16 +571,12 @@ export default class RoomView extends React.Component<IProps, IState> {
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
const hasPropsDiff = objectHasDiff(this.props, nextProps); const hasPropsDiff = objectHasDiff(this.props, nextProps);
// React only shallow comparison and we only want to trigger const { upgradeRecommendation, ...state } = this.state;
// a component re-render if a room requires an upgrade const { upgradeRecommendation: newUpgradeRecommendation, ...newState } = nextState;
const newUpgradeRecommendation = nextState.upgradeRecommendation || {}
const state = omit(this.state, ['upgradeRecommendation']);
const newState = omit(nextState, ['upgradeRecommendation'])
const hasStateDiff = const hasStateDiff =
objectHasDiff(state, newState) || newUpgradeRecommendation?.needsUpgrade !== upgradeRecommendation?.needsUpgrade ||
(newUpgradeRecommendation.needsUpgrade === true) objectHasDiff(state, newState);
return hasPropsDiff || hasStateDiff; return hasPropsDiff || hasStateDiff;
} }