I have read the docs and many posts (here and elsewhere) on this subject with no joy thus far
It's a TypeScript Electron app built with Electron-Vite app, developed in VS Code
// package.json "scripts": { "dev": "electron-vite dev -w", It launches via its main.ts file
// main.ts imports here... console.log('main start'); const ipcListener = new IpcListener<IpcHandlerEvents>(); const ipcEmitter = new IpcEmitter<IpcRendererEvents>(); The main.ts file create the BrowserWindow, and with a preload file
const mainWindow = new BrowserWindow({ show: false, autoHideMenuBar: true, webPreferences: { preload: join(__dirname, '../preload/preload.js'), sandbox: process.env.NODE_ENV !== 'test', }, }); And preload.ts starts similarly to main.ts
// preload.ts imports here... console.log('preload start'); if (process.contextIsolated) { try { The main index.tsx in the renderer process then begins
// index.tsx imports here... console.log('index start'); Which populates content via createRoot
createRoot(document.getElementById('root') as HTMLElement).render( <StrictMode> <RouterProvider router={createHashRouter(getRoutesConfig(store), { future: { v7_relativeSplatPath: true, v7_fetcherPersist: true, v7_partialHydration: true, v7_skipActionErrorRevalidation: true, v7_normalizeFormMethod: true, }, })} future={{ v7_startTransition: true }} /> </StrictMode> Finally displaying root.tsx as the, well, root of the app. With an error boundary
console.log('root start') return ( <ReduxProvider store={store}> <ErrorBoundary> <App /> </ErrorBoundary> </ReduxProvider> ); When an error is thrown the error boundary: stores the current state; then informs the main process
localStorage.setItem('storeToLoad', JSON.stringify(state)); window.electron.ipcRenderer.send('ERROR_IN_WINDOW', { error, errorInfo, }); Which in turn attempts to relaunch the app after exiting
// main.ts ipcListener.on('ERROR_IN_WINDOW', (_, args: unknown) => { console.log('error in window - relaunch'); app.relaunch(); app.exit(); }); So. When one first runs the app this log is shown
// in VS Code terminal main start // in app console preload start index start root start But once an error is thrown and the app 'relaunches` (cough) this is what is shown
// in VS Code terminal AB C:\development\AppDir\App> (ie: the process ends) // in app console preload start And the relaunched app is just a white rectangle
Obviously this is not the desired outcome. Any ideas how I might reach the desired outcome (pls, ty)?