Skip to content

fix: clean up event listeners and timers in React hooks - #43

Merged
atomantic merged 1 commit into
mainfrom
better/stack-specific
Mar 6, 2026
Merged

fix: clean up event listeners and timers in React hooks#43
atomantic merged 1 commit into
mainfrom
better/stack-specific

Conversation

@atomantic

Copy link
Copy Markdown
Owner

Better Audit — Stack-Specific (React)

2 findings fixed across 2 files. Added removeEventListener cleanup in useSSE hook (memory leak fix). Added setTimeout cleanup in CopyButton.

Copilot AI review requested due to automatic review settings March 6, 2026 02:26
@atomantic
atomantic merged commit 37ae9fa into main Mar 6, 2026
6 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes two memory-leak-related cleanup issues in React hooks/components. In useSSE.ts, named SSE event listeners are now properly tracked and removed via removeEventListener before the EventSource is closed. In CopyButton.tsx, a useRef holds the debounce timer ID so it can be cleared both when a new copy action fires and when the component unmounts.

Changes:

  • Introduced a listeners array in useSSE.ts to track and explicitly remove named event listeners in the effect cleanup.
  • Added useRef + useEffect in CopyButton.tsx to cancel any pending setTimeout on unmount, preventing a state update on an unmounted component.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
client/src/hooks/useSSE.ts Tracks named event listeners and calls removeEventListener for each before closing the EventSource.
client/src/components/ui/CopyButton.tsx Stores the setTimeout handle in a ref so it can be cancelled both on subsequent copies and on unmount.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@atomantic
atomantic deleted the better/stack-specific branch March 6, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants