Description
While testing plugin loading in Music Blocks, I noticed that dynamically injected plugin <script> elements are never removed from document.head after they finish executing.
The issue occurs in:
inside the processPluginData plugin-loading flow.
Current implementation:
const script = document.createElement("script");
script.src = url;
document.head.appendChild(script);
The script element is appended to the DOM and executed, but it is never removed afterward.
This happens both for:
- the main Blob-based plugin script
- additional setup scripts created for plugin initialization
As a result, every plugin load leaves behind extra <script> nodes inside <head> for the lifetime of the session.
Expected Behavior
Temporary plugin loader <script> elements should be cleaned up after:
- successful execution
- failed loading
- rejected initialization
The plugin should load normally without leaving unused DOM nodes behind.
Current Behavior
Every plugin load permanently adds new <script> tags to:
Reloading plugins multiple times in the same session causes:
- unnecessary DOM growth
- accumulation of unused script nodes
- gradual memory increase during long-running sessions
Steps to Reproduce
- Open Music Blocks
- Load any plugin using the plugin menu
- Reload the same plugin multiple times
- Open DevTools → Elements
- Inspect:
- Observe that injected plugin
<script> tags continue accumulating and are never removed
Root Cause
The dynamically created script elements are appended to the DOM but no cleanup happens after onload or onerror.
Current flow:
document.head.appendChild(script);
Missing cleanup:
document.head.removeChild(script);
Suggested Fix
Remove temporary script elements after execution completes:
script.onload = () => {
URL.revokeObjectURL(url);
document.head.removeChild(script); // ← ADD THIS
resolve();
};
script.onerror = e => {
URL.revokeObjectURL(url);
document.head.removeChild(script); // ← ADD THIS
reject(e);
};
The same cleanup should also be applied to the additional setup scripts created later in processPluginData.
Why This Matters
This issue does not usually break plugin functionality immediately, but repeated plugin loads in long-running sessions can gradually increase unnecessary DOM and memory usage.
Cleaning up temporary loader scripts keeps the runtime cleaner and prevents avoidable accumulation inside document.head.
Checklist
Description
While testing plugin loading in Music Blocks, I noticed that dynamically injected plugin
<script>elements are never removed fromdocument.headafter they finish executing.The issue occurs in:
inside the
processPluginDataplugin-loading flow.Current implementation:
The script element is appended to the DOM and executed, but it is never removed afterward.
This happens both for:
As a result, every plugin load leaves behind extra
<script>nodes inside<head>for the lifetime of the session.Expected Behavior
Temporary plugin loader
<script>elements should be cleaned up after:The plugin should load normally without leaving unused DOM nodes behind.
Current Behavior
Every plugin load permanently adds new
<script>tags to:Reloading plugins multiple times in the same session causes:
Steps to Reproduce
<script>tags continue accumulating and are never removedRoot Cause
The dynamically created script elements are appended to the DOM but no cleanup happens after
onloadoronerror.Current flow:
Missing cleanup:
Suggested Fix
Remove temporary script elements after execution completes:
The same cleanup should also be applied to the additional setup scripts created later in
processPluginData.Why This Matters
This issue does not usually break plugin functionality immediately, but repeated plugin loads in long-running sessions can gradually increase unnecessary DOM and memory usage.
Cleaning up temporary loader scripts keeps the runtime cleaner and prevents avoidable accumulation inside
document.head.Checklist