Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Invalid value for <ellipse> attribute ry="Infinity" when setting display: none; to Waveform with Envelope plugin #3856

Open
thomasmol opened this issue Sep 4, 2024 · 2 comments
Labels

Comments

@thomasmol
Copy link

Bug description

I get an error/warning in my browser console Error: Invalid value for <ellipse> attribute ry="Infinity" when adding a display:none; styling to the waveform player which uses the envelope plugin. The error is shown for every x and y point in the envelope, so e.g. the minimal example below generates 6 errors.

It seems like the points get assigned new coordinates with a value of Infinity, but I can't find out why or where.

It does not break anything else though. The hiding and unhiding works fine and all points on the envelope and waveform keep working as expected.

Environment

  • Browser: Safari (but in other browsers as well)
  • MacOS 15
  • SvelteKit 2.0

Minimal code snippet

In a Svelte component + TailwindCSS ('hidden' class adds display:none; to an element)

<script>
  import { onMount } from 'svelte';
  import WaveSurfer from 'wavesurfer.js';
  import EnvelopePlugin from 'wavesurfer.js/plugins/envelope';
  import SampleAudio from '$lib/assets/audio/test.mp3';

  let hidden = false;

  onMount(() => {
    const ws = WaveSurfer.create({
      container: '#waveform',
      url: SampleAudio
    });
    // add envelope with 3 test points
    const envelope = EnvelopePlugin.create({
      points: [
        { time: 0, volume: 0 },
        { time: 1, volume: 1 },
        { time: 2, volume: 0 }
      ]
    });
    ws.registerPlugin(envelope);
  });
</script>

<button type="button" on:click={() => (hidden = !hidden)}> Show/hide audio player </button>

<div class={hidden ? 'hidden' : ''}>
  <div id="waveform"></div>
</div>

Expected result

No errors

Obtained result

[Error] Error: Invalid value for <ellipse> attribute ry="Infinity"
	(anonymous function) (wavesurfer__js_plugins_envelope.js:156)
	forEach
	update (wavesurfer__js_plugins_envelope.js:154)
	(anonymous function) (wavesurfer__js_plugins_envelope.js:210)
	forEach
	emit (wavesurfer__js.js:53)
	(anonymous function) (wavesurfer__js.js:758)
	forEach
	emit (wavesurfer__js.js:53)
	(anonymous function) (wavesurfer__js.js:524:412)
	(anonymous function) (wavesurfer__js.js:26)
	Promise
	t (wavesurfer__js.js:5)
	reRender (wavesurfer__js.js:539)
	onContainerResize (wavesurfer__js.js:234:118)
[Error] Error: Invalid value for <ellipse> attribute rx="Infinity"
	(anonymous function) (wavesurfer__js_plugins_envelope.js:156)
	forEach
	update (wavesurfer__js_plugins_envelope.js:154)
	(anonymous function) (wavesurfer__js_plugins_envelope.js:210)
	forEach
	emit (wavesurfer__js.js:53)
	(anonymous function) (wavesurfer__js.js:758)
	forEach
	emit (wavesurfer__js.js:53)
	(anonymous function) (wavesurfer__js.js:524:412)
	(anonymous function) (wavesurfer__js.js:26)
	Promise
	t (wavesurfer__js.js:5)
	reRender (wavesurfer__js.js:539)
	onContainerResize (wavesurfer__js.js:234:118)

Screenshots

CleanShot 2024-09-04 at 14 11 08@2x

@thomasmol thomasmol added the bug label Sep 4, 2024
@Mattk70
Copy link

Mattk70 commented Feb 12, 2025

The error happens when you set display: none on the container. This triggers a redraw event (because the container has "resized", and it errors because the reported height of the container is 0.

This affects the spectrogram plugin implementation too. A minimal implementation:

// Spectrogram plugin

import WaveSurfer from 'wavesurfer.js'
import Spectrogram from 'wavesurfer.js/dist/plugins/spectrogram.esm.js'

// Create an instance of WaveSurfer
const ws = WaveSurfer.create({
  container: '#waveform',
  waveColor: 'rgb(200, 0, 200)',
  progressColor: 'rgb(100, 0, 100)',
  url: '/examples/audio/audio.wav',
  sampleRate: 44100,
})

// Initialize the Spectrogram plugin
ws.registerPlugin(
  Spectrogram.create({
    labels: true,
    height: 200,
    splitChannels: true,
    scale: 'mel', // or 'linear', 'logarithmic', 'bark', 'erb'
    frequencyMax: 8000,
    frequencyMin: 0,
    fftSamples: 1024,
    labelsBackground: 'rgba(0, 0, 0, 0.1)',
  }),
)

// Play on click
ws.once('interaction', () => {
  document.getElementById('waveform').style.display = 'none'
})

/*
<html>
  <div id="waveform"></div>
  <p>
    📖 <a href="https://wavesurfer.xyz/docs/modules/plugins_spectrogram">Spectrogram plugin docs</a>
  </p>
</html>
*/

Image

It may be possible to prevent the error with a 'redraw' handler, but I haven't figured out how.

@katspaugh
Copy link
Owner

It may be possible to prevent the error with a 'redraw' handler, but I haven't figured out how.

We should probably fix the math and handle a zero container size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants