From e90009772d0c2955e8caeecb1fc4f81d83b61afa Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 15 Jan 2021 11:21:52 +0000 Subject: [PATCH 1/2] Fix React warnings about missing key for edited messages This uses a fragment instead of an array to avoid the need for key attributes. --- src/components/views/messages/TextualBody.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/views/messages/TextualBody.js b/src/components/views/messages/TextualBody.js index 8f153e48e9..bf0884a2f3 100644 --- a/src/components/views/messages/TextualBody.js +++ b/src/components/views/messages/TextualBody.js @@ -410,7 +410,10 @@ export default class TextualBody extends React.Component { ref: this._content, }); if (this.props.replacingEventId) { - body = [body, this._renderEditedMarker()]; + body = <> + {body} + {this._renderEditedMarker()} + ; } if (this.props.highlightLink) { From 80f3e14faf19ca0b188ad05a68d00af778728171 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 15 Jan 2021 11:42:30 +0000 Subject: [PATCH 2/2] Move `LoggedInView` subscriptions to after mounted This avoids a React warning about trying to call `setState` before the component is mounted. --- src/components/structures/LoggedInView.tsx | 34 +++++++++++++--------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/components/structures/LoggedInView.tsx b/src/components/structures/LoggedInView.tsx index ec5afd13f0..70ec2b7033 100644 --- a/src/components/structures/LoggedInView.tsx +++ b/src/components/structures/LoggedInView.tsx @@ -140,7 +140,7 @@ class LoggedInView extends React.Component { protected readonly _matrixClient: MatrixClient; protected readonly _roomView: React.RefObject; protected readonly _resizeContainer: React.RefObject; - protected readonly _compactLayoutWatcherRef: string; + protected compactLayoutWatcherRef: string; protected resizer: Resizer; constructor(props, context) { @@ -157,18 +157,6 @@ class LoggedInView extends React.Component { CallMediaHandler.loadDevices(); - document.addEventListener('keydown', this._onNativeKeyDown, false); - - this._updateServerNoticeEvents(); - - this._matrixClient.on("accountData", this.onAccountData); - this._matrixClient.on("sync", this.onSync); - this._matrixClient.on("RoomState.events", this.onRoomStateEvents); - - this._compactLayoutWatcherRef = SettingsStore.watchSetting( - "useCompactLayout", null, this.onCompactLayoutChanged, - ); - fixupColorFonts(); this._roomView = React.createRef(); @@ -176,6 +164,24 @@ class LoggedInView extends React.Component { } componentDidMount() { + document.addEventListener('keydown', this._onNativeKeyDown, false); + + this._updateServerNoticeEvents(); + + this._matrixClient.on("accountData", this.onAccountData); + this._matrixClient.on("sync", this.onSync); + // Call `onSync` with the current state as well + this.onSync( + this._matrixClient.getSyncState(), + null, + this._matrixClient.getSyncStateData(), + ); + this._matrixClient.on("RoomState.events", this.onRoomStateEvents); + + this.compactLayoutWatcherRef = SettingsStore.watchSetting( + "useCompactLayout", null, this.onCompactLayoutChanged, + ); + this.resizer = this._createResizer(); this.resizer.attach(); this._loadResizerPreferences(); @@ -186,7 +192,7 @@ class LoggedInView extends React.Component { this._matrixClient.removeListener("accountData", this.onAccountData); this._matrixClient.removeListener("sync", this.onSync); this._matrixClient.removeListener("RoomState.events", this.onRoomStateEvents); - SettingsStore.unwatchSetting(this._compactLayoutWatcherRef); + SettingsStore.unwatchSetting(this.compactLayoutWatcherRef); this.resizer.detach(); }