From d0b34ef2cad524baa1a366b144c5724c16f01ee9 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Wed, 3 Nov 2021 13:56:21 +0530 Subject: [PATCH] Use flags to work around race --- src/domain/session/room/timeline/TimelineViewModel.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/domain/session/room/timeline/TimelineViewModel.js b/src/domain/session/room/timeline/TimelineViewModel.js index f12d8511..b8e31674 100644 --- a/src/domain/session/room/timeline/TimelineViewModel.js +++ b/src/domain/session/room/timeline/TimelineViewModel.js @@ -47,9 +47,11 @@ export class TimelineViewModel extends ViewModel { this._requestedEndTile = null; this._requestScheduled = false; this._showJumpDown = false; + this._watchMap = new WeakMap(); } async watchForGapFill(gapPromise, gapTile, depth = 0) { + this._watchMap.set(gapTile, true); if (depth >= 10) { console.error("watchForGapFill exceeded a recursive depth of 10"); return; @@ -69,8 +71,8 @@ export class TimelineViewModel extends ViewModel { } const subscription = { onAdd: (idx, tile) => checkForUpdate(idx, tile), - onUpdate: () => {/*checkForUpdate(idx, tile)*/}, onRemove: (idx, tile) => checkForUpdate(idx, tile), + onUpdate: () => { /* shouldn't be called */ }, onMove: () => { /* shouldn't be called */ }, onReset: () => { /* shouldn't be called */ } }; @@ -87,9 +89,10 @@ export class TimelineViewModel extends ViewModel { If gapResult resolves to false, then the gap is already being filled and is thus being tracked for updates by a previous invocation of this method */ + this._watchMap.set(gapTile, false); return; } - if (!hasSeenUpdate) { + if (!hasSeenUpdate || !this._watchMap.get(gapTile)) { this.watchForGapFill(gapTile.notifyVisible(), gapTile, depth + 1); } }