From 36f9fab47443c5ac571f37ee9081a6cdb7e85a6a Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 28 Nov 2019 19:45:37 -0700 Subject: [PATCH] Ensure read receipts end up with a valid reference to checkUnmounting Fixes https://github.com/vector-im/riot-web/issues/11496 Fixes https://github.com/vector-im/riot-web/issues/11385 Fixes https://github.com/vector-im/riot-web/issues/10007 Fixes https://github.com/vector-im/riot-web/issues/9769 React does (kinda) bind `this._isUnmounting` for us in the context of the EventTile, but the EventTile then passes the function straight through to the ReadReceiptMarker component, which then binds it in the context of EventTile. This results in `this._mounted` being falsey all the time, preventing the ReadReceiptMarker from hitting the code where it updates rrInfo in its unmount. The velocity stuff is smart enough to realize that it has a read receipt and shuffles everything over by one, but when it goes to check the starting height (which will be null/undefined because the RRMarker didn't update it) it assumes it has never seen the receipt before and appends it again - this is what causes some holes/stacking. By forcefully binding the `this._isUnmounting` function we ensure that the `this._mounted` variable is correctly referenced in the context of the MessagePanel, allowing the RRMarker to update its position, and therefore allowing the velocity behaviour to be consistent. --- src/components/structures/MessagePanel.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/structures/MessagePanel.js b/src/components/structures/MessagePanel.js index d1cc1b7cafd..c6f218377a0 100644 --- a/src/components/structures/MessagePanel.js +++ b/src/components/structures/MessagePanel.js @@ -693,6 +693,10 @@ export default class MessagePanel extends React.Component { const readReceipts = this._readReceiptsByEvent[eventId]; + // Dev note: `this._isUnmounting.bind(this)` is important - it ensures that + // the function is run in the context of this class and not EventTile, therefore + // ensuring the right `this._mounted` variable is used by read receipts (which + // don't update their position if we, the MessagePanel, is unmounting). ret.push(