RocketChat / RocketChat/EmbeddedChat

fix: onAuthChange memory leak in React package

Open
#1,198 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
165
Forks
381
Avg merge
1d 2h
Merged PRs (30d)
1

Description

Description

The onAuthChange listener in the React package is registered within useEffect hooks but never unsubscribed in the cleanup phase. This leads to a memory leak and potential duplicate executions of code within the listener when the authentication state changes.

Root Cause

In files like ChatBody.js, ChatInput.js, and EmbeddedChat.js, RCInstance.auth.onAuthChange is called inside useEffect, but the returned cleanup function does not call RCInstance.auth.removeAuthListener. Consequently, every time the effect re-runs, a new listener is added without removing the old one.

Affected Files
  • packages/react/src/views/ChatBody/ChatBody.js
  • packages/react/src/views/ChatInput/ChatInput.js
  • packages/react/src/views/EmbeddedChat.js
Proposed Fix

Extract the callback to a named function and call removeAuthListener in the useEffect cleanup.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the useEffect hooks in packages/react/src/views/ChatBody/ChatBody.js, packages/react/src/views/ChatInput/ChatInput.js, and packages/react/src/views/EmbeddedChat.js. Trace how RCInstance.auth.onAuthChange registers its callback and how the effect cleanup currently works. Done means each affected listener is removed during cleanup so rerunning the effects does not leave duplicate listeners.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.