Skip to content

fix: Add cleanup for VideoConfManager listener in VideoConfProvider#38930

Open
Makeepan-dev wants to merge 2 commits intoRocketChat:developfrom
Makeepan-dev:develop
Open

fix: Add cleanup for VideoConfManager listener in VideoConfProvider#38930
Makeepan-dev wants to merge 2 commits intoRocketChat:developfrom
Makeepan-dev:develop

Conversation

@Makeepan-dev
Copy link
Contributor

@Makeepan-dev Makeepan-dev commented Feb 23, 2026

Proposed changes (including videos or screenshots)

While looking through the VideoConfProvider component, I noticed that we were setting up event listeners for direct/stopped and calling/ended inside a useEffect hook, but we weren't actually cleaning them up when the component unmounted.

Issue(s)

Closes #38895

Steps to test or reproduce

Start a video call or a direct call in a local workspace.

End the call or navigate away from the provider to trigger an unmount.

If you use a memory profiler or add temporary logs to the VideoConfManager, you'll see that without this change, the listeners stay attached. With this fix, they’re correctly cleared out as soon as the component unmounts.

Further comments

This was tested on a local build after working through some environment setup with Deno 2.6.10 and Yarn 4. The monorepo builds successfully with turbo.

Summary by CodeRabbit

  • Bug Fixes
    • Improved video conferencing reliability by ensuring event listeners are properly cleaned up when calls end, preventing stale handlers and ensuring outgoing call state resets correctly.

@Makeepan-dev Makeepan-dev requested a review from a team as a code owner February 23, 2026 12:09
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Feb 23, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Feb 23, 2026

⚠️ No Changeset found

Latest commit: e2814d3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 976f337 and e2814d3.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (1)
  • apps/meteor/client/providers/VideoConfProvider.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/client/providers/VideoConfProvider.tsx
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: CodeQL-Build

Walkthrough

Fixed a memory leak in VideoConfProvider by consolidating the direct/stopped and calling/ended event handlers into a shared handler and adding cleanup to unsubscribe those listeners when the component unmounts.

Changes

Cohort / File(s) Summary
VideoConfProvider Listener Cleanup
apps/meteor/client/providers/VideoConfProvider.tsx
Combined inline listeners for direct/stopped and calling/ended into a single handleStop handler and added unmount cleanup to remove subscriptions via VideoConfManager.off(), preventing accumulation of stale listeners.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I hopped in to tidy a listener-lined track,
Merged two little handlers and took the rest back.
On unmount I wave, subscriptions set free—
No more memory crumbs left from video spree! 🥕✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely describes the main change: adding cleanup for VideoConfManager listeners in VideoConfProvider to fix a memory leak.
Linked Issues check ✅ Passed The code changes capture and invoke teardown functions for VideoConfManager.on() listeners on unmount, directly addressing all coding requirements from issue #38895.
Out of Scope Changes check ✅ Passed All changes are scoped to VideoConfProvider listener cleanup with no unrelated modifications present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
apps/meteor/client/providers/VideoConfProvider.tsx (1)

38-47: Inconsistent cleanup pattern — align with established style or fix formatting.

The .off() method is valid on VideoConfManager, so this code works correctly. However, the rest of the file uses the pattern of returning the unsubscribe function directly from .on() (lines 21–27 and 29–36). This new block breaks that consistency with explicit .off() calls. Additionally, line 39 has a spacing issue (handleStop =() should be handleStop = () =>).

For consistency with the rest of the file, capture the return values from .on() and call them in cleanup:

♻️ Refactor to match established pattern
 	useEffect(() => {
-		const handleStop =() => setOutgoing(undefined);
-		VideoConfManager.on('direct/stopped', handleStop);
-		VideoConfManager.on('calling/ended', handleStop);
-		
-		return () => {
-			VideoConfManager.off('direct/stopped', handleStop);
-			VideoConfManager.off('calling/ended', handleStop);
-		}
+		const handleStop = () => setOutgoing(undefined);
+		const offStop = VideoConfManager.on('direct/stopped', handleStop);
+		const offEnded = VideoConfManager.on('calling/ended', handleStop);
+		return () => {
+			offStop();
+			offEnded();
+		};
 	}, []);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/client/providers/VideoConfProvider.tsx` around lines 38 - 47, The
handler declaration has a spacing typo and the cleanup should follow the
established unsubscribe-return pattern: change "const handleStop =() =>
setOutgoing(undefined);" to "const handleStop = () => setOutgoing(undefined);",
store the unsubscribe functions returned by
VideoConfManager.on('direct/stopped', handleStop) and
VideoConfManager.on('calling/ended', handleStop) into variables (e.g.,
unsubscribeDirect and unsubscribeCalling) and call those functions in the effect
cleanup instead of calling VideoConfManager.off; reference handleStop,
VideoConfManager.on, and setOutgoing to locate the code to update.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/meteor/client/providers/VideoConfProvider.tsx`:
- Around line 38-47: The handler declaration has a spacing typo and the cleanup
should follow the established unsubscribe-return pattern: change "const
handleStop =() => setOutgoing(undefined);" to "const handleStop = () =>
setOutgoing(undefined);", store the unsubscribe functions returned by
VideoConfManager.on('direct/stopped', handleStop) and
VideoConfManager.on('calling/ended', handleStop) into variables (e.g.,
unsubscribeDirect and unsubscribeCalling) and call those functions in the effect
cleanup instead of calling VideoConfManager.off; reference handleStop,
VideoConfManager.on, and setOutgoing to locate the code to update.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 133da0b and 976f337.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (1)
  • apps/meteor/client/providers/VideoConfProvider.tsx
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/providers/VideoConfProvider.tsx
🧠 Learnings (1)
📚 Learning: 2025-12-18T15:18:31.688Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 37773
File: apps/meteor/client/views/mediaCallHistory/MediaCallHistoryInternal.tsx:24-34
Timestamp: 2025-12-18T15:18:31.688Z
Learning: In apps/meteor/client/views/mediaCallHistory/MediaCallHistoryInternal.tsx, for internal call history items, the item.contactId is guaranteed to always match either the caller.id or callee.id in the call data, so the contact resolution in getContact will never result in undefined.

Applied to files:

  • apps/meteor/client/providers/VideoConfProvider.tsx

@ggazzo ggazzo added this to the 8.3.0 milestone Feb 23, 2026
@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.65%. Comparing base (50e0f90) to head (e2814d3).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38930      +/-   ##
===========================================
- Coverage    70.66%   70.65%   -0.01%     
===========================================
  Files         3189     3189              
  Lines       112715   112713       -2     
  Branches     20397    20460      +63     
===========================================
- Hits         79652    79641      -11     
- Misses       31015    31021       +6     
- Partials      2048     2051       +3     
Flag Coverage Δ
unit 71.19% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 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.

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