Skip to content

fix(react): unsubscribe onAuthChange listeners and prevent race conditions#1199

Open
deepak0x wants to merge 2 commits intoRocketChat:developfrom
deepak0x:fix/onauthchange-memory-leak
Open

fix(react): unsubscribe onAuthChange listeners and prevent race conditions#1199
deepak0x wants to merge 2 commits intoRocketChat:developfrom
deepak0x:fix/onauthchange-memory-leak

Conversation

@deepak0x
Copy link
Contributor

@deepak0x deepak0x commented Mar 11, 2026

Description

This PR fixes a memory leak in the React components where onAuthChange listeners were registered in useEffect hooks but never unsubscribed in the cleanup phase. Additionally, it adds a check in RocketChatAuth.ts to prevent a race condition where a callback might be executed after it has been unsubscribed.

Changes

  • ChatBody, ChatInput, EmbeddedChat: Extracted onAuthChange callbacks to named functions and added removeAuthListener in useEffect cleanup.
  • RocketChatAuth: Added a check in onAuthChange to verify the callback is still registered after the async getCurrentUser call.

Fixes #1198

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.

fix: onAuthChange memory leak in React package

1 participant