Commit 6d2a98b
Fix: Additional bugs and code quality improvements (#4210)
* Fix: Log unhandled async error in constructor
The constructor's initial load() call silently swallowed errors with
.catch(() => null), making debugging difficult when initial load fails.
Issues fixed:
- Added console.error to log the error for debugging
- Error event is still emitted inside load() as documented
- Developers can now see initial load failures in console
- No change to error event behavior
While errors cannot be caught from a constructor call, this provides
visibility into initial load failures for debugging purposes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix: RecordPlugin blob URL memory leak
The RecordPlugin created blob URLs with URL.createObjectURL() but
never revoked them, causing memory leaks during multiple recordings.
Issues fixed:
- Added recordedBlobUrl property to track created blob URLs
- Revoke previous blob URL before creating new one
- Revoke blob URL in destroy() to free memory
- Prevents blob accumulation during multiple recording sessions
Each recording now properly cleans up its blob URL before creating
a new one, preventing memory leaks from unreleased blob references.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix: Clear ResizeObserver reference after disconnect
The Renderer's destroy() method disconnected the ResizeObserver but
didn't clear the reference, causing minor memory retention.
Issues fixed:
- Set resizeObserver to null after disconnect()
- Ensures reference is cleared for garbage collection
- Prevents disconnected observer from remaining in memory
While the observer was disconnected, the reference prevented it from
being garbage collected. Now properly releases the reference.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix: Clear debounce timeout on destroy in drag handler
The drag handler had a pending setTimeout that wasn't cleared when
WaveSurfer was destroyed, potentially causing seekTo() calls on
destroyed instances.
Issues fixed:
- Store unsubscribeDrag separately from subscriptions array
- Add cleanup function that clears timeout and unsubscribes
- Prevents setTimeout callback from executing after destroy
- Avoids potential null reference errors
The debounce timeout is now properly cleared when the instance is
destroyed, preventing orphaned timeout callbacks.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix: Add numberOfChannels bounds check in regions
The region element initialization could divide by zero if
numberOfChannels was 0, resulting in Infinity for elementHeight.
Issues fixed:
- Added check for numberOfChannels > 0 before division
- Prevents Infinity from being set as CSS height value
- Falls back to default 100% height for invalid channel counts
- Ensures region rendering doesn't break with edge case data
The region now safely handles cases where numberOfChannels is 0
or undefined, preventing invalid CSS values.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix: Handle empty color array with default value
The convertColorValues() method returned empty string for empty
arrays, which could cause rendering issues. Now returns default color.
Issues fixed:
- Added explicit check for empty color array (length === 0)
- Returns default waveColor '#999' instead of empty string
- Ensures waveform always has a valid color value
- Prevents potential rendering failures with invalid colors
Empty color arrays now fall back to a sensible default rather than
an empty string that could break rendering.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix: Close previous AudioContext in RecordPlugin startMic
The startMic() method created new AudioContext instances without
closing previous ones when called multiple times, causing resource
exhaustion.
Issues fixed:
- Added check for existing micStream before starting new one
- Call stopMic() to clean up previous AudioContext
- Prevents AudioContext accumulation from multiple startMic() calls
- Ensures system audio resources are properly released
Each startMic() call now properly closes the previous AudioContext
before creating a new one, preventing audio resource exhaustion.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix: Remove event listeners from detached region content
The setContent() method removed old content elements without removing
their event listeners first, causing memory leaks from orphaned listeners
on detached DOM nodes.
Issues fixed:
- Store content event listeners in properties for later removal
- Remove listeners from old content before detaching it
- Re-add listeners to new content after setting it
- Prevents memory leaks from orphaned event listeners
Event listeners on region content are now properly cleaned up when
content is changed, preventing memory leaks from detached DOM nodes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix: Add iteration limit to prevent infinite recursion in Fetcher
The watchProgress() recursive read() function had no safeguards against
malformed streams that never signal completion, potentially causing
infinite recursion.
Issues fixed:
- Added maxIterations limit (100,000) to prevent infinite loops
- Added iteration counter to track read attempts
- Logs error and exits if limit is reached
- Protects against malformed or never-ending streams
While reader.read() should eventually return done: true, this provides
a safety net for edge cases with malformed streams or protocol errors.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 0fba2ad commit 6d2a98b
File tree
5 files changed
+86
-32
lines changed- src
- plugins
5 files changed
+86
-32
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
17 | 25 | | |
18 | 26 | | |
19 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
213 | 214 | | |
214 | 215 | | |
215 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
216 | 222 | | |
217 | 223 | | |
218 | 224 | | |
| |||
272 | 278 | | |
273 | 279 | | |
274 | 280 | | |
275 | | - | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
276 | 287 | | |
277 | 288 | | |
278 | 289 | | |
| |||
355 | 366 | | |
356 | 367 | | |
357 | 368 | | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
358 | 374 | | |
359 | 375 | | |
360 | 376 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
| |||
218 | 220 | | |
219 | 221 | | |
220 | 222 | | |
221 | | - | |
| 223 | + | |
222 | 224 | | |
223 | 225 | | |
224 | 226 | | |
| |||
284 | 286 | | |
285 | 287 | | |
286 | 288 | | |
287 | | - | |
288 | | - | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
289 | 293 | | |
290 | 294 | | |
291 | 295 | | |
| |||
375 | 379 | | |
376 | 380 | | |
377 | 381 | | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
378 | 392 | | |
379 | 393 | | |
380 | 394 | | |
| |||
394 | 408 | | |
395 | 409 | | |
396 | 410 | | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
397 | 416 | | |
398 | 417 | | |
399 | 418 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
300 | | - | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
301 | 304 | | |
302 | 305 | | |
303 | 306 | | |
| |||
329 | 332 | | |
330 | 333 | | |
331 | 334 | | |
| 335 | + | |
332 | 336 | | |
333 | 337 | | |
334 | 338 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
204 | 207 | | |
205 | 208 | | |
206 | 209 | | |
| |||
318 | 321 | | |
319 | 322 | | |
320 | 323 | | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
340 | 342 | | |
341 | | - | |
342 | | - | |
343 | | - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
344 | 346 | | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
349 | 356 | | |
350 | 357 | | |
351 | 358 | | |
| |||
0 commit comments