perf: Move to passive scroll listeners where supported
This commit is contained in:
@@ -2,22 +2,7 @@
|
||||
// maintained.
|
||||
import { throttle } from "lodash";
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
let supportsPassive = false;
|
||||
|
||||
try {
|
||||
const opts = Object.defineProperty({}, "passive", {
|
||||
get: function () {
|
||||
supportsPassive = true;
|
||||
},
|
||||
});
|
||||
// @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call.
|
||||
window.addEventListener("testPassive", null, opts);
|
||||
// @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call.
|
||||
window.removeEventListener("testPassive", null, opts);
|
||||
} catch (e) {
|
||||
// No-op
|
||||
}
|
||||
import { supportsPassiveListener } from "~/utils/browser";
|
||||
|
||||
const getPosition = () => ({
|
||||
x: window.pageXOffset,
|
||||
@@ -44,7 +29,7 @@ export default function useWindowScrollPosition(options: {
|
||||
window.addEventListener(
|
||||
"scroll",
|
||||
handleScroll,
|
||||
supportsPassive
|
||||
supportsPassiveListener
|
||||
? {
|
||||
passive: true,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user