Skip to content

fix: onAuthChange memory leak in React package #1198

@deepak0x

Description

@deepak0x

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions