Minimal SvelteKit app in SPA mode (ssr = false, @sveltejs/adapter-static + fallback: 'index.html') to reproduce accumulation of detached DOM nodes after mount/destroy cycles when the compiled template holds multiple DOM references (wrapper + <video> + controls) in shared closure scopes.
Upstream issue: sveltejs/svelte#18096
npm install
npm run dev
Production SPA build (index.html fallback):
npm run build
npm run preview
bind: + buttons) grid and mounts a new one.gc() in the console (Chrome: --js-flags="--expose-gc").HTMLVideoElement, HTMLDivElement (class row), etc.You can also use “Remount ×40” several times before step 5.
A single tiny component often shows no visible delta between snapshots because GC clears between captures; the grid + row clicks + stress sequence is what made the issue observable for us.
Chrome documents the underlying DOM retention pattern: a JS reference to any node in a detached subtree keeps the entire subtree alive via parentNode / child links until that reference is dropped.
Clearing video.src / load() from app onDestroy did not fix large detached counts in a real app; extending remove_effect_dom in the Svelte runtime (clear event_symbol, reset media, recursively remove children after remove()) did (~99% reduction in detached delta in that scenario). See svelte#18096 for the reference patch.