Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

`useScrolling` doesn't clean up its timer

Đang mở
#2,675 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

@selvaganapathycoder đang làm issue này rồi.

Từ ngày 19/2/2026.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
frontend

Hướng nghiên cứu

Start by locating the useScrolling hook and its Jest coverage. Read the effect cleanup and reproduce the intermittent unmount behavior in the tests. Done means the timeout is cleared during cleanup and the relevant Jest tests pass without leaving timers running.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

What is the current behavior?

useScrolling can leave a timer running on unmount because it doesn't clean up correctly.

I think we need to update the code to something like:

const useScrolling = (ref: RefObject<HTMLElement>): boolean => {  
  const [scrolling, setScrolling] = useState<boolean>(false);

  useEffect(() => {
    if (ref.current) {
      let scrollingTimeout: ReturnType<typeof setTimeout>;

      const handleScrollEnd = () => {
        setScrolling(false);
      };

      const handleScroll = () => {
        setScrolling(true);
        clearTimeout(scrollingTimeout);
        scrollingTimeout = setTimeout(() => handleScrollEnd(), 150);
      };

      on(ref.current, "scroll", handleScroll, false);
      return () => {
        // This is the change from the original implementation
        clearTimeout(scrollingTimeout);

        if (ref.current) {
          off(ref.current, "scroll", handleScroll, false);
        }
      };
    }
    return () => {};
  }, [ref]);

  return scrolling;
}

We need to call clearTimeout() in the cleanup function to correctly remove the timeout.

Steps to reproduce it and if possible a minimal demo of the problem:
This turned up intermittently in our Jest tests.

What is the expected behavior?
The timeout should be cleaned up.

A little about versions:

  • OS:
    macOS 26
  • Browser (vendor and version):
    Node 22.12 (in tests)
  • React:
    17.0.2
  • react-use:
    17.3.1
  • Did this worked in the previous package version?
    No, it looks like the same issue is present in master.
Ngôn ngữ chính
TypeScript
Star
44k
Fork
3.3k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của streamich/react-use

Tất cả issue của streamich/react-use

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.