diff --git a/addons/web/static/src/legacy/js/core/dom.js b/addons/web/static/src/legacy/js/core/dom.js index 063ee3742b8..9412fdc1cde 100644 --- a/addons/web/static/src/legacy/js/core/dom.js +++ b/addons/web/static/src/legacy/js/core/dom.js @@ -157,10 +157,10 @@ var dom = { } }, /** - * @return {HTMLElement} + * @return {HTMLElement|null} */ closestScrollable(el) { - return $(el).closestScrollable()[0]; + return $(el).closestScrollable()[0] || null; }, /** * @param {HTMLElement} el @@ -549,6 +549,9 @@ var dom = { * @return {Promise} */ scrollTo(el, options = {}) { + if (!el) { + throw new Error("The scrollTo function was called without any given element"); + } const $el = $(el); const $scrollable = options.$scrollable || $el.parent().closestScrollable(); // If $scrollable and $el are not in the same document, we can safely diff --git a/addons/web/static/src/legacy/js/libs/jquery.js b/addons/web/static/src/legacy/js/libs/jquery.js index c4c627cb306..7fc19bf1d94 100644 --- a/addons/web/static/src/legacy/js/libs/jquery.js +++ b/addons/web/static/src/legacy/js/libs/jquery.js @@ -128,6 +128,10 @@ $.fn.extend({ closestScrollable() { let $el = this; while ($el[0] !== document.scrollingElement) { + // Avoid infinite loop. + if (!$el.length) { + return $(); + } if ($el.isScrollable()) { return $el; }