Skip to content

Commit e7d1e70

Browse files
GitHub Copilotclaude
andcommitted
Fix race condition with autoCenter/autoScroll during loadBlob (#4187)
Fixed a race condition where autoScroll and autoCenter would sometimes cause the scroll position to jump to the beginning when loading a blob. The issue occurred when renderProgress was called while the audio data was still being loaded/decoded (duration temporarily 0 or invalid), which triggered scrollIntoView to scroll to position 0. The fix adds a guard to only call scrollIntoView when valid audio data exists with a duration > 0, preventing the race condition. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e37b915 commit e7d1e70

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

.beads/issues.jsonl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"id":"wavesurfer.js-pgw","title":"Fix race condition with autoCenter/autoScroll during loadBlob","description":"","status":"closed","priority":2,"issue_type":"bug","created_at":"2025-12-04T20:44:48.179843+01:00","updated_at":"2025-12-04T20:48:52.196792+01:00","closed_at":"2025-12-04T20:48:52.196792+01:00"}

src/renderer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,8 @@ class Renderer extends EventEmitter<RendererEvents> {
725725
? `translateX(-${progress * this.options.cursorWidth}px)`
726726
: ''
727727

728-
if (this.isScrollable && this.options.autoScroll) {
728+
// Only scroll if we have valid audio data to prevent race conditions during loading
729+
if (this.isScrollable && this.options.autoScroll && this.audioData && this.audioData.duration > 0) {
729730
this.scrollIntoView(progress, isPlaying)
730731
}
731732
}

0 commit comments

Comments
 (0)