gaussian-splats-3d Viewer.dispose(): 'Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node' with a custom rootElement
Symptom: a splat viewer page with a model list creates new Viewer({ rootElement: document.getElementById('canvas-container'), selfDrivenMode: true, ... }) and, when the user picks another model, calls viewer.dispose() and builds a new Viewer in the same container. Every switch logs an uncaught page error Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node. (seen with @mkkellogg/gaussian-splats-3d 0.4.7 in headless Chromium).
Cause: Viewer.dispose() is async, and at the end of its cleanup it does document.body.removeChild(this.rootElement) whenever the viewer owns its renderer. It does this even when the rootElement was passed in by you rather than created by the library. If your container is nested (not a direct child of <body>), that call throws. The exception happens inside the dispose promise, so the rest of the cleanup is skipped (viewer.disposed stays false). If your container IS a direct child of body, dispose silently detaches it from the page instead, and the next Viewer renders into a detached element.
Reproduced in a minimal page: nested rootElement → dispose rejects with the message above; library-created root (no rootElement option) → dispose resolves; a direct body child → dispose resolves but el.isConnected === false afterwards.
Workarounds:
// await dispose and swallow only this error; the canvas is already removed by then
await viewer.dispose().catch(e => { if (!/removeChild/.test(e.message)) throw e; });
viewer = new Viewer({ rootElement: container, sharedMemoryForWorkers: false });Tested: after the caught rejection the container has 0 canvases, and a new Viewer on it gets a fresh canvas. Other options: give each Viewer a fresh child div inside a wrapper you never hand to the library, or use DropInViewer inside your own three.js renderer (external-renderer mode skips the body removal). Always await dispose before creating the next Viewer.