From 4e67aafeb784265a8304f6de976089cdd106e9bf Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sat, 2 Dec 2023 08:58:35 +0000 Subject: [PATCH] Scrollable hotfix: Avoid setTimeout See #7869 --- core/modules/widgets/scrollable.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/modules/widgets/scrollable.js b/core/modules/widgets/scrollable.js index f6cb5e67b..227c455c3 100644 --- a/core/modules/widgets/scrollable.js +++ b/core/modules/widgets/scrollable.js @@ -176,7 +176,7 @@ ScrollableWidget.prototype.render = function(parent,nextSibling) { // If the scroll position is bound to a tiddler if(this.scrollableBind) { // After a delay for rendering, scroll to the bound position - setTimeout(this.updateScrollPositionFromBoundTiddler.bind(this),50); + this.updateScrollPositionFromBoundTiddler(); // Set up event listener this.currentListener = this.listenerFunction.bind(this); this.outerDomNode.addEventListener("scroll", this.currentListener); @@ -251,13 +251,14 @@ ScrollableWidget.prototype.refresh = function(changedTiddlers) { this.scrollableBind = this.getAttribute("bind"); this.currentListener = this.listenerFunction.bind(this); this.outerDomNode.addEventListener("scroll", this.currentListener); - setTimeout(this.updateScrollPositionFromBoundTiddler.bind(this),50); } - // If a new scroll position was written into the tiddler, update scroll position - if(changedTiddlers[this.getAttribute("bind")]) { - setTimeout(this.updateScrollPositionFromBoundTiddler.bind(this),50); + // Refresh children + var result = this.refreshChildren(changedTiddlers); + // If the bound tiddler has changed, update scroll position + if(changedAttributes["bind"] || changedTiddlers[this.getAttribute("bind")]) { + this.updateScrollPositionFromBoundTiddler(); } - return this.refreshChildren(changedTiddlers); + return result; }; exports.scrollable = ScrollableWidget;