saltyshiomix / nextron

⚡ Next.js + Electron ⚡
https://npm.im/nextron
MIT License
3.97k stars 229 forks source link

ipcMain.on() still run after background.js hot reload #19

Closed zeroslope closed 5 years ago

zeroslope commented 5 years ago

ipcMain.on() still run after background hot reload

you can add alert('a') on this line https://github.com/saltyshiomix/nextron/blob/6910b108cd6596bf493db1bd717322c742b4e536/examples/ipc-communication/renderer/pages/home.jsx#L24

and then reload background.js, click the button, you can see two alert; reload again, you can see three alert.

and after reload, the output won't appear on console.

saltyshiomix commented 5 years ago

@zeroslope Thank you for your reporting this issue 👍

I fixed nextron@3.5.20:

# install latest nextron
$ npm install --global nextron@latest

# test it
$ nextron init my-app --template ipc-communication
$ cd my-app
$ yarn && yarn dev
zeroslope commented 5 years ago

Thank you for your contribution to open source. The Ipc problem is due to the listener not deleted.

The most difficult is another problem that I can't output anything in the command after reload.

The first time I run yarn dev, I click ipc then output '1'

2019-02-09 3 00 36

I change it to '2', then reload, It output nothing.

2019-02-09 3 01 11

I don't know why.

saltyshiomix commented 5 years ago

I just published nextron@3.6.0 and fixed this issue 👍

$ npm i -g nextron@latest

$ nextron init test-ipc -t ipc-communication
$ cd test-ipc
$ yarn && yarn dev
saltyshiomix commented 5 years ago

@zeroslope

Thank you for your details 💯

I got it like this: (this is a little tricky)

  1. first electron process is from build/nextron-dev.js
  2. the electron processes after hot reloading are from main/helpers/enable-hot-reload.js

So this missing console output bug happens.

I changed main/helpers/enable-hot-reload.js to main/helpers/exit-on-change.js and always start the electron process from build/nextron-dev.js.

zeroslope commented 5 years ago

Thanks for your help! 👍