Electron / Best Practices

December 6, 2019 · View on GitHub

Don't use ipcRenderer.sendSync

As explained in the docs:

Sending a synchronous message will block the whole renderer process, unless you know what you are doing you should never use it.

For example, the following code completely freezes the app:

// renderer
ipcRenderer.sendSync("event-key");
// main
ipcMain.on("event-key", event => {});

Subscribe main's event listeners as soon as possible

This way the messages won't get lost.

app.on("ready", () => {
    subscribeListeners();

    // ...
});