perf: Move to passive scroll listeners where supported

This commit is contained in:
Tom Moor
2022-02-10 19:29:25 -08:00
parent af6c5a1f45
commit 25fd8466e0
4 changed files with 36 additions and 20 deletions

View File

@@ -15,6 +15,7 @@ import usePageVisibility from "~/hooks/usePageVisibility";
import useStores from "~/hooks/useStores";
import useToasts from "~/hooks/useToasts";
import MultiplayerExtension from "~/multiplayer/MultiplayerExtension";
import { supportsPassiveListener } from "~/utils/browser";
import { homePath } from "~/utils/routeHelpers";
type Props = EditorProps & {
@@ -76,7 +77,7 @@ function MultiplayerEditor({ onSynced, ...props }: Props, ref: any) {
"scrollY",
window.scrollY / window.innerHeight
);
}, 200);
}, 250);
const finishObserving = () => {
if (ui.observingUserId) {
@@ -86,7 +87,11 @@ function MultiplayerEditor({ onSynced, ...props }: Props, ref: any) {
window.addEventListener("click", finishObserving);
window.addEventListener("wheel", finishObserving);
window.addEventListener("scroll", syncScrollPosition);
window.addEventListener(
"scroll",
syncScrollPosition,
supportsPassiveListener ? { passive: true } : false
);
provider.on("authenticationFailed", () => {
showToast(