useAudio/useVideo play lock resets across renders
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 75/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- react, typescript
Hướng nghiên cứu
Bắt đầu từ createHTMLMediaHook và phần xử lý lockPlay được mô tả trong issue, sau đó lần theo luồng rerender của các media event. Được coi là hoàn tất khi lock vẫn tồn tại qua các lần rerender cho đến khi play() hoàn tất, kèm theo một regression test tập trung bao phủ trường hợp pause khi play đang chờ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What is the current behavior?
useAudio and useVideo use a lockPlay local variable inside createHTMLMediaHook to avoid calling pause() while a pending HTMLMediaElement.play() promise is still resolving.
Because lockPlay is a plain local variable, it is recreated on every render. Media events such as play, playing, waiting, pause, durationchange, or timeupdate can call setState, causing a rerender before the original play() promise settles. After that rerender, the lock is reset to false, so a new controls.pause() call can run while the earlier play() promise is still pending.
This weakens the Chromium workaround described in the comment above the lock:
Some browsers return
Promiseon.play()and may throw errors if one tries to execute another.play()or.pause()while that promise is resolving.
Expected behavior
The play lock should persist across renders until the pending play() promise resolves or rejects.
Using a ref for the lock would preserve the intended behavior without changing the public API.
Why this matters
In video/audio-heavy UIs, components often call controls.play() and controls.pause() in response to store changes, user interactions, or source changes. If a media event causes a rerender while play() is still pending, the current lock can be lost and the hook can issue a conflicting pause().
Possible fix
Change the local variable:
let lockPlay = false;
to a ref-backed value, for example:
const lockPlay = useRef(false);
and read/write lockPlay.current inside the controls.
I can open a PR with a focused regression test if this direction sounds good.
- Ngôn ngữ chính
- TypeScript
- Star
- 44k
- Fork
- 3.3k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của streamich/react-use
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Add Generic Fn for useDebounceCó thể đã có người làm @itsmejay80 đã nhận 180 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
-
useVideo.story.tsx - sampleVideo can not be loadedCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
-
useSlider: event callbacks are not updatedCó thể đã có người làm @erykpiast đã nhận 1827 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Tất cả issue của streamich/react-use
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
MystenLabs/MemWal#1163 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Mondriaan
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
knaw-huc/textannoviz#709 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
billion-context-pi
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
ranxianglei/billion-context#2521 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add: YRF Music NepalĐang mởstreams:add
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100