You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: Memory leak — resize event listener never removed in SidebarLayout #2588
In components/Sidebar.tsx, the SidebarLayout component attaches a resize event listener to window inside a useEffect using an anonymous function, but does not provide a cleanup function to remove it on unmount.
Consequently, each time a user navigates between pages that mount SidebarLayout, a new listener is added to window while previous listeners remain in memory. Over prolonged navigation sessions, these stacked listeners accumulate, causing unnecessary re-renders and memory leakage when resizing the viewport.
Additionally, the dependency array [typeof window !== 'undefined'] evaluates to [true] on the client side, acting as a misleading no-op that should be [].
Hi @vtushar06, I've updated and restructured the issue description with clear sections, reproduction steps (using DevTools event listener inspection), root cause details, and a proposed code diff matching the codebase's existing conventions. Please take a look!
To resolve the memory leak and clean up the effect implementation in components/Sidebar.tsx:
Extract Named Handler & Add Cleanup: Define handleResize as a named function reference and return a cleanup teardown callback invoking window.removeEventListener('resize', handleResize) when the component unmounts.
Clean Dependency Array: Replace [typeof window !== 'undefined'] with []. In the browser, typeof window !== 'undefined' evaluates to a constant [true], which is misleading.
Remove Redundant Guard: Drop if (window) as useEffect exclusively runs client-side post-mount where window is guaranteed.
I have opened a pull request resolving this issue: #2595
The PR extracts the resize listener to a named handler, adds proper cleanup with removeEventListener on component unmount, cleans up the dependency array, and aligns with the existing pattern in components/Layout.tsx.
Whenever you have a moment, please take a look. Thank you!
Activity
Sarthak-Pandey commentedon Oct 24, 2026
Hi @Relequestual
I'd like to work on this issue. I've already identified the root cause and have a fix ready.
vtushar06 commentedon Oct 24, 2026
can you restructure issues description for better clarification. @Sarthak-Pandey
Sarthak-Pandey commentedon Oct 24, 2026
Hi @vtushar06, I've updated and restructured the issue description with clear sections, reproduction steps (using DevTools event listener inspection), root cause details, and a proposed code diff matching the codebase's existing conventions. Please take a look!
Sarthak-Pandey commentedon Oct 24, 2026
Proposed Solution
To resolve the memory leak and clean up the effect implementation in
components/Sidebar.tsx:handleResizeas a named function reference and return a cleanup teardown callback invokingwindow.removeEventListener('resize', handleResize)when the component unmounts.[typeof window !== 'undefined']with[]. In the browser,typeof window !== 'undefined'evaluates to a constant[true], which is misleading.if (window)asuseEffectexclusively runs client-side post-mount wherewindowis guaranteed.This aligns with the existing listener cleanup pattern in
components/Layout.tsx.Diff:
vtushar06 commentedon Oct 25, 2026
Changes looks valid, Proceed with your PR @Sarthak-Pandey
Sarthak-Pandey commentedon Oct 25, 2026
Hi @vtushar06,
I have opened a pull request resolving this issue: #2595
The PR extracts the resize listener to a named handler, adds proper cleanup with
removeEventListeneron component unmount, cleans up the dependency array, and aligns with the existing pattern incomponents/Layout.tsx.Whenever you have a moment, please take a look. Thank you!