Merge pull request #4552 from matrix-org/foldleft/fix-sublist-crash

Fix a crash where a name could unexpectedly be an empty list
pull/21833/head
Zoe 2020-05-06 13:52:50 +01:00 committed by GitHub
commit 14516d3e7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 4 deletions

View File

@ -37,6 +37,42 @@ import toRem from "../../utils/rem";
// turn this on for drop & drag console debugging galore // turn this on for drop & drag console debugging galore
const debug = false; const debug = false;
class RoomTileErrorBoundary extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
error: null,
};
}
static getDerivedStateFromError(error) {
// Side effects are not permitted here, so we only update the state so
// that the next render shows an error message.
return { error };
}
componentDidCatch(error, { componentStack }) {
// Browser consoles are better at formatting output when native errors are passed
// in their own `console.error` invocation.
console.error(error);
console.error(
"The above error occured while React was rendering the following components:",
componentStack,
);
}
render() {
if (this.state.error) {
return (<div className="mx_RoomTile mx_RoomTileError">
{this.props.roomId}
</div>);
} else {
return this.props.children;
}
}
}
export default class RoomSubList extends React.PureComponent { export default class RoomSubList extends React.PureComponent {
static displayName = 'RoomSubList'; static displayName = 'RoomSubList';
static debug = debug; static debug = debug;
@ -208,7 +244,7 @@ export default class RoomSubList extends React.PureComponent {
}; };
makeRoomTile = (room) => { makeRoomTile = (room) => {
return <RoomTile return <RoomTileErrorBoundary roomId={room.roomId}><RoomTile
room={room} room={room}
roomSubList={this} roomSubList={this}
tagName={this.props.tagName} tagName={this.props.tagName}
@ -221,7 +257,7 @@ export default class RoomSubList extends React.PureComponent {
refreshSubList={this._updateSubListCount} refreshSubList={this._updateSubListCount}
incomingCall={null} incomingCall={null}
onClick={this.onRoomTileClick} onClick={this.onRoomTileClick}
/>; /></RoomTileErrorBoundary>;
}; };
_onNotifBadgeClick = (e) => { _onNotifBadgeClick = (e) => {

View File

@ -432,10 +432,9 @@ export default createReactClass({
}); });
let name = this.state.roomName; let name = this.state.roomName;
if (name == undefined || name == null) name = ''; if (typeof name !== 'string') name = '';
name = name.replace(":", ":\u200b"); // add a zero-width space to allow linewrapping after the colon name = name.replace(":", ":\u200b"); // add a zero-width space to allow linewrapping after the colon
let badge; let badge;
if (badges) { if (badges) {
const limitedCount = FormattingUtils.formatCount(notificationCount); const limitedCount = FormattingUtils.formatCount(notificationCount);