Skip to content

Conversation

@katspaugh
Copy link
Owner

Summary

Fixes #4187 - Race condition where autoScroll and autoCenter would sometimes cause the scroll position to jump to the beginning when loading a blob.

Root Cause

The issue occurred when renderProgress() was called while audio data was still being loaded/decoded. During this time:

  • The audio duration could be 0, Infinity, or undefined
  • scrollIntoView() would be called with an invalid progress value (often 0)
  • This caused the scroll position to jump to the beginning of the waveform

Solution

Added a guard in renderProgress() (src/renderer.ts:729) to only call scrollIntoView() when:

  1. The waveform is scrollable
  2. autoScroll is enabled
  3. Valid audio data exists (this.audioData is not null)
  4. The audio has a valid duration (this.audioData.duration > 0)

This prevents the race condition by ensuring scroll operations only happen after audio is fully loaded.

Test Plan

  • All existing Cypress tests pass (83/83)
  • All existing unit tests pass (416/416)
  • Build succeeds
  • Fix verified to prevent unwanted scrolling during blob load

The fix preserves the original user workaround behavior (temporarily disabling autoCenter/autoScroll), but eliminates the need for it.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings December 4, 2025 19:49
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>
@katspaugh katspaugh force-pushed the fix/autoscroll-race-condition branch from e7d1e70 to cfc0a06 Compare December 4, 2025 19:51
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 4, 2025

Deploying wavesurfer-js with  Cloudflare Pages  Cloudflare Pages

Latest commit: cfc0a06
Status: ✅  Deploy successful!
Preview URL: https://da6e5fcd.wavesurfer-js.pages.dev
Branch Preview URL: https://fix-autoscroll-race-conditio.wavesurfer-js.pages.dev

View logs

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a race condition where autoScroll and autoCenter options could cause the waveform scroll position to jump to the beginning during audio blob loading.

Key Changes:

  • Added a guard condition in renderProgress() to prevent scroll operations during audio loading
  • Added metadata tracking for the bug fix in .beads/issues.jsonl

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.

File Description
src/renderer.ts Added validation to check for valid audio data (existence and duration > 0) before calling scrollIntoView(), preventing race condition during loading
.beads/issues.jsonl Added issue tracking metadata for the bug fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@katspaugh katspaugh merged commit 72a8cb3 into main Dec 4, 2025
5 checks passed
@katspaugh katspaugh deleted the fix/autoscroll-race-condition branch December 4, 2025 20:02
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.

Race condition while load blob if autoCenter and autoScroll is activated

2 participants