Skip to content

fix: clean up resize event listener in SidebarLayout (#2588) - #2595

Merged
vtushar06 merged 1 commit into
json-schema-org:mainfrom
Sarthak-Pandey:fix/sidebar-resize-memory-leak
Nov 16, 2026
Merged

vtushar06 merged 1 commit into
json-schema-org:mainfrom
Sarthak-Pandey:fix/sidebar-resize-memory-leak

Conversation

@Sarthak-Pandey

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bugfix

Issue Number:

Screenshots/videos:

N/A (Behavioral cleanup of background event listeners)

If relevant, did you update the documentation?

N/A

Summary

In components/Sidebar.tsx, the SidebarLayout component attached a resize event listener to window using an anonymous function inside a useEffect, but did not return a cleanup function to remove it on unmount.

Consequently, whenever navigating between pages mounting SidebarLayout, new listeners accumulated on window, leading to potential memory leaks and redundant callback execution on viewport resize. Additionally, the dependency array [typeof window !== 'undefined'] evaluated to a constant [true] on the client side.

This PR fixes the issue by:

  1. Extracting the listener into a named callback (handleResize) and returning window.removeEventListener('resize', handleResize) to clean it up on unmount.
  2. Replacing the dependency array [typeof window !== 'undefined'] with [].
  3. Removing the redundant if (window) guard since useEffect exclusively runs client-side post-mount.

This matches the existing cleanup pattern used in components/Layout.tsx.

Does this PR introduce a breaking change?

No

Checklist

Please ensure the following tasks are completed before submitting this pull request.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

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

@codecov

codecov Bot commented Oct 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (441d2a0) to head (6732374).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #2595   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           31        31           
  Lines          719       719           
  Branches       223       223           
=========================================
  Hits           719       719           

☔ View full report in Codecov by Harness.
📢 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.

@vtushar06 vtushar06 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, the named handler and removeEventListener on unmount match what we already do in Layout.tsx.

@vtushar06
vtushar06 merged commit 630fbbf into json-schema-org:main Nov 16, 2026
11 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to review to Done in PR - Triage Group Nov 16, 2026
@github-actions

Copy link
Copy Markdown

Congratulations, @Sarthak-Pandey for your first pull request merge in this repository! 🎉🎉. Thanks for your contribution to JSON Schema!

This branch was successfully deployed

1 active deployment
Preview — 67323746 Deployed Oct 25, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix: Memory leak — resize event listener never removed in SidebarLayout

2 participants