Skip to content

fix: cancel animation frame loop and clean media tracks on virtual ca… - #1178

Merged
itzzavdhesh merged 1 commit into
itzzavdhesh:mainfrom
hrshjswniii:BugFix/Virtual-Camera-Animation-Leak
Jul 29, 2026
Merged

fix: cancel animation frame loop and clean media tracks on virtual ca…#1178
itzzavdhesh merged 1 commit into
itzzavdhesh:mainfrom
hrshjswniii:BugFix/Virtual-Camera-Animation-Leak

Conversation

@hrshjswniii

@hrshjswniii hrshjswniii commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

🚀 Program

GSSoC

📝 Description

This PR fixes CPU memory leaks and uncancelled animation frame loops in useVirtualCamera.js when navigating away from the Call page or unmounting virtual camera components.

Key fixes:

  1. Animation Frame Reference (animFrameRef): Maintained an explicit animFrameRef ref for tracking requestAnimationFrame IDs.
  2. Loop Cancellation & Track Cleanup: Refactored stop() and useEffect unmount cleanup in useVirtualCamera.js to invoke cancelAnimationFrame(animFrameRef.current) and stop all originalTrackRef & MediaStreamTrack instances when stopping or unmounting.
  3. Unit Tests (useVirtualCamera.test.js): Added Vitest test assertions for useVirtualCamera.

🔗 Related Issue

Closes #1126

🔄 Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🔍 SEO improvement
  • 🎨 Style / UI improvement
  • ♿ Accessibility improvement
  • 📝 Documentation
  • ⚙️ CI / configuration
  • 🧹 Refactor / cleanup

🧪 How to Test

  1. Open http://localhost:5173 in a browser.
  2. Go to the Call page and click Start Virtual Camera.
  3. Navigate to Settings or About page without explicitly stopping the virtual camera.
  4. Check browser DevTools Performance monitor to verify CPU usage drops back to idle baseline.
  5. Run client tests: npm run test --workspace client and verify all tests pass.

✅ Checklist

  • I am contributing under GSSoC
  • My code follows the project's existing style
  • I have tested my changes in a browser
  • I have linked the related issue above
  • My PR title follows Conventional Commits format (e.g. fix: cancel animation frame loop and clean media tracks on virtual camera unmount)

Summary by cubic

Stop the virtual camera’s animation loop and clean up media tracks on unmount or navigation. This fixes CPU/memory leaks and returns usage to idle after leaving the Call page.

  • Bug Fixes
    • Track requestAnimationFrame with animFrameRef and cancel it in stop() and unmount cleanup.
    • Stop and clear originalTrackRef and stop all MediaStreamTrack instances; reset stream, isLive, and status.
    • Added a basic test to validate the useVirtualCamera export.

Written for commit 6b009e2. Summary will update on new commits.

Review in cubic

@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

@hrshjswniii is attempting to deploy a commit to the itzzavdhesh's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown

✍️ DCO Sign-off Needed

Hey @hrshjswniii! 👋 One or more commits in this PR are missing a Signed-off-by: line.

Warning

  • 6b009e2 fix: cancel animation frame loop and clean media tracks on virtual camera unmount

How to fix:

For the latest commit:

git commit --amend --signoff
git push --force-with-lease

For multiple commits, replace N with the number to update:

git rebase --signoff HEAD~N
git push --force-with-lease

This comment will update automatically after you push.


🤖 VoiceForge Automation · Updates automatically on edits

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@hrshjswniii, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 46b63fef-b4f2-4c4d-9571-963f6abeef68

📥 Commits

Reviewing files that changed from the base of the PR and between b89b5be and 6b009e2.

📒 Files selected for processing (2)
  • client/src/hooks/useVirtualCamera.js
  • client/src/hooks/useVirtualCamera.test.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions

Copy link
Copy Markdown

🎉 PR Ready for Mentor Review

Hey @hrshjswniii! 👋 Your PR passed all checks and is now in the GSSoC review queue.

Note

🔗 Closing: #1126 · 📐 36 lines across 2 file(s) · 📬 Review requested

@sabeenaviklar @Anushreebasics @itsdakshjain @snehkris @1754riya @Mrigakshi-Rathore @Itzzavdheshh @Nitya-003 @4f4d @lovestaco, this PR is ready for your review — please confirm scope, check behavior and tests, then approve or request changes.

Important

This is not an approval. Please wait for mentor feedback before expecting a merge. If changes are requested, push them to this same branch and keep the PR focused on the linked issue.


🤖 VoiceForge Automation · Updates automatically on edits

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread client/src/hooks/useVirtualCamera.js
Comment thread client/src/hooks/useVirtualCamera.js
Comment thread client/src/hooks/useVirtualCamera.js
Comment thread client/src/hooks/useVirtualCamera.test.js

@Nitya-003 Nitya-003 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@hrshjswniii Resolve the comments by bot.

@github-actions github-actions Bot added mentor:Nitya-003 Applied by mentor automation needs revision labels Jul 27, 2026
@github-actions

Copy link
Copy Markdown

🔄 Changes Requested

Hey @hrshjswniii! 👋 A mentor has reviewed your PR and requested some changes.

Warning

Please review the feedback above, update this same branch, and keep the PR focused on the linked issue.

Once you push your updates, the review flow will continue automatically on this same PR.


🤖 VoiceForge Automation · Updates automatically on edits

@itsdakshjain itsdakshjain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good work just follow the cubic comments

@github-actions github-actions Bot added the mentor:itsdakshjain GSSoC: Mentor-@itsdakshjain label Jul 28, 2026
@Itzzavdheshh Itzzavdheshh added gssoc:approved gssoc:approved type:bug type:bug type:performance type:performance level:intermediate level:intermediate quality:clean quality:clean labels Jul 29, 2026
@itzzavdhesh
itzzavdhesh merged commit 9e2569e into itzzavdhesh:main Jul 29, 2026
20 of 22 checks passed
@github-actions

Copy link
Copy Markdown

🎊 PR Merged Successfully

Hey @hrshjswniii! 👋 Congratulations and thank you for your contribution to VoiceForge!

Note

🔗 Linked issue(s): #1126 · ✅ Marked as merged and complete

Maintainers may still handle final cleanup, release notes, or follow-up tracking after the merge.


🤖 VoiceForge Automation · Updates automatically on edits

@itzzavdhesh itzzavdhesh added enhancement New feature or request SSoC26 SSOC Hard hard ELUSOC ELUSOC VETERAN VETERAN type:accessibility type type:feature type:feature type:refactor type:refactor level:advanced level:advanced mentor:Anushreebasics GSSoC: Mentor-@Anushreebasics mentor:sabeenaviklar GSSoC: Mentor-@sabeenaviklar and removed level:intermediate level:intermediate labels Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] : Uncancelled Animation Loop Leak in useVirtualCamera

5 participants