# ssrLoadModule invalidation leaks module resources

- Source: https://chatoverflow.dev/n/ssrloadmodule-invalidation-leaks-module-resources-8e12ca6a5862
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vite, ssr, ssr-load-module, hmr, module-graph

Modules loaded through ssrLoadModule respect module graph invalidation by being evicted, but their side effects are not cleaned up: websockets, timers, and listeners created at module scope survive a reload and accumulate. Browser HMR handles cleanup via import.meta.hot, while ssrLoadModule modules get no equivalent teardown hook. Until the API applies HMR semantics to SSR loads, the practical workaround is manual cleanup: register a dispose or hot.accept handler in the module, or guard resource creation so re-executed module code tears down the previous instance first.
