FIX: ensures scrolls work in chat when touch is on text (#30817)

The stacking context fix we use in chat to avoid:
https://bugs.webkit.org/show_bug.cgi?id=262287 was causing this weird
behavior in chat where the scroll event wouldn't fire when the finger is
on text and not an empty area of the scrollable div.

This simplified implementation seems to work reliably and avoids the
issue.
This commit is contained in:
Joffrey JAFFEUX 2025-01-16 13:02:23 +01:00 committed by GitHub
parent 41bf8ddfd0
commit f28eb5b0dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,34 +1,20 @@
import { next, schedule } from "@ember/runloop";
import discourseLater from "discourse/lib/later";
import { capabilities } from "discourse/services/capabilities"; import { capabilities } from "discourse/services/capabilities";
// since -webkit-overflow-scrolling: touch can't be used anymore to disable momentum scrolling // since -webkit-overflow-scrolling: touch can't be used anymore to disable momentum scrolling
// we use different hacks to work around this // we use different hacks to work around this
// if you change any line in this method, make sure to test on iOS // if you change any line in this method, make sure to test on iOS
export function stackingContextFix(scrollable, callback) { export function stackingContextFix(scrollable, callback) {
if (capabilities.isIOS) {
scrollable.style.overflow = "hidden";
scrollable
.querySelectorAll(".chat-message-separator__text-container")
.forEach((container) => (container.style.zIndex = "1"));
}
callback?.(); callback?.();
if (capabilities.isIOS) { if (capabilities.isIOS) {
next(() => { // stores scroll position otherwise we will lose it
schedule("afterRender", () => { const currentScroll = scrollable.scrollTop;
scrollable.style.overflow = "auto";
discourseLater(() => {
if (!scrollable) {
return;
}
scrollable const display = scrollable.style.display;
.querySelectorAll(".chat-message-separator__text-container") scrollable.style.display = "none"; // forces redraw on the container
.forEach((container) => (container.style.zIndex = "2")); scrollable.offsetHeight; // triggers a reflow
}, 50); scrollable.style.display = display;
});
}); scrollable.scrollTop = currentScroll;
} }
} }