Fix memory leak in onLoadById functionFix memory leak in onLoadById function #699
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.
Summary of Changes
Fixed a memory leak in the
onLoadByIdutility function that could cause intervals to run indefinitely when DOM elements are not found.Type of Change
The Problem
The
onLoadByIdfunction insrc/utils/scrollingOperations.jscreates asetIntervalthat checks every 100ms for a DOM element to appear. However, if the element never appears (e.g., when a user navigates away before the page fully loads), the interval continues running indefinitely.Why the old code was risky:
Affected code path: This function is used in
LeftNav.jsxwhen navigating to the "How it Works" section from other pages.The Solution
Added a timeout mechanism that automatically clears the interval after 5 seconds (50 attempts × 100ms) if the element is not found:
Changes made:
maxAttemptsconstant to limit interval execution@paramannotationsHow the new code handles it:
Testing
Code Validation
node -c)Manual Testing Recommended
After merge, please verify:
Additional Notes
Also improved JSDoc comments to use proper @param annotations.