Skip to content

fix: keep media play lock across renders#2709

Open
pupuking723 wants to merge 1 commit into
streamich:masterfrom
pupuking723:fix/media-play-lock-ref
Open

fix: keep media play lock across renders#2709
pupuking723 wants to merge 1 commit into
streamich:masterfrom
pupuking723:fix/media-play-lock-ref

Conversation

@pupuking723

Copy link
Copy Markdown

Fixes #2708.

Description

createHTMLMediaHook uses a play lock to avoid calling pause() while an HTMLMediaElement.play() promise is still resolving. The lock was a plain local variable, so it was recreated on every render. If media state updates triggered a rerender before the play promise settled, the lock could be lost.

This stores the lock in a ref so it persists across renders until the play promise resolves or rejects.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as before)

Checklist

  • Read the Contributing Guide
  • Perform a code self-review
  • Cover changes with tests
  • Ensure the test suite passes (yarn jest tests/useAudio.test.ts --runInBand)
  • Make sure code lints (./node_modules/.bin/eslint src/factory/createHTMLMediaHook.ts tests/useAudio.test.ts)
  • Make sure types are fine (yarn lint:types)

Verification

  • yarn jest tests/useAudio.test.ts --runInBand
  • yarn lint:types
  • ./node_modules/.bin/eslint src/factory/createHTMLMediaHook.ts tests/useAudio.test.ts (0 errors, 1 existing hook dependency warning in createHTMLMediaHook.ts)
  • yarn build

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.

useAudio/useVideo play lock resets across renders

1 participant