test(sidebar): add event listener lifecycle cleanup tests #465#617
Closed
elcabasa wants to merge 2 commits into
Closed
test(sidebar): add event listener lifecycle cleanup tests #465#617elcabasa wants to merge 2 commits into
elcabasa wants to merge 2 commits into
Conversation
Verify that all window and matchMedia listeners registered by SidebarProvider and useIsMobile are properly cleaned up on unmount using identical callback references.
Removes the second retry callback (which referenced undefined MAX_RETRIES) that shadowed the correct implementation above.
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.
Fix event listener cleanup in Sidebar to prevent listener leaks
#465
Summary
This PR audits the event listener lifecycle in
src/shared/components/ui/sidebar.tsxand ensures that all listeners registered by the sidebar are properly cleaned up when the component unmounts.The goal is to prevent potential memory leaks and unnecessary event listener accumulation during repeated mount/unmount cycles (for example, when navigating between dashboard pages), while preserving all existing sidebar behavior.
What Changed
Event listener audit
addEventListenerregistration insidebar.tsx.removeEventListenerin the appropriateuseEffectcleanup.Cleanup improvements
Test coverage
Added/updated tests to verify:
addEventListenerandremoveEventListenerare called with matching callback references.Validation
Verified by running:
npm test -- SidebarAdditionally confirmed that:
Why This Change?
Without proper cleanup, event listeners can persist after a component unmounts, leading to:
This PR ensures the sidebar cleans up after itself correctly while maintaining identical user-facing behavior.
Acceptance Criteria
Security Impact
None.
This is a performance and correctness improvement focused on preventing event listener leaks without changing application behavior.