Add bunch of null-guards and similar to fix React Errors/complaints

pull/21833/head
Michael Telatynski 2019-12-19 15:10:54 +00:00
parent 29523000dc
commit 709b2eed7c
5 changed files with 16 additions and 7 deletions

View File

@ -56,14 +56,20 @@ class ItemRange {
} }
export default class LazyRenderList extends React.Component { export default class LazyRenderList extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
static getDerivedStateFromProps(props, state) { static getDerivedStateFromProps(props, state) {
const range = LazyRenderList.getVisibleRangeFromProps(props); const range = LazyRenderList.getVisibleRangeFromProps(props);
const intersectRange = range.expand(props.overflowMargin); const intersectRange = range.expand(props.overflowMargin);
const renderRange = range.expand(props.overflowItems); const renderRange = range.expand(props.overflowItems);
const listHasChangedSize = !!state && renderRange.totalSize() !== state.renderRange.totalSize(); const listHasChangedSize = !!state.renderRange && renderRange.totalSize() !== state.renderRange.totalSize();
// only update render Range if the list has shrunk/grown and we need to adjust padding OR // only update render Range if the list has shrunk/grown and we need to adjust padding OR
// if the new range + overflowMargin isn't contained by the old anymore // if the new range + overflowMargin isn't contained by the old anymore
if (listHasChangedSize || !state || !state.renderRange.contains(intersectRange)) { if (listHasChangedSize || !state.renderRange || !state.renderRange.contains(intersectRange)) {
return {renderRange}; return {renderRange};
} }
return null; return null;

View File

@ -127,7 +127,7 @@ const Pill = createReactClass({
} }
break; break;
case Pill.TYPE_USER_MENTION: { case Pill.TYPE_USER_MENTION: {
const localMember = nextProps.room.getMember(resourceId); const localMember = nextProps.room ? nextProps.room.getMember(resourceId) : null;
member = localMember; member = localMember;
if (!localMember) { if (!localMember) {
member = new RoomMember(null, resourceId); member = new RoomMember(null, resourceId);

View File

@ -34,12 +34,13 @@ module.exports = createReactClass({
getInitialState: function() { getInitialState: function() {
return { return {
value: SettingsStore.getValueAt( // convert to Boolean to protect against null-capable "tri-state" Settings e.g fallbackICEServerAllowed
value: Boolean(SettingsStore.getValueAt(
this.props.level, this.props.level,
this.props.name, this.props.name,
this.props.roomId, this.props.roomId,
this.props.isExplicit, this.props.isExplicit,
), )),
}; };
}, },

View File

@ -56,6 +56,8 @@ export default createReactClass({
hover: false, hover: false,
// The profile data of the group if this.props.tag is a group ID // The profile data of the group if this.props.tag is a group ID
profile: null, profile: null,
// Whether or not the context menu is open
menuDisplayed: false,
}; };
}, },

View File

@ -32,7 +32,7 @@ export default createReactClass({
return { return {
busy: false, busy: false,
ready: false, ready: false,
isGroupPublicised: null, isGroupPublicised: false, // assume false as <ToggleSwitch /> expects a boolean
}; };
}, },
@ -43,7 +43,7 @@ export default createReactClass({
_initGroupStore: function(groupId) { _initGroupStore: function(groupId) {
this._groupStoreToken = GroupStore.registerListener(groupId, () => { this._groupStoreToken = GroupStore.registerListener(groupId, () => {
this.setState({ this.setState({
isGroupPublicised: GroupStore.getGroupPublicity(groupId), isGroupPublicised: Boolean(GroupStore.getGroupPublicity(groupId)),
ready: GroupStore.isStateReady(groupId, GroupStore.STATE_KEY.Summary), ready: GroupStore.isStateReady(groupId, GroupStore.STATE_KEY.Summary),
}); });
}); });