openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Bug: HMR orphans Tauri event listeners in App.tsx service singletons

Open Liohtml opened this issue 6 months ago • 0 comments

Summary

app/src/App.tsx starts five service singletons at module evaluation time (startWebviewAccountService(), etc.). These attach Tauri listen<>() event handlers internally. During Vite HMR, module re-evaluation is guarded by started flags (preventing double-start), but orphaned listeners from the previous module instance are never cleaned up.

Impact

Low — Development-only: HMR accumulates orphaned event listeners, causing duplicate handler execution and potential memory leaks during hot reload cycles.

Suggested Fix

Export cleanup functions from each service and call them in import.meta.hot?.dispose():

if (import.meta.hot) {
  import.meta.hot.dispose(() => {
    stopWebviewAccountService();
    stopWebviewNotificationsService();
    // ...
  });
}

Liohtml avatar May 16 '26 14:05 Liohtml