Revert "Revert "[Refactoring] Intersection Observer: Revert redundant workaround for freezing""

This reverts commit 55d7648698917aa9c51d4a4e5ca18b8433a968bd.
This commit is contained in:
Alexander Zinchuk 2021-12-10 18:33:31 +01:00
parent 6afcae9512
commit 560299e129
2 changed files with 4 additions and 31 deletions

View File

@ -31,7 +31,6 @@ export default function useMessageObservers(
} = useIntersectionObserver({
rootRef: containerRef,
throttleMs: INTERSECTION_THROTTLE_FOR_READING,
noAutoFreeze: true,
}, (entries) => {
if (type !== 'thread') {
return;

View File

@ -22,8 +22,6 @@ interface Response {
unfreeze: NoneToVoidFunction;
}
const AUTO_UNFREEZE_TIMEOUT = 2000;
export function useIntersectionObserver({
rootRef,
throttleMs,
@ -32,7 +30,6 @@ export function useIntersectionObserver({
margin,
threshold,
isDisabled,
noAutoFreeze = false,
}: {
rootRef: RefObject<HTMLDivElement>;
throttleMs?: number;
@ -41,16 +38,18 @@ export function useIntersectionObserver({
margin?: number;
threshold?: number | number[];
isDisabled?: boolean;
noAutoFreeze?: boolean;
}, rootCallback?: RootCallback): Response {
const controllerRef = useRef<IntersectionController>();
const rootCallbackRef = useRef<RootCallback>();
const freezeFlagsRef = useRef(0);
const autoUnfreezeTimeoutRef = useRef<number>();
const onUnfreezeRef = useRef<NoneToVoidFunction>();
rootCallbackRef.current = rootCallback;
const freeze = useCallback(() => {
freezeFlagsRef.current++;
}, []);
const unfreeze = useCallback(() => {
if (!freezeFlagsRef.current) {
return;
@ -64,31 +63,6 @@ export function useIntersectionObserver({
}
}, []);
const freeze = useCallback(() => {
freezeFlagsRef.current++;
if (noAutoFreeze) {
return;
}
if (autoUnfreezeTimeoutRef.current) {
clearTimeout(autoUnfreezeTimeoutRef.current);
autoUnfreezeTimeoutRef.current = undefined;
}
// Make sure to unfreeze even if unfreeze callback was not called (which was some hardly-reproducible bug)
autoUnfreezeTimeoutRef.current = window.setTimeout(() => {
autoUnfreezeTimeoutRef.current = undefined;
if (!freezeFlagsRef.current) {
return;
}
freezeFlagsRef.current = 1;
unfreeze();
}, AUTO_UNFREEZE_TIMEOUT);
}, [noAutoFreeze, unfreeze]);
useHeavyAnimationCheck(freeze, unfreeze);
useEffect(() => {