Skip to content

Fix VideoPlayer source reload under StrictMode#39

Merged
skier233 merged 1 commit into
yourcove:mainfrom
MinasukiHikimuna:fix-38
Jul 6, 2026
Merged

Fix VideoPlayer source reload under StrictMode#39
skier233 merged 1 commit into
yourcove:mainfrom
MinasukiHikimuna:fix-38

Conversation

@MinasukiHikimuna

Copy link
Copy Markdown
Collaborator

Summary

Fixes a VideoPlayer source reload bug that appears under React StrictMode. The player cleanup removes rendered source URLs to release the media stream, but the next StrictMode effect pass could incorrectly skip reloading because the cached source signature still matched. This keeps the cached signature aligned with the actual DOM source attributes, restores missing source attributes when needed, and adds regression coverage.

Linked issue

Closes #38

Type of change

  • Bug fix
  • New feature
  • Refactor / tech debt
  • Docs
  • Other:

AI usage

  • No AI was used for this PR.
  • AI was used for this PR.
    • Model(s): GPT-5.5 / Codex
    • Where / how: Code review, PR preparation, and test/implementation guidance.
  • A human (me) has reviewed, understands, and takes full responsibility for every change here including that the design and architecture are sound. (required)

Testing done & evidence

Ran all the pre-existing tests and verified they are not broken after this.

Ran the new tests.

Manually first verified that the playback is broken on both Arch Linux hosted dev container and on a local Mac development environment. I used a very limited fresh setup with a single video file. Stream URL worked just fine so this is definitely not a file permission issue or caused by a corrupted file.

After the fix I verified that the playback is working on both setups.

Checklist

  • I have read and followed the Contribution Guide.
  • Builds and existing tests pass.
  • I added or updated tests where it makes sense.
  • I updated docs where needed.
  • This PR is focused and does not bundle unrelated changes.

React StrictMode replays mount effects in development: the first VideoPlayer source effect records the loaded stream signature and calls video.load(), then the cleanup effect strips the rendered source src attributes and calls video.load() to release the stream.

On the second effect pass, lastLoadedSourceRef still matched the same stream signature, so the source effect returned early even though the real DOM source no longer had a src. The media element then reported no available source and never requested /api/stream/video/... despite the endpoint being reachable directly.

Make the cached source signature agree with the DOM by tracking the rendered source element, validating its src and MIME type before skipping a reload, restoring missing or stale attributes imperatively when needed, and clearing lastLoadedSourceRef when cleanup strips the source.

Add a StrictMode regression test that renders VideoPlayer, lets mount effects replay, and verifies the source src and type are still present. Keep the unknown direct-stream MIME behavior covered so unsupported formats still avoid a misleading type attribute.
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.

Video playback broken when running dev environment on the host

2 participants