From d08393d450f6f6b2023f0042540625e085645af7 Mon Sep 17 00:00:00 2001 From: Charlie Powell <31997505+cp2004@users.noreply.github.com> Date: Mon, 26 Jun 2023 11:23:58 +0100 Subject: [PATCH] :bug: Reduce intersection observer threshold (#4824) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :bug: Reduce intersection observer threshold When this value is 1, scrolling down the page (sometimes?) triggers the value to change - probably something changes invisibly. Setting it to anything less than 1 seems to cure the issue, and there are no longer unwanted triggers of changes. 1% also seems to make more sense here than 100% - we want the webcam to load whenever even a tiny amount of it is visible. * ♻️ Change visibility observer threshold to 1% * ♻️ Use log.debug instead of console.debug --------- Co-authored-by: Gina Häußge --- src/octoprint/static/js/app/viewmodels/control.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/control.js b/src/octoprint/static/js/app/viewmodels/control.js index 9601f7f6f..09e182dec 100644 --- a/src/octoprint/static/js/app/viewmodels/control.js +++ b/src/octoprint/static/js/app/viewmodels/control.js @@ -57,19 +57,20 @@ $(function () { self._visibleWebcam = undefined; self._dispatchWebcamVisibilityChange = function (target, visible) { + log.debug(`Webcam visibility of #${target.id} changed to ${visible}`); var vm = ko.dataFor(target.children[0]); if (vm === self) { - console.debug( + log.debug( `VM for webcam #${target.id} is not bound, skipping visibility update` ); } else if (vm === undefined) { - console.debug( + log.debug( `VM for webcam #${target.id} not found, skipping visibility update` ); } else if (typeof vm.onWebcamVisibilityChange === "function") { vm.onWebcamVisibilityChange(visible); } else { - console.debug( + log.debug( `VM for webcam #${target.id} does not declare 'onWebcamVisibilityChange(visible)', skipping visibility update (vm=${vm.constructor.name})` ); } @@ -122,7 +123,7 @@ $(function () { var options = { root: document.querySelector("#webcam_plugins_container"), rootMargin: "0px", - threshold: 1.0 + threshold: 0.01 }; var callback = function (entries) { var visible = entries[0].isIntersecting;