Repository navigation
fix(useScrolling): clear pending timeout during cleanup - #2740
Open
wanxiankai wants to merge 1 commit into
Open
wanxiankai wants to merge 1 commit into
wanxiankai wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
useScrollingleaves its 150ms debounce timeout pending when the component unmounts or the ref object changes. The timeout can then update an unmounted component.Clear the timeout in the effect cleanup and capture the subscribed element so the scroll listener is removed even when React has cleared the ref or it points to a different element. Keep the existing 150ms debounce behavior.
Fixes #2675.
Add seven tests covering the debounce interval, repeated scroll events, a missing element, unmount with and without a pending timeout, React clearing a real DOM ref, and ref replacement. Four of these tests fail on the original implementation. The updated hook has 100% statement, branch, function, and line coverage.
Type of change
Checklist
Sensors/useScrollingstory continues to cover the public API.yarn test) β 77 suites, 499 tests.src/useScrolling.ts.yarn lint). Fix it withyarn lint:fixin case of failure. β 0 errors; 96 warnings elsewhere in the existing codebase. The changed source and test files pass ESLint without warnings.yarn lint:types).Additional validation:
yarn build(CommonJS and ES modules), changed-file Prettier check using the repository's ESLint formatting options, andgit diff --checkall pass.Prepared with AI assistance.