Skip to content

Fix: remove resize listener on unmount in Sidebar (#2241)#2262

Open
severe77 wants to merge 1 commit intojson-schema-org:mainfrom
severe77:fix/sidebar-resize-listener-2241
Open

Fix: remove resize listener on unmount in Sidebar (#2241)#2262
severe77 wants to merge 1 commit intojson-schema-org:mainfrom
severe77:fix/sidebar-resize-listener-2241

Conversation

@severe77
Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix


Issue Number:


Screenshots/videos:

N/A – internal lifecycle fix, no visible UI changes.


If relevant, did you update the documentation?

No documentation changes required.


Summary

This PR fixes a resize event listener accumulation issue in components/Sidebar.tsx.

Previously, the useEffect hook added a window.resize listener using an anonymous function and did not remove it on unmount. When navigating between pages that mount/unmount the Sidebar, multiple resize listeners accumulated over time. This caused redundant executions on resize and a small memory leak.

The fix:

  • Introduces a named handleResize function
  • Adds proper cleanup using window.removeEventListener
  • Keeps the implementation SSR-safe
  • Uses an empty dependency array to ensure the listener is registered only once

No other logic or behavior was changed.


Notes

  • Verified locally that only a single resize listener remains attached after repeated navigation.
  • All existing tests pass.
  • Lint and type checks pass locally.
  • No UI behavior changes were introduced.

Does this PR introduce a breaking change?

No.


Checklist

  • Read, understood, and followed the contributing guidelines.

@severe77 severe77 requested a review from a team as a code owner February 22, 2026 06:12
@github-project-automation github-project-automation bot moved this to Ready to review in PR - Triage Group Feb 22, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 22, 2026

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
website ✅ Ready (View Log) Visit Preview 9e1994f

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2ee67ff) to head (9e1994f).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #2262   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           30        30           
  Lines          663       663           
  Branches       205       205           
=========================================
  Hits           663       663           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready to review

Development

Successfully merging this pull request may close these issues.

🐛 Bug: Sidebar resize listener never removed - memory leak on navigation

1 participant