I'm using Vite, but I think this applies to all backends.
A file that has "other stuff" than Preact components must let HMR reload the page, e.g. by not calling accept at all, or calling invalidate.
The Vite React Refresh plugin checks that all exports are components, and ignores the HMR request if there are non-components: vitejs/vite-plugin-react-refresh@feec176