From 709b2eed7c802789334769d176790bfe5c6d9705 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 19 Dec 2019 15:10:54 +0000 Subject: [PATCH] Add bunch of null-guards and similar to fix React Errors/complaints --- src/components/views/elements/LazyRenderList.js | 10 ++++++++-- src/components/views/elements/Pill.js | 2 +- src/components/views/elements/SettingsFlag.js | 5 +++-- src/components/views/elements/TagTile.js | 2 ++ src/components/views/groups/GroupPublicityToggle.js | 4 ++-- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/components/views/elements/LazyRenderList.js b/src/components/views/elements/LazyRenderList.js index 0fc0ef6733..7572dced0b 100644 --- a/src/components/views/elements/LazyRenderList.js +++ b/src/components/views/elements/LazyRenderList.js @@ -56,14 +56,20 @@ class ItemRange { } export default class LazyRenderList extends React.Component { + constructor(props) { + super(props); + + this.state = {}; + } + static getDerivedStateFromProps(props, state) { const range = LazyRenderList.getVisibleRangeFromProps(props); const intersectRange = range.expand(props.overflowMargin); 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 // 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 null; diff --git a/src/components/views/elements/Pill.js b/src/components/views/elements/Pill.js index 12830488b1..b821276e92 100644 --- a/src/components/views/elements/Pill.js +++ b/src/components/views/elements/Pill.js @@ -127,7 +127,7 @@ const Pill = createReactClass({ } break; case Pill.TYPE_USER_MENTION: { - const localMember = nextProps.room.getMember(resourceId); + const localMember = nextProps.room ? nextProps.room.getMember(resourceId) : null; member = localMember; if (!localMember) { member = new RoomMember(null, resourceId); diff --git a/src/components/views/elements/SettingsFlag.js b/src/components/views/elements/SettingsFlag.js index a3a6d18d33..d62f3182fc 100644 --- a/src/components/views/elements/SettingsFlag.js +++ b/src/components/views/elements/SettingsFlag.js @@ -34,12 +34,13 @@ module.exports = createReactClass({ getInitialState: function() { 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.name, this.props.roomId, this.props.isExplicit, - ), + )), }; }, diff --git a/src/components/views/elements/TagTile.js b/src/components/views/elements/TagTile.js index 767980f0a0..e31c1c524e 100644 --- a/src/components/views/elements/TagTile.js +++ b/src/components/views/elements/TagTile.js @@ -56,6 +56,8 @@ export default createReactClass({ hover: false, // The profile data of the group if this.props.tag is a group ID profile: null, + // Whether or not the context menu is open + menuDisplayed: false, }; }, diff --git a/src/components/views/groups/GroupPublicityToggle.js b/src/components/views/groups/GroupPublicityToggle.js index bacf54382a..176bd9f988 100644 --- a/src/components/views/groups/GroupPublicityToggle.js +++ b/src/components/views/groups/GroupPublicityToggle.js @@ -32,7 +32,7 @@ export default createReactClass({ return { busy: false, ready: false, - isGroupPublicised: null, + isGroupPublicised: false, // assume false as expects a boolean }; }, @@ -43,7 +43,7 @@ export default createReactClass({ _initGroupStore: function(groupId) { this._groupStoreToken = GroupStore.registerListener(groupId, () => { this.setState({ - isGroupPublicised: GroupStore.getGroupPublicity(groupId), + isGroupPublicised: Boolean(GroupStore.getGroupPublicity(groupId)), ready: GroupStore.isStateReady(groupId, GroupStore.STATE_KEY.Summary), }); });