Skip to content

A platform for community discussion. Free, open, simple.

FIX: prevents scroll-lock to crash the app (#36246)

Joffrey JAFFEUXbc36f0355d3f
diff --git a/frontend/discourse/app/lib/scroll-lock.js b/frontend/discourse/app/lib/scroll-lock.js
index 9b29b8732a9..8a0be70fa56 100644
--- a/frontend/discourse/app/lib/scroll-lock.js
+++ b/frontend/discourse/app/lib/scroll-lock.js
@@ -2,7 +2,12 @@
lock scroll of an element using overflow:hidden
preserve gutter with scroll detection
*/
-function lockScroll(element = document.scrollingElement) {
+function lockScroll(element) {
+ element ??= document.scrollingElement;
+ if (!element) {
+ return;
+ }
+
let scrollGap = 0;
//Add scroll gap if using default scrolling element
@@ -15,7 +20,12 @@ function lockScroll(element = document.scrollingElement) {
element.classList.add("scroll-lock");
}
-function unlockScroll(element = document.scrollingElement) {
+function unlockScroll(element) {
+ element ??= document.scrollingElement;
+ if (!element) {
+ return;
+ }
+
element.classList.remove("scroll-lock");
element.style.setProperty("--scroll-gap", null);
}