Web Studio: unguarded document.head.removeChild in 1ms setTimeout crashes the whole page (NotFoundError)
Environment
- OpenViking server 0.5.1.1 (uv tool install, macOS arm64)
- Web Studio served at 127.0.0.1:1933, observed since 0.4.22, still present in 0.5.1.1
Symptom
Studio intermittently crashes the entire page with:
Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
The route error boundary catches it and renders a full-page error, killing whatever view was open. Reproduces across browsers (Chrome, embedded webviews), with valid API keys configured.
Root cause
In the main bundle (assets/index-CCa_d8ke.js in 0.5.1.1; index-B7Ke5peF.js in 0.4.22) a theme utility injects a transition-suppressing <style> into document.head and removes it in an unguarded 1ms timer:
),document.head.appendChild(t),()=>{window.getComputedStyle(document.body),setTimeout(()=>{document.head.removeChild(t)},1)}
document.head.removeChild(t) is called without checking t.parentNode === document.head. With React 19 managing <head> children concurrently, the node can already be removed by the time the timer fires, throwing DOMException (NotFoundError) which the error boundary escalates to a full-page crash.
Suggested fix
Guard the removal:
setTimeout(() => { if (t.parentNode === document.head) document.head.removeChild(t) }, 1)
Local workaround (for other affected users)
We patched web_studio/dist/index.html with a runtime guard wrapping HTMLHeadElement.prototype.removeChild to silently ignore orphaned nodes — zero crashes since. Happy to provide the shim if useful.
(Reported by a 0.4.22 → 0.5.1.1 upgrader; the bug survived both versions, so filing it upstream. Original local diagnosis from 2026-10-01.)
A narrowing result: both current main and v0.5.1.1 mount ThemeProvider without disableTransitionOnChange. The published [email protected] defaults that option to false; the quoted cleanup runs only when it is enabled.
I mounted the actual dependency with Studio's props, React 19.2.8 and happy-dom 20.11.1. Mounting and switching dark/light created zero suppression styles and zero 1 ms cleanup callbacks. An explicitly enabled control created three; removing those nodes before firing the callbacks produced three DOMExceptions.
This is an isolated dependency check, not a reproduction of the packaged Studio crash. Could you share the full exception stack and whether the deployed bundle or another provider enables that option? The helper's presence in the bundle alone does not establish that this path executed, so I have no verified Studio patch yet.
AI-generated investigation; no live server, browser session or model was tested.