From 619aea8dbbc1e6ee2c76865d975bc8fed72a6f8a Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Wed, 17 Jun 2020 14:50:55 -0700 Subject: [PATCH] Guard the request animation frame with the existing requestFrame flag --- ui/app/components/streaming-file.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ui/app/components/streaming-file.js b/ui/app/components/streaming-file.js index 23bb4e811..9d82dda50 100644 --- a/ui/app/components/streaming-file.js +++ b/ui/app/components/streaming-file.js @@ -52,11 +52,16 @@ export default class StreamingFile extends Component.extend(WindowResizable) { scrollHandler() { const cli = this.element; - window.requestAnimationFrame(() => { - // If the scroll position is close enough to the bottom, autoscroll to the bottom - this.set('follow', cli.scrollHeight - cli.scrollTop - cli.clientHeight < 20); - this.requestFrame = true; - }); + + // Scroll events can fire multiple times per frame, this eliminates + // redundant computation. + if (this.requestFrame) { + window.requestAnimationFrame(() => { + // If the scroll position is close enough to the bottom, autoscroll to the bottom + this.set('follow', cli.scrollHeight - cli.scrollTop - cli.clientHeight < 20); + this.requestFrame = true; + }); + } this.requestFrame = false; }