Skip to content

fix(MediaRecorder): guard pause/resume against inactive recorder to prevent InvalidStateError#3217

Open
MartinCupela wants to merge 1 commit into
release-v13from
fix/MediaRecorder/prevent-invalid-state-error
Open

fix(MediaRecorder): guard pause/resume against inactive recorder to prevent InvalidStateError#3217
MartinCupela wants to merge 1 commit into
release-v13from
fix/MediaRecorder/prevent-invalid-state-error

Conversation

@MartinCupela

Copy link
Copy Markdown
Contributor

🎯 Goal

Closes REACT-789

πŸ›  Implementation details

Root cause
In MediaRecorderController, pause() guards only against the controller's internal state subject, then calls the native API unconditionally:

pause = () => {
  if (this.recordingState.value !== MediaRecordingState.RECORDING) return;
  ...
  this.mediaRecorder?.pause();   // ← throws if native state is 'inactive'
  ...
};

The internal recordingState BehaviorSubject can drift out of sync with the native mediaRecorder.state. On iOS Safari the native MediaRecorder can transition to inactive on its own (interruptions, the stop button's native stop(), track ending) while the React-driven recordingState subject still reads RECORDING. When the user taps stop then immediately pause, pause() passes its internal-state guard but this.mediaRecorder.pause() hits an inactive recorder β†’ InvalidStateError: The MediaRecorder's state cannot be inactive.

Note the inconsistency: stop() already guards against the native this.mediaRecorder?.state, but pause()/resume() guard only against the internal subject. That asymmetry is the bug.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 69460099-1184-4851-8fb1-a559e455297d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • πŸ” Trigger review
✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/MediaRecorder/prevent-invalid-state-error

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.

@MartinCupela MartinCupela changed the title fix(MediaRecorder): guard pause/resume against inactive recorder to p… fix(MediaRecorder): guard pause/resume against inactive recorder to prevent InvalidStateError Jun 10, 2026
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 80.97%. Comparing base (9a59022) to head (e68e2d7).

Additional details and impacted files
@@               Coverage Diff               @@
##           release-v13    #3217      +/-   ##
===============================================
+ Coverage        80.86%   80.97%   +0.10%     
===============================================
  Files              506      506              
  Lines            10563    10570       +7     
  Branches          2482     2484       +2     
===============================================
+ Hits              8542     8559      +17     
+ Misses            1586     1578       -8     
+ Partials           435      433       -2     

β˜” View full report in Codecov by Harness.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ 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